XiaoRuby
2023-07-21 2086b1f359f4a59c1f6de67b38dd29be88f2c7bf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package com.yuanchu.limslaboratory.controller;
 
 
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yuanchu.limslaboratory.pojo.Specifications;
import com.yuanchu.limslaboratory.service.SpecificationsService;
import com.yuanchu.limslaboratory.utils.JackSonUtil;
import com.yuanchu.limslaboratory.utils.MyUtil;
import com.yuanchu.limslaboratory.utils.RedisUtil;
import com.yuanchu.limslaboratory.vo.Result;
import com.yuanchu.limslaboratory.vo.UpdateSpeStateSpecifications;
import com.yuanchu.limslaboratory.vo.UpdateSpecificationsInformation;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;
 
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
 
/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 江苏鵷雏网络科技有限公司
 * @since 2023-07-11
 */
@Api(tags = "标准库-->型号-->产品规格")
@RestController
@RequestMapping("/specifications")
public class SpecificationsController {
 
    @Autowired
    private SpecificationsService specificationsService;
 
    @ApiOperation("标准库-->产品规格")
    @PostMapping("/add")
    public Result<?> addSpecificationsInformation(@RequestHeader("X-Token") String token,@RequestBody Specifications specifications) throws Exception {
        Object object = RedisUtil.get(token);
        Map<String, Object> unmarshal = JackSonUtil.unmarshal(JackSonUtil.marshal(object), Map.class);
        specifications.setUserId((Integer) unmarshal.get("id"));
        Integer isStandardsSuccess = specificationsService.addSpecificationsInformation(specifications);
        if (isStandardsSuccess == 1) {
            return Result.success("添加【"+ specifications.getName() +"】成功!");
        }
        return Result.fail("添加【"+ specifications.getName() +"】失败!");
    }
 
    @ApiOperation("标准库-->根据型号查询产品规格")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "pageNo", value = "起始页", dataTypeClass = Integer.class, required = true),
            @ApiImplicitParam(name = "pageSize", value = "每一页数量", dataTypeClass = Integer.class, required = true),
            @ApiImplicitParam(name = "specificationsName", value = "规格名称", dataTypeClass = String.class),
            @ApiImplicitParam(name = "serialNumberId", value = "型号ID", dataTypeClass = String.class,required = true)
    })
    @GetMapping("/list")
    public Result<?> listSpecificationsInformation(Integer pageNo,
                                                   Integer pageSize,
                                                   String specificationsName,
                                                   String serialNumberId){
        IPage<Map<String, Objects>> pageList= specificationsService.listSpecificationsInformation(specificationsName,serialNumberId,new Page<Objects>(pageNo, pageSize));
        Map<String, Object> map = new HashMap<>();
        map.put("row", pageList.getRecords());
        map.put("total", pageList.getTotal());
        return Result.success(map);
    }
 
    @ApiOperation("标准库-->产品规格-->编辑")
    @PutMapping("/update")
    public Result<?> updateSpecificationsInformation(@RequestHeader("X-Token") String token, @RequestBody UpdateSpecificationsInformation updateSpecificationsInformation) throws Exception {
        Object object = RedisUtil.get(token);
        if (ObjectUtils.isEmpty(object)){
            return Result.fail("对不起,请携带Token!");
        }
        Map<String, Object> unmarshal = JackSonUtil.unmarshal(JackSonUtil.marshal(object), Map.class);
        updateSpecificationsInformation.setUserId((Integer) unmarshal.get("id"));
        Specifications specifications = JackSonUtil.unmarshal(JackSonUtil.marshal(updateSpecificationsInformation), Specifications.class);
        Integer isStandardsSuccess = specificationsService.updateSpecificationsInformation(specifications);
        if (isStandardsSuccess == 1) {
            return Result.success("更新【"+ specifications.getName() +"】成功!");
        }
        return Result.fail("更新【"+ specifications.getName() +"】失败!");
    }
 
    @ApiOperation("标准库-->产品规格-->删除")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "specificationsId", value = "规格Id", dataTypeClass = Integer.class, required = true)
    })
    @DeleteMapping("/delete")
    public Result<?> deleteSpecificationsInformation(Integer specificationsId) {
        Integer isStandardsSuccess = specificationsService.deleteSpecifications(specificationsId);
        if (isStandardsSuccess == 1) {
            return Result.success("删除成功!");
        }
        return Result.fail("删除失败!");
    }
 
    @ApiOperation("标准库-->产品规格-->更新规格状态")
    @PutMapping("/update_spe_state")
    public Result<?> updateSpeStateSpecifications(@RequestBody UpdateSpeStateSpecifications updateSpeStateSpecifications) {
        Integer isStandardsSuccess = specificationsService.updateSpeStateSpecifications(updateSpeStateSpecifications);
        if (isStandardsSuccess == 1) {
            return Result.success("操作成功!");
        }
        return Result.fail("操作失败!");
    }
}