李林
2023-07-17 150c89bd7d5037024468417f5ac11fd518ca44d3
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
package com.yuanchu.limslaboratory.controller;
 
 
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.yuanchu.limslaboratory.pojo.Inspection;
import com.yuanchu.limslaboratory.pojo.InspectionProductList;
import com.yuanchu.limslaboratory.pojo.Product;
import com.yuanchu.limslaboratory.service.InspectionProductListService;
import com.yuanchu.limslaboratory.service.InspectionService;
import com.yuanchu.limslaboratory.service.ProductService;
import com.yuanchu.limslaboratory.service.SpecificationsService;
import com.yuanchu.limslaboratory.utils.JackSonUtil;
import com.yuanchu.limslaboratory.utils.RedisUtil;
import com.yuanchu.limslaboratory.vo.Result;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
 
import org.springframework.web.bind.annotation.RestController;
 
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
 
/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author 江苏鵷雏网络科技有限公司
 * @since 2023-07-17
 */
@ApiModel(value = "检验模块")
@RestController
@RequestMapping("/inspection")
public class InspectionController {
 
    @Autowired
    private InspectionService inspectionService;
 
    @Autowired
    private ProductService productService;
 
    @Autowired
    private SpecificationsService specificationsService;
 
    @Autowired
    private InspectionProductListService inspectionProductListService;
 
    @ApiOperation("添加检验申请单")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "materialId", value = "物料信息id", dataTypeClass = Integer.class, required = true),
    })
    @PostMapping("/addInspection")
    @Transactional(rollbackFor = Exception.class)
    public Result addInspection(@RequestHeader("X-Token") String token, int materialId,int type) throws Exception {
        List<Product> list = productService.selectProductByMaterialId(materialId);
        Map<String, Object> map = specificationsService.selectSNameSNName(materialId);
        if (map==null)return Result.fail("找不到该物料信息");
        Object object = RedisUtil.get(token);
        Map<String, Object> unmarshal = JackSonUtil.unmarshal(JackSonUtil.marshal(object), Map.class);
        Inspection inspection = new Inspection();
        inspection.setId(IdWorker.getIdStr())
                .setType(type)
                .setInspectionStatus(0)
                .setState(1)
                .setVersion(1)
                .setUserName("" + unmarshal.get("name"))
                .setMaterialNum(Integer.valueOf("" + map.get("num")))
                .setMaterialSupplier("" + map.get("supplier"))
                .setMaterialName("" + map.get("m_name"))
                .setMaterialLocation("" + map.get("location"))
                .setMaterialBatch("" + map.get("batch"))
                .setMaterialReelNumber("" + map.get("reel_number"))
                .setSpecificationsSerialNumber("" + map.get("ss_name"))
                .setSpecificationsVoltageLevel("" + map.get("voltage_level"))
                .setSpecificationsCrossSection("" + map.get("cross_section"))
                .setSpecificationsNumberOfCores("" + map.get("number_of_cores"))
                .setSpecificationsInstruct("" + map.get("instruct"));
        int judge1 = 0;
        int judge2 = 0;
        try {
            judge1 = inspectionService.addInspection(inspection);
            List<InspectionProductList> list2 = new ArrayList<>();
            list.forEach(a -> {
                InspectionProductList inspectionProductList = new InspectionProductList();
                inspectionProductList.setName(a.getName())
                        .setMethod(a.getMethod())
                        .setUnit(a.getUnit())
                        .setRequired(a.getRequired())
                        .setInternal(a.getInternal())
                        .setState(1)
                        .setVersion(1)
                        .setInspectionId(inspection.getId())
                        .setUserId(Integer.parseInt("" + unmarshal.get("id")))
                        .setCreateTime(new Date())
                        .setUpdateTime(new Date());
                list2.add(inspectionProductList);
            });
            judge2 = inspectionProductListService.addInspectionProductList(list2);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return Result.success(judge1 > 0 && judge2 > 0 ? "提交成功" : "提交失败", judge1 > 0 && judge2 > 0);
    }
}