#
tqs
2023-12-05 a0b733a8b19b1db43395a96408098596ac3d2a86
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
package zy.cloud.wms.manager.controller;
 
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy;
import com.baomidou.mybatisplus.plugins.Page;
import com.core.annotations.ManagerAuth;
import com.core.common.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import zy.cloud.wms.common.utils.VersionUtils;
import zy.cloud.wms.common.web.BaseController;
import zy.cloud.wms.manager.entity.LocDetl;
import zy.cloud.wms.manager.entity.Mat;
import zy.cloud.wms.manager.service.LocDetlService;
import zy.cloud.wms.manager.service.MatService;
 
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URLEncoder;
import java.util.List;
import java.util.Map;
 
/**
 * Created by vincent on 2021/4/2
 */
@RestController
public class StatisController extends BaseController {
 
    @Autowired
    private MatService matService;
    @Autowired
    private LocDetlService locDetlService;
 
    @RequestMapping(value = "/stock/statis/auth")
    @ManagerAuth
    public R stockStatis(@RequestParam(defaultValue = "1")Integer curr,
                    @RequestParam(defaultValue = "10")Integer limit,
                    @RequestParam Map<String, Object> param) {
        Page<LocDetl> stockStatis = locDetlService.getStockStatis(toPage(curr, limit, param, LocDetl.class));
        for (LocDetl locDetl : stockStatis.getRecords()) {
            Mat mat = matService.selectByMatnr(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) {
            Mat mat = matService.selectByMatnr(locDetl.getMatnr());
            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);
    }
 
}