zss
2023-08-19 e6ffa9fcebef022be1e8e8162c65f52754f9081e
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
package com.yuanchu.limslaboratory.controller;
 
import com.baomidou.mybatisplus.core.metadata.IPage;
 
import java.text.ParseException;
import java.util.*;
 
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.yuanchu.limslaboratory.pojo.Inspection;
import com.yuanchu.limslaboratory.pojo.Report;
import com.yuanchu.limslaboratory.pojo.vo.InspectionVo;
import com.yuanchu.limslaboratory.service.LinkBasicInformationService;
import com.yuanchu.limslaboratory.service.RawMaterialService;
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.web.bind.annotation.*;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yuanchu.limslaboratory.service.InspectionService;
 
import javax.annotation.Resource;
 
/**
 * 申请表(Inspection)表控制层
 *
 * @author zss
 * @since 2023-08-03 13:03:36
 */
@Api(tags = "试验管理-->检验申请")
@RestController
@RequestMapping("/inspection")
public class InspectionController {
 
    @Autowired
    private InspectionService inspectionService;
 
    @Resource
    RawMaterialService rawMaterialService;
 
    @Resource
    LinkBasicInformationService linkBasicInformationService;
 
    @ApiOperation(value = "查询检验申请单列表")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "pageSize", value = "页数", dataTypeClass = Integer.class, required = true),
            @ApiImplicitParam(name = "countSize", value = "条数/页", dataTypeClass = Integer.class, required = true),
            @ApiImplicitParam(name = "message", value = "申请单号/原材料名称", dataTypeClass = String.class)
    })
    @GetMapping("/selectInspectsList")
    public Result selectInspectsList(int pageSize, int countSize, String message) {
        IPage<Map<String, Object>> inspectionPage = inspectionService.selectInspectsList(new Page<Object>(pageSize, countSize), message);
        Map<String, Object> map = new HashMap<>();
        map.put("total", inspectionPage.getTotal());
        map.put("row", inspectionPage.getRecords());
        return Result.success(map);
    }
 
 
    @ApiOperation(value = "查询所有报检")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "type", value = "类型", dataTypeClass = Integer.class, required = true)
    })
    @GetMapping("/selectAll")
    public Result selectAll(Integer type) {
        switch (type) {
            case 0:
                //原材料
                return Result.success(rawMaterialService.selectRawmaAll());
            case 1:
                //委托单
                return Result.success(linkBasicInformationService.selectLinkAll());
            case 2:
                //成品检验
                return Result.success("请输入检验信息!");
        }
        return Result.fail("类型错误!");
    }
 
 
    @ApiOperation(value = "新增检验单")
    @PostMapping("/addInspect")
    public Result addInspect(@RequestHeader("token") String token, @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));
    }
 
    @ApiOperation(value = "根据检验单id查询原材料检验单详情")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "id", value = "检验单id", dataTypeClass = Integer.class, required = true)
    })
    @GetMapping("/selectInspectsListById")
    public Result selectInspectsListById(Integer id) {
        return Result.success(inspectionService.selectInspectsListById(id));
    }
 
    @ApiOperation(value = "上报(更新检验状态)")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "id", value = "检验单id", dataTypeClass = Integer.class, required = true)
    })
    @PostMapping("/updateInspectsById")
    public Result updateInspectsById(Integer id) {
        //如果已经上报了不能再一次上报
        Inspection inspection = inspectionService.getById(id);
        if (ObjectUtils.isNotEmpty(inspection.getInspectionStatus())) {
            return Result.fail("已经上报过了,不能再次上报!");
        }
        return Result.success(inspectionService.updateInspectsById(id));
    }
 
}