自动化立体仓库 - WMS系统
#
18516761980
2021-09-08 93b591f65d0dbc0ab2238fb8a027c58f44e5fb66
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
package com.zy.asrs.controller;
 
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.core.annotations.ManagerAuth;
import com.core.common.R;
import com.core.exception.CoolException;
import com.zy.asrs.entity.LocDetl;
import com.zy.asrs.entity.MatCode;
import com.zy.asrs.service.LocDetlService;
import com.zy.asrs.service.MatCodeService;
import com.zy.asrs.utils.VersionUtils;
import com.zy.common.web.BaseController;
import com.zy.ints.entity.StockSync;
import com.zy.ints.service.StockSyncService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
 
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URLEncoder;
import java.util.Date;
import java.util.List;
import java.util.Map;
 
/**
 * Created by vincent on 2021/4/2
 */
@RestController
public class StatisController extends BaseController {
 
    @Autowired
    private MatCodeService matCodeService;
    @Autowired
    private LocDetlService locDetlService;
    @Autowired
    StockSyncService stockSyncService;
 
    // 库存统计 ------------------------------------------------------------------------------------------
 
    @RequestMapping(value = "/stock/statis/auth")
    @ManagerAuth
    public R stockStatis(@RequestParam(defaultValue = "1")Integer curr,
                         @RequestParam(defaultValue = "14")Integer limit,
//                         @RequestParam(required = false)String condition,
                         @RequestParam Map<String, Object> param) {
        Page<LocDetl> stockStatis = locDetlService.getStockStatis(toPage(curr, limit, param, LocDetl.class));
        for (LocDetl locDetl : stockStatis.getRecords()) {
            MatCode mat = matCodeService.selectOne(new EntityWrapper<MatCode>().eq("mat_no",locDetl.getMatNo()));
//            MatCode mat = matCodeService.selectById(locDetl.getMatnr());
            if (mat != null) {
                VersionUtils.setLocDetl(locDetl, mat);
            }
        }
        return R.ok().add(stockStatis);
    }
 
    //库位报表导出
    @RequestMapping(value = "/stock/statis/export")
    public void stockStatisExport(HttpServletResponse response) throws IOException {
        List<LocDetl> excel = locDetlService.getStockStatisExcel();
        for (LocDetl locDetl : excel) {
            MatCode mat = matCodeService.selectById(locDetl.getMatNo());
            if (mat != null) {
                VersionUtils.setLocDetl(locDetl, mat);
            }
        }
        response.setContentType("application/vnd.ms-excel");
        response.setCharacterEncoding("utf-8");
        String fileName = URLEncoder.encode("库存明细统计报表", "UTF-8");
        response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx");
        EasyExcel.write(response.getOutputStream(), LocDetl.class)
                .registerWriteHandler(new LongestMatchColumnWidthStyleStrategy())
                .sheet("sheet1")
                .doWrite(excel);
    }
 
    /**
     * 获取库存同步表数据
     * @return
     */
    @RequestMapping(value = "/stock/stockSyncCount")
    @ManagerAuth(memo = "获取库存同步上传清单数量")
    public R getStockSyncCount() {
        return R.ok(stockSyncService.getStockSyncCount());
    }
 
    /**
     * 插入数据到库存同步表
     * @return
     */
    @RequestMapping(value = "/stock/insertStockSync")
    @ManagerAuth(memo = "同步上传清单数据插入")
    @Transactional
    public R insertStockSync() {
        Date now = new Date();
        Long userId = getUserId();
        List<LocDetl> locDetls = locDetlService.getStockSum();
        for(LocDetl locdetl : locDetls){
            StockSync stockSync = new StockSync();
            stockSync.setMatNo(locdetl.getMatNo());
            stockSync.setMatName(locdetl.getMatName());
            stockSync.setQty(locdetl.getQty());
            stockSync.setModiUser(userId);
            stockSync.setModiTime(now);
            stockSync.setAppeUser(userId);
            stockSync.setAppeTime(now);
            if(!stockSyncService.insert(stockSync)){
                throw new CoolException("插入同步库存数据失败");
            }
        }
        return R.ok(locDetls.size());
    }
 
    /**
     * 更新数据到库存同步表,先清空再插入
     * @return
     */
    @RequestMapping(value = "/stock/updateStockSync")
    @ManagerAuth(memo = "清空同步上传数据并插入")
    @Transactional
    public R updateStockSync() {
        if(!stockSyncService.clearStockSync()){
            throw new CoolException("同步上传数据清空失败,请联系管理员");
        }
 
        Date now = new Date();
        Long userId = getUserId();
        List<LocDetl> locDetls = locDetlService.getStockSum();
        for(LocDetl locdetl : locDetls){
            StockSync stockSync = new StockSync();
            stockSync.setMatNo(locdetl.getMatNo());
            stockSync.setMatName(locdetl.getMatName());
            stockSync.setQty(locdetl.getQty());
            stockSync.setModiUser(userId);
            stockSync.setModiTime(now);
            stockSync.setAppeUser(userId);
            stockSync.setAppeTime(now);
            if(!stockSyncService.insert(stockSync)){
                throw new CoolException("更新同步库存数据失败");
            }
        }
        return R.ok(locDetls.size());
    }
}