zss
2023-09-09 f9e06198cfbccf337b53c0fa6cb3404455ceb0ba
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
package com.yuanchu.mom.controller;
 
import com.yuanchu.mom.pojo.MeteringPlan;
import com.yuanchu.mom.service.DeviceService;
import com.yuanchu.mom.service.MeteringPlanService;
import com.yuanchu.mom.service.UserService;
import com.yuanchu.mom.utils.JackSonUtil;
import com.yuanchu.mom.utils.Jwt;
import com.yuanchu.mom.utils.MyUtil;
import com.yuanchu.mom.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.validation.Valid;
import java.util.List;
import java.util.Map;
 
/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 江苏鵷雏网络科技有限公司
 * @since 2023-08-16 11:42:31
 */
@Api(tags = "QMS管理-->计量管理")
@RestController
@RequestMapping("/meteringPlan")
public class MeteringPlanController {
 
    @Autowired
    private MeteringPlanService meteringPlanService;
 
    @Autowired
    private UserService userService;
 
    @Autowired
    private DeviceService deviceService;
 
    @Autowired
    private Jwt jwt;
    @ApiOperation(value = "计量计划-->新增按钮")
    @PostMapping("/add_plan")
    public Result<?> addMeteringPlan(@RequestHeader("token") String token, @Validated @RequestBody MeteringPlan meteringPlan) throws Exception {
        Map<String, String> data = JackSonUtil.unmarshal(jwt.readJWT(token).get("data"), Map.class);
        String id = data.get("id").replaceAll("\"", "");
        meteringPlan.setFounder(Integer.valueOf(id));
        Integer isInsertSuccess = meteringPlanService.addMeteringPlan(meteringPlan);
        if (isInsertSuccess == 1){
            return Result.success("新增成功!");
        }
        return Result.fail("新增失败!");
    }
 
    @ApiOperation(value = "计量计划-->负责人下拉框")
    @GetMapping("/list_user")
    public Result<?> selectUserIdAndName(){
        List<Map<String, Object>> maps = userService.listUserIdAndName();
        return Result.success(maps);
    }
 
    @ApiOperation(value = "计量计划-->计量单位下拉框")
    @GetMapping("/list_unit")
    public Result<?> selectUnit(){
        List<Map<String, Object>> maps = meteringPlanService.selectUnit();
        return Result.success(maps);
    }
 
    @ApiOperation(value = "计量计划-->分页表格")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "pageNo", value = "条数/页", dataTypeClass = Integer.class, required = true),
            @ApiImplicitParam(name = "pageSize", value = "页数", dataTypeClass = Integer.class, required = true),
            @ApiImplicitParam(name = "code", value = "计量编号", dataTypeClass = String.class),
            @ApiImplicitParam(name = "meteringUnit", value = "计量单位", dataTypeClass = String.class)
    })
    @GetMapping("/metering_table")
    public Result<?> selectMeteringTable(Integer pageNo, Integer pageSize, String code, String meteringUnit){
        pageNo = (pageNo - 1) * pageSize;
        Map<String, Object> maps = meteringPlanService.selectMeteringTable(pageNo, pageSize, code, meteringUnit);
        return Result.success(maps);
    }
 
    @ApiOperation(value = "计量计划<-->计量台账:查看计量履历")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "pageNo", value = "条数/页", dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "pageSize", value = "页数", dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "measureId", value = "计量Id", dataTypeClass = Integer.class, required = true),
            @ApiImplicitParam(name = "accountOrPlan", value = "true为台账|false为计划", dataTypeClass = Boolean.class, required = true),
    })
    @GetMapping("/list_record")
    public Result<?> standingBook(Integer pageNo, Integer pageSize, Integer measureId, Boolean accountOrPlan){
        Object maps = meteringPlanService.standingBook(pageNo, pageSize, measureId, accountOrPlan);
        return Result.success(maps);
    }
 
    @ApiOperation(value = "计量计划:新增按钮:点击新增行后提交设备名称")
    @GetMapping("/list_device")
    public Result<?> selectOneDeviceId(){
        List<Map<String, Object>> mapList = deviceService.selectDeviceIdAndName();
        return Result.success(mapList);
    }
}