Fixiaobai
2023-09-06 8abe275e36823f1065300af45e1f7a9a68f549a7
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
package com.yuanchu.limslaboratory.controller;
 
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yuanchu.limslaboratory.annotation.AuthHandler;
import com.yuanchu.limslaboratory.enums.InterfaceType;
import com.yuanchu.limslaboratory.enums.MenuEnums;
import com.yuanchu.limslaboratory.mapper.ProductMapper;
import com.yuanchu.limslaboratory.pojo.Material;
import com.yuanchu.limslaboratory.pojo.Product;
import com.yuanchu.limslaboratory.pojo.RawMaterial;
import com.yuanchu.limslaboratory.pojo.vo.InspectionVo;
import com.yuanchu.limslaboratory.service.*;
import com.yuanchu.limslaboratory.utils.JackSonUtil;
import com.yuanchu.limslaboratory.utils.RedisUtil;
import com.yuanchu.limslaboratory.vo.Result;
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.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
 
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
 
/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 江苏鵷雏网络科技有限公司
 * @since 2023-07-28
 */
@Api(tags = "报检管理-->原材料报检-->页面版本表")
@RestController
@RequestMapping("/raw-material")
public class RawMaterialController {
 
    @Autowired
    private RawMaterialService rawMaterialService;
 
    @Autowired
    private StandardService standardService;
 
    @Autowired
    private MaterialService materialService;
 
    @Resource
    private ProductMapper productMapper;
 
    @Resource
    private InspectionService inspectionService;
 
    @ApiOperation("查询所有检验计划分配")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "pageNo", value = "起始页", dataTypeClass = Integer.class, required = true),
            @ApiImplicitParam(name = "pageSize", value = "每一页数量", dataTypeClass = Integer.class, required = true),
            @ApiImplicitParam(name = "materialCoding", value = "材料编码", dataTypeClass = String.class),
            @ApiImplicitParam(name = "materialName", value = "材料名称", dataTypeClass = String.class),
            @ApiImplicitParam(name = "type", value = "状态", dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "createTime", value = "来料日期", dataTypeClass = String.class)
    })
    @GetMapping("/selectAll")
    @AuthHandler
    public Result<?> selectRawMaterial(Integer pageSize, Integer pageNo, String materialCoding, String materialName, Integer type, String createTime) {
        IPage<RawMaterial> iPage = rawMaterialService.selectRawMaterial(materialCoding, materialName, type, createTime, new Page<Objects>(pageNo, pageSize));
        Map<String, Object> map = new HashMap<>();
        map.put("row", iPage.getRecords());
        map.put("total", iPage.getTotal());
        return Result.success(map);
    }
 
    @ApiOperation("原材料报检添加")
    @PostMapping("/add")
    @AuthHandler(type = InterfaceType.ADD,menuId = MenuEnums.reportForInspection,isAdd = true)
    public Result<?> insertRawMaterial(@Validated @RequestBody RawMaterial rawMaterial) {
        Integer integer = rawMaterialService.insertRawMaterial(rawMaterial);
        if (integer >= 1) {
            return Result.success("添加成功");
        }
        return Result.fail("添加失败");
    }
 
    @ApiOperation("原材料报检删除")
    @PostMapping("/delete")
    @AuthHandler(type = InterfaceType.DELETE,menuId = MenuEnums.reportForInspection,isAdd = true)
    public Result<?> deleteRawMaterial(String deleteId) {
        Integer integer = rawMaterialService.deleteRawMaterial(deleteId);
        if (integer >= 1) {
            return Result.success("删除成功");
        }
        return Result.fail("删除失败");
    }
 
 
    @ApiOperation("获取物料名称")
    @GetMapping("/getMaterielName")
    @AuthHandler(type = InterfaceType.SELECT,menuId = MenuEnums.reportForInspection,isAdd = true)
    public Result<?> getMaterielName(){
        LambdaQueryWrapper<Material> wrapper = new LambdaQueryWrapper<>();
        wrapper.select(Material::getId, Material::getName, Material::getCode)
                .eq(Material::getType,0).eq(Material::getState,1);
        List<Map<String, Object>> maps = materialService.listMaps(wrapper);
        return Result.success(maps);
    }
 
    @ApiOperation("获取规格型号")
    @GetMapping("/specification")
    @AuthHandler(type = InterfaceType.SELECT,menuId = MenuEnums.reportForInspection,isAdd = true)
    public Result<?> getSpecificationIdAndName(String materialId) {
        List<Map<String, Object>> specificationIdAndName = standardService.getSpecificationIdAndName(materialId);
        return Result.success(specificationIdAndName);
    }
 
    @ApiOperation("选择版本")
    @GetMapping("/chooseVer")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "name", value = "产品名称", dataTypeClass = String.class, required = true),
            @ApiImplicitParam(name = "mcode", value = "产品编号", dataTypeClass = String.class, required = true),
            @ApiImplicitParam(name = "specifications", value = "规格型号", dataTypeClass = String.class, required = true)
    })
    @AuthHandler(type = InterfaceType.SELECT,menuId = MenuEnums.reportForInspection,isAdd = true)
    public Result<?> chooseVer(String name, String mcode, String specifications) {
        return Result.success(inspectionService.chooseVer(name, mcode, specifications));
    }
 
 
    @ApiOperation(value = "查看该版本下我们要做的项目要求")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "name", value = "产品名称", dataTypeClass = String.class, required = true),
            @ApiImplicitParam(name = "mcode", value = "产品编号", dataTypeClass = String.class, required = true),
            @ApiImplicitParam(name = "specifications", value = "规格型号", dataTypeClass = String.class, required = true),
            @ApiImplicitParam(name = "version", value = "版本(默认最新版本)", dataTypeClass = Integer.class,required = true ),
    })
    @GetMapping("/lookProByVer")
    @AuthHandler(type = InterfaceType.SELECT,menuId = MenuEnums.reportForInspection,isAdd = true)
    public Result lookProByVer(String name, String mcode, String specifications,Integer version) {
        return Result.success(inspectionService.lookProByVer(name, mcode, specifications,version,null));
    }
 
    @ApiOperation(value = "原材料生成报检单")
    @PostMapping("/addInspect")
    @AuthHandler(type = InterfaceType.ADD,menuId = MenuEnums.reportForInspection,isAdd = true)
    public Result addInspect(@RequestHeader("X-Token") String token, @Validated @RequestBody InspectionVo inspectionVo) throws Exception {
        Object object = RedisUtil.get(token);
        Map<String, Object> unmarshal = JackSonUtil.unmarshal(JackSonUtil.marshal(object), Map.class);
        return Result.success(inspectionService.addInspect((Integer) unmarshal.get("id"), inspectionVo));
    }
 
}