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 list(WeighingBox weighingBox, PageQuery pageQuery) { return weighingBoxService.queryPageList(weighingBox, pageQuery); } /** * 获取称重盒子详细信息 * * @param id 主键 */ @SaCheckPermission("md:weighingBox:query") @GetMapping("/{id}") public R 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 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 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 remove(@NotEmpty(message = "主键不能为空") @PathVariable Long[] ids) { return toAjax(weighingBoxService.deleteWeighingBoxByIds(ids)); } /** * 执行单个校准 */ @SaCheckPermission("md:weighingBox:calibrate") @Log(title = "称重盒子校准", businessType = BusinessType.UPDATE) @PostMapping("/calibrate") public R calibrate(@RequestBody Map 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> batchCalibrate(@RequestBody BatchCalibrateBo batchCalibrateDTO) { Map result = weighingBoxService.batchCalibrate(batchCalibrateDTO); return R.ok(result); } /** * 统一配置校准周期 */ @SaCheckPermission("md:weighingBox:batchConfig") @Log(title = "称重盒子统一配置", businessType = BusinessType.UPDATE) @PostMapping("/batchConfig") public R batchConfig(@RequestBody BatchConfigBo batchConfigDTO) { return toAjax(weighingBoxService.batchConfig(batchConfigDTO)); } /** * 批量更新状态 */ @SaCheckPermission("md:weighingBox:batchUpdateStatus") @Log(title = "称重盒子批量更新状态", businessType = BusinessType.UPDATE) @PostMapping("/batchUpdateStatus") public R batchUpdateStatus(@RequestBody Map params) { List boxIds = (List) params.get("boxIds"); Integer activeStatus = (Integer) params.get("activeStatus"); return toAjax(weighingBoxService.batchUpdateStatus(boxIds, activeStatus)); } /** * 复制盒子 */ @Log(title = "称重盒子复制", businessType = BusinessType.INSERT) @PostMapping("/copy") public R> copy(@RequestBody Map params) { try { Long sourceId = Long.valueOf(params.get("sourceId").toString()); Integer count = Integer.valueOf(params.get("count").toString()); Map result = weighingBoxService.copyBox(sourceId, count); return R.ok(result); } catch (Exception e) { return R.fail(e.getMessage()); } } /** * 获取校准状态统计 */ @GetMapping("/statistics") public R> statistics() { Map statistics = weighingBoxService.getStatistics(); return R.ok(statistics); } }