广丰卷烟厂数采质量分析系统
baoshiwei
19 小时以前 d143af7023cfd4a0ced6f0ecf04ae3b3a06fd1dc
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
package org.dromara.qa.md.controller;
 
import java.util.List;
import java.util.Map;
 
import lombok.RequiredArgsConstructor;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.dromara.qa.md.domain.bo.BatchCalibrateBo;
import org.dromara.qa.md.domain.bo.BatchConfigBo;
import org.dromara.qa.md.domain.WeighingBox;
import org.dromara.qa.md.service.IWeighingBoxService;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.mybatis.core.page.TableDataInfo;
 
/**
 * 称重盒子控制器
 * 
 * @author ruoyi
 * @date 2026-04-09
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/md/weighingBox")
public class WeighingBoxController extends BaseController {
 
    private final IWeighingBoxService weighingBoxService;
 
    /**
     * 查询称重盒子列表
     */
    @SaCheckPermission("md:weighingBox:list")
    @GetMapping("/list")
    public TableDataInfo<WeighingBox> list(WeighingBox weighingBox, PageQuery pageQuery) {
        return weighingBoxService.queryPageList(weighingBox, pageQuery);
    }
 
    /**
     * 获取称重盒子详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("md:weighingBox:query")
    @GetMapping("/{id}")
    public R<WeighingBox> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        WeighingBox box = weighingBoxService.getById(id);
        if (box != null) {
            weighingBoxService.calculateCalibStatus(box);
        }
        return R.ok(box);
    }
 
    /**
     * 新增称重盒子
     */
    @SaCheckPermission("md:weighingBox:add")
    @Log(title = "称重盒子", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody WeighingBox weighingBox) {
        return toAjax(weighingBoxService.insertWeighingBox(weighingBox));
    }
 
    /**
     * 修改称重盒子
     */
    @SaCheckPermission("md:weighingBox:edit")
    @Log(title = "称重盒子", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody WeighingBox weighingBox) {
        return toAjax(weighingBoxService.updateWeighingBox(weighingBox));
    }
 
    /**
     * 删除称重盒子
     *
     * @param ids 主键串
     */
    @SaCheckPermission("md:weighingBox:remove")
    @Log(title = "称重盒子", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(weighingBoxService.deleteWeighingBoxByIds(ids));
    }
 
    /**
     * 执行单个校准
     */
    @SaCheckPermission("md:weighingBox:calibrate")
    @Log(title = "称重盒子校准", businessType = BusinessType.UPDATE)
    @PostMapping("/calibrate")
    public R<Void> calibrate(@RequestBody Map<String, Object> params) {
        try {
            Long boxId = Long.valueOf(params.get("boxId").toString());
            String calibDate = params.get("calibDate").toString();
            java.math.BigDecimal actualWeight = params.containsKey("actualWeight") && params.get("actualWeight") != null ? new java.math.BigDecimal(params.get("actualWeight").toString()) : null;
            String note = params.containsKey("note") ? params.get("note").toString() : null;
            
            java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy-MM-dd");
            java.util.Date date = sdf.parse(calibDate);
            return toAjax(weighingBoxService.calibrate(boxId, date, actualWeight, note));
        } catch (Exception e) {
            return R.fail("日期格式错误");
        }
    }
 
    /**
     * 批量校准
     */
    @SaCheckPermission("md:weighingBox:batchCalibrate")
    @Log(title = "称重盒子批量校准", businessType = BusinessType.UPDATE)
    @PostMapping("/batchCalibrate")
    public R<Map<String, Object>> batchCalibrate(@RequestBody BatchCalibrateBo batchCalibrateDTO) {
        Map<String, Object> result = weighingBoxService.batchCalibrate(batchCalibrateDTO);
        return R.ok(result);
    }
 
    /**
     * 统一配置校准周期
     */
    @SaCheckPermission("md:weighingBox:batchConfig")
    @Log(title = "称重盒子统一配置", businessType = BusinessType.UPDATE)
    @PostMapping("/batchConfig")
    public R<Void> batchConfig(@RequestBody BatchConfigBo batchConfigDTO) {
        return toAjax(weighingBoxService.batchConfig(batchConfigDTO));
    }
 
    /**
     * 批量更新状态
     */
    @SaCheckPermission("md:weighingBox:batchUpdateStatus")
    @Log(title = "称重盒子批量更新状态", businessType = BusinessType.UPDATE)
    @PostMapping("/batchUpdateStatus")
    public R<Void> batchUpdateStatus(@RequestBody Map<String, Object> params) {
        List<Long> boxIds = (List<Long>) params.get("boxIds");
        Integer activeStatus = (Integer) params.get("activeStatus");
        return toAjax(weighingBoxService.batchUpdateStatus(boxIds, activeStatus));
    }
 
    /**
     * 复制盒子
     */
    @Log(title = "称重盒子复制", businessType = BusinessType.INSERT)
    @PostMapping("/copy")
    public R<Map<String, Object>> copy(@RequestBody Map<String, Object> params) {
        try {
            Long sourceId = Long.valueOf(params.get("sourceId").toString());
            Integer count = Integer.valueOf(params.get("count").toString());
            Map<String, Object> result = weighingBoxService.copyBox(sourceId, count);
            return R.ok(result);
        } catch (Exception e) {
            return R.fail(e.getMessage());
        }
    }
 
    /**
     * 获取校准状态统计
     */
    @GetMapping("/statistics")
    public R<Map<String, Integer>> statistics() {
        Map<String, Integer> statistics = weighingBoxService.getStatistics();
        return R.ok(statistics);
    }
}