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
package com.ruoyi.envaccess.controller;
 
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
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);
        LocalDateTime now = LocalDateTime.now();
        req.setCreateTime(now);
        req.setUpdateTime(now);
        return envWeighbridgeSystemService.save(req) ? AjaxResult.success() : AjaxResult.error("新增失败");
    }
 
    @PutMapping("/weighbridgeSystemUpdate")
    @Log(title = "无人值守地磅-修改", businessType = BusinessType.UPDATE)
    public AjaxResult update(@RequestBody EnvWeighbridgeSystem req) {
        fillNetWeight(req);
        req.setUpdateTime(LocalDateTime.now());
        return envWeighbridgeSystemService.updateById(req) ? AjaxResult.success() : AjaxResult.error("修改失败");
    }
 
    @DeleteMapping("/weighbridgeSystemDelete")
    @Log(title = "无人值守地磅-删除", businessType = BusinessType.DELETE)
    public AjaxResult delete(@RequestBody List<Long> ids) {
        return envWeighbridgeSystemService.removeByIds(ids) ? AjaxResult.success() : AjaxResult.error("删除失败");
    }
 
    /**
     * 每日过磅统计报表(车次 / 货量吨 / 偏差率)
     */
    @GetMapping("/weighbridgeDailyReport")
    public AjaxResult dailyReport(@RequestParam(required = false) String startDate,
                                  @RequestParam(required = false) String endDate) {
        List<Map<String, Object>> 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));
        }
    }
}