Fixiaobai
2023-08-21 1d1091013432cbac77a38b32d7d6d4f809b1b378
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
package com.yuanchu.limslaboratory.controller;
 
import com.yuanchu.limslaboratory.pojo.MetricalInformation;
import com.yuanchu.limslaboratory.pojo.dto.UpdateMetricalInformationDto;
import com.yuanchu.limslaboratory.service.MetricalInformationService;
import com.yuanchu.limslaboratory.service.UserService;
import com.yuanchu.limslaboratory.utils.JackSonUtil;
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 org.springframework.web.multipart.MultipartFile;
 
import java.util.List;
import java.util.Map;
 
/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 江苏鵷雏网络科技有限公司
 * @since 2023-07-20
 */
@Api(tags = "实验室-->1、设备台账-->4、计量信息")
@RestController
@RequestMapping("/metrical-information")
public class MetricalInformationController {
 
    @Autowired
    private MetricalInformationService metricalInformationService;
 
    @Autowired
    private UserService userService;
 
    @ApiOperation("添加计量信息")
    @PostMapping("/add")
    public Result<?> addMetricalInformation(MetricalInformation metricalInformation,
                                            @RequestPart(value = "file", required = false) MultipartFile file) {
        Integer isInsertSuccess = metricalInformationService.addEquipmentPointInformation(metricalInformation, file);
        if (isInsertSuccess == 1){
            return Result.success("添加【"+ metricalInformation.getMeasurementUnit() +"】成功!");
        }
        return Result.fail("添加【"+ metricalInformation.getMeasurementUnit() +"】失败!设备码点编码重复!");
    }
 
    @ApiOperation("查询所有计量信息数据")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "InstrumentId", value = "仪器模块Id", dataTypeClass = String.class, required = true)
    })
    @GetMapping("/list")
    public Result<?> getListMetricalInformation(String InstrumentId) {
        List<Map<String, Object>> list = metricalInformationService.getListEquipmentPointInformation(InstrumentId);
        return Result.success(list);
    }
 
    @ApiOperation("根据计量信息Id删除数据")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "metricalInformationId", value = "计量信息Id", dataTypeClass = Integer.class, required = true)
    })
    @DeleteMapping("/delete")
    public Result<?> deleteMetricalInformation(Integer metricalInformationId) {
        Integer isDeleteSuccess = metricalInformationService.deleteMetricalInformation(metricalInformationId);
        if (isDeleteSuccess == 1){
            return Result.success("删除成功!");
        }
        return Result.fail("删除失败!");
    }
 
    @ApiOperation("根据计量信息Id更新数据")
    @PutMapping("/update")
    public Result<?> updateMetricalInformation(UpdateMetricalInformationDto updateMetricalInformationDto,
                                                     @RequestPart(value = "file", required = false) MultipartFile file) throws Exception {
        MetricalInformation metricalInformation = JackSonUtil.unmarshal(JackSonUtil.marshal(updateMetricalInformationDto), MetricalInformation.class);
        Integer isUpdateSuccess = metricalInformationService.updateMetricalInformation(metricalInformation, file);
        if (isUpdateSuccess == 1){
            return Result.success("更新成功!");
        }
        return Result.fail("更新失败!");
    }
 
    @ApiOperation("添加计量信息时负责人下拉框数据")
    @GetMapping("/get_user")
    public Result<?> getMapUserInformation() {
        return Result.success(userService.getUserNameAndId());
    }
 
    @ApiOperation("更新计量结果")
    public Result<?> updateMetricalInformationResult(String code,Integer result){
        return null;
    }
 
}