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);
|
}
|
}
|