package com.ruoyi.envaccess.controller; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.ruoyi.common.handler.CustomTenantLineHandler; import com.ruoyi.envaccess.pojo.EnvWeighbridgeSystem; import com.ruoyi.envaccess.service.IEnvWeighbridgeSystemService; import com.ruoyi.framework.aspectj.lang.annotation.Log; import com.ruoyi.framework.aspectj.lang.enums.BusinessType; import com.ruoyi.framework.web.domain.AjaxResult; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import java.math.BigDecimal; import java.time.LocalDateTime; import java.util.List; import java.util.Map; /** * 环保门禁--无人值守地磅管理 / 报表中心 */ @RestController @RequestMapping("/environmentAccess") public class EnvWeighbridgeController { @Resource private IEnvWeighbridgeSystemService envWeighbridgeSystemService; @GetMapping("/weighbridgeSystemPage") public AjaxResult page(Page page, EnvWeighbridgeSystem req) { return AjaxResult.success(envWeighbridgeSystemService.listPage(page, req)); } @GetMapping("/weighbridgeSystemInfo") public AjaxResult info(@RequestParam Long id) { return AjaxResult.success(envWeighbridgeSystemService.getById(id)); } @PostMapping("/weighbridgeSystemAdd") @Log(title = "无人值守地磅-新增", businessType = BusinessType.INSERT) public AjaxResult add(@RequestBody EnvWeighbridgeSystem req) { req.setId(null); fillNetWeight(req); // 租户插件在本表 insert 时会抛 SetOperationList 解析异常,临时跳过; // tenant_id / create_time / update_time 由实体上的 @TableField(fill=...) 自动填充 CustomTenantLineHandler.TEMP_IGNORE.set(Boolean.TRUE); try { return envWeighbridgeSystemService.save(req) ? AjaxResult.success() : AjaxResult.error("新增失败"); } finally { CustomTenantLineHandler.TEMP_IGNORE.remove(); } } @PutMapping("/weighbridgeSystemUpdate") @Log(title = "无人值守地磅-修改", businessType = BusinessType.UPDATE) public AjaxResult update(@RequestBody EnvWeighbridgeSystem req) { fillNetWeight(req); CustomTenantLineHandler.TEMP_IGNORE.set(Boolean.TRUE); try { return envWeighbridgeSystemService.updateById(req) ? AjaxResult.success() : AjaxResult.error("修改失败"); } finally { CustomTenantLineHandler.TEMP_IGNORE.remove(); } } @DeleteMapping("/weighbridgeSystemDelete") @Log(title = "无人值守地磅-删除", businessType = BusinessType.DELETE) public AjaxResult delete(@RequestBody List ids) { CustomTenantLineHandler.TEMP_IGNORE.set(Boolean.TRUE); try { return envWeighbridgeSystemService.removeByIds(ids) ? AjaxResult.success() : AjaxResult.error("删除失败"); } finally { CustomTenantLineHandler.TEMP_IGNORE.remove(); } } /** * 每日过磅统计报表(车次 / 货量吨 / 偏差率) */ @GetMapping("/weighbridgeDailyReport") public AjaxResult dailyReport(@RequestParam(required = false) String startDate, @RequestParam(required = false) String endDate) { List> list = envWeighbridgeSystemService.dailyReport(startDate, endDate); return AjaxResult.success(list); } /** * 净重 = 毛重 - 皮重 */ private void fillNetWeight(EnvWeighbridgeSystem req) { if (req.getNetWeight() == null && req.getGrossWeight() != null && req.getTareWeight() != null) { req.setNetWeight(req.getGrossWeight().subtract(req.getTareWeight()).setScale(2, BigDecimal.ROUND_HALF_UP)); } } }