Fixiaobai
2023-09-05 c9da1b0da1178911e383ddcaebecd1e088fa6004
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
package com.yuanchu.limslaboratory.controller;
 
 
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.pojo.Instrument;
import com.yuanchu.limslaboratory.pojo.dto.UpdateInstrumentDto;
import com.yuanchu.limslaboratory.service.InstrumentService;
import com.yuanchu.limslaboratory.service.UserService;
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 java.util.HashMap;
import java.util.Map;
import java.util.Objects;
 
/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 江苏鵷雏网络科技有限公司
 * @since 2023-07-20
 */
@Api(tags = "实验室-->1、设备台账-->2、仪器模块")
@RestController
@RequestMapping("/instrument")
public class InstrumentController {
 
    @Autowired
    private InstrumentService instrumentService;
 
    @Autowired
    private UserService userService;
 
    @ApiOperation("添加仪器设备")
    @PostMapping("/add")
    @AuthHandler
    public Result<?> addInstrumentInformation(@RequestHeader("X-Token") String token, @RequestBody Instrument instrument) throws Exception {
        Object object = RedisUtil.get(token);
        Map<String, Object> unmarshal = JackSonUtil.unmarshal(JackSonUtil.marshal(object), Map.class);
        instrument.setCreateUserId((Integer) unmarshal.get("id"));
        Integer isInsertSuccess = instrumentService.addInstrumentInformation(instrument);
        if (isInsertSuccess == 1){
            return Result.success("添加【" + instrument.getEquipmentName() + "】成功!");
        }
        return Result.fail("仪器设备编号重复,添加【" + instrument.getEquipmentName() + "】失败! ");
    }
 
    @ApiOperation("根据分类Id:分页列表展示")
    @GetMapping("/list")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "classifyId", value = "分类Id", dataTypeClass = Integer.class, required = true),
            @ApiImplicitParam(name = "pageNo", value = "起始页", dataTypeClass = Integer.class, required = true),
            @ApiImplicitParam(name = "pageSize", value = "每一页数量", dataTypeClass = Integer.class, required = true),
            @ApiImplicitParam(name = "conditions", value = "查询状态:默认全部", dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "whetherWhether", value = "是否已过期", dataTypeClass = Boolean.class),
            @ApiImplicitParam(name = "numberOrNameOrSpecifications", value = "编号/设备名称/规格型号", dataTypeClass = String.class)
    })
    @AuthHandler
    public Result<?> getListInstrumentInformation(Integer pageNo,
                                                  Integer pageSize,
                                                  Integer conditions,
                                                  Integer classifyId,
                                                  Boolean whetherWhether,
                                                  String numberOrNameOrSpecifications) {
        IPage<Map<String, Object>> pageList = instrumentService.getListInstrumentInformation(conditions, whetherWhether, numberOrNameOrSpecifications,
                classifyId, 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("删除仪器数据")
    @DeleteMapping("/delete")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "instrumentId", value = "仪器Id", dataTypeClass = String.class, required = true)
    })
    @AuthHandler
    public Result<?> deleteInstrumentInformation(String instrumentId) {
        Boolean isDeleteSuccess = instrumentService.deleteInstrumentInformation(instrumentId);
        if (isDeleteSuccess){
            return Result.success("删除仪器成功!");
        }
        return Result.fail("删除仪器失败!");
    }
 
    @ApiOperation("添加仪器时保管人下拉框数据")
    @GetMapping("/get_user")
    @AuthHandler
    public Result<?> getMapUserInformation() {
        return Result.success(userService.getUserNameAndId());
    }
 
    @ApiOperation("根据仪器Id获取信息用于编辑")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "InstrumentId", value = "分类Id", dataTypeClass = Integer.class, required = true)
    })
    @GetMapping("/get_instrument")
    @AuthHandler
    public Result<?> getIdInstrumentInformation(Integer InstrumentId) {
        return Result.success(instrumentService.getIdInstrumentInformation(InstrumentId));
    }
 
    @ApiOperation("根据仪器Id更新数据")
    @PutMapping("/update")
    @AuthHandler
    public Result<?> updateEquipmentPointInformation(@RequestBody UpdateInstrumentDto updateInstrumentDto) throws Exception {
        Instrument instrument = JackSonUtil.unmarshal(JackSonUtil.marshal(updateInstrumentDto), Instrument.class);
        Integer isUpdateSuccess = instrumentService.updateEquipmentPointInformation(instrument);
        if (isUpdateSuccess == 1){
            return Result.success("更新【" + instrument.getEquipmentName() + "】成功!");
        }
        return Result.fail("仪器设备编号重复,更新【" + instrument.getEquipmentName() + "】失败! ");
    }
}