自动化立体仓库 - WMS系统
chen.llin
2025-12-25 5232d8b5939cb832c3d17c2aa1d6eaf66e5acb74
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
package com.zy.asrs.controller;
 
import com.baomidou.mybatisplus.plugins.Page;
import com.core.annotations.ManagerAuth;
import com.core.common.R;
import com.zy.asrs.entity.MonthlySettle;
import com.zy.asrs.entity.MonthlySettleDetail;
import com.zy.asrs.entity.param.DateRangeParam;
import com.zy.asrs.entity.param.MonthlySettleQueryParam;
import com.zy.asrs.entity.result.MonthlySettleStatisticsVO;
import com.zy.asrs.service.MonthlySettleService;
import com.zy.common.web.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
 
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
 
@RestController
public class MonthlySettleController extends BaseController {
 
    @Autowired
    private MonthlySettleService monthlySettleService;
 
    /**
     * 获取月结信息
     */
    @RequestMapping(value = "/monthlySettle/{id}/auth")
    @ManagerAuth
    public R get(@PathVariable("id") Long id) {
        return R.ok(monthlySettleService.selectById(id));
    }
 
    /**
     * 分页查询月结列表
     */
    @RequestMapping(value = "/monthlySettle/list/auth")
    @ManagerAuth
    public R list(MonthlySettleQueryParam param) {
        Page<MonthlySettle> page = new Page<>(param.getCurr(), param.getLimit());
        java.util.Map<String, Object> condition = new java.util.HashMap<>();
        if (param.getSettleNo() != null && !param.getSettleNo().trim().isEmpty()) {
            condition.put("settleNo", param.getSettleNo());
        }
        if (param.getStatus() != null) {
            condition.put("status", param.getStatus());
        }
        if (param.getStartDate() != null && !param.getStartDate().trim().isEmpty() 
                && param.getEndDate() != null && !param.getEndDate().trim().isEmpty()) {
            condition.put("startDate", param.getStartDate());
            condition.put("endDate", param.getEndDate());
        }
        page.setCondition(condition);
        return R.ok(monthlySettleService.getPage(page));
    }
 
    /**
     * 获取最近的月结记录
     */
    @RequestMapping(value = "/monthlySettle/latest/auth")
    @ManagerAuth
    public R getLatest() {
        MonthlySettle latest = monthlySettleService.getLatestSettle();
        return R.ok(latest);
    }
 
    /**
     * 获取下一个月结的起始日期
     */
    @RequestMapping(value = "/monthlySettle/nextStartDate/auth")
    @ManagerAuth
    public R getNextStartDate() {
        Date nextStartDate = monthlySettleService.getNextStartDate();
        if (nextStartDate != null) {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            return R.ok(sdf.format(nextStartDate));
        }
        return R.ok(null);
    }
 
    /**
     * 获取最晚月结记录的结束日期
     */
    @RequestMapping(value = "/monthlySettle/latestEndDate/auth")
    @ManagerAuth
    public R getLatestEndDate() {
        Date latestEndDate = monthlySettleService.getLatestEndDate();
        if (latestEndDate != null) {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            return R.ok(sdf.format(latestEndDate));
        }
        return R.ok(null);
    }
 
    /**
     * 检查月结时间范围内是否有未完成的订单
     */
    @RequestMapping(value = "/monthlySettle/checkUnfinished/auth")
    @ManagerAuth
    public R checkUnfinished(DateRangeParam param) {
        boolean hasUnfinished = monthlySettleService.hasUnfinishedOrders(param.getStartDate(), param.getEndDate());
        if (hasUnfinished) {
            return R.error("月结时间范围内存在未完成的订单,无法进行月结");
        }
        return R.ok();
    }
 
    /**
     * 发起月结
     */
    @RequestMapping(value = "/monthlySettle/start/auth")
    @ManagerAuth
    public R startSettle(DateRangeParam param) {
        return R.ok(monthlySettleService.startSettle(param.getStartDate(), param.getEndDate(), getUserId()));
    }
 
    /**
     * 获取月结统计信息
     */
    @RequestMapping(value = "/monthlySettle/statistics/{id}/auth")
    @ManagerAuth
    public R getStatistics(@PathVariable("id") Long id) {
        return R.ok(monthlySettleService.getSettleStatistics(id));
    }
 
    /**
     * 删除月结记录
     */
    @RequestMapping(value = "/monthlySettle/{id}/auth", method = RequestMethod.DELETE)
    @ManagerAuth
    public R delete(@PathVariable("id") Long id) {
        monthlySettleService.deleteSettle(id);
        return R.ok("删除成功");
    }
 
    /**
     * 导出月结明细
     */
    @RequestMapping(value = "/monthlySettle/detail/export/{id}/auth")
    @ManagerAuth(memo = "导出月结明细")
    public R exportDetail(@PathVariable("id") Long id) {
        // 获取月结统计信息
        MonthlySettleStatisticsVO statistics = monthlySettleService.getSettleStatistics(id);
        if (statistics == null || statistics.getDetails() == null) {
            return R.error("月结明细不存在");
        }
        
        List<MonthlySettleDetail> details = statistics.getDetails();
        
        // 定义导出字段
        List<String> fields = new ArrayList<>();
        fields.add("matnr");
        fields.add("maktx");
        fields.add("batch");
        fields.add("brand");
        fields.add("beginningQty");
        fields.add("endingQty");
        fields.add("diffQty");
        fields.add("inQty");
        fields.add("outQty");
        
        return R.ok(exportSupport(details, fields));
    }
 
}