WangHan
2025-04-02 a8ba678a3fe5a39da2c732014cebbb66e408e97c
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
package com.consum.base.controller;
 
import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.entity.TemplateExportParams;
import com.consum.base.BaseController;
import com.consum.base.core.utils.CommonUtil;
import com.consum.base.pojo.query.LWhLedgerQry;
import com.consum.base.service.FinWarehouseLedgerServiceImpl;
import com.consum.model.po.FinSysTenantUser;
import com.iplatform.model.po.S_user_core;
import com.walker.db.page.GenericPager;
import com.walker.web.ResponseValue;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.core.io.ClassPathResource;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
 
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
/**
 * @ClassName FinWarehouseLedgerController
 * @Author cy
 * @Date 2023/11/20
 * @Description 仓库台账
 * @Version 1.0
 **/
@RestController
@RequestMapping("/pc/fin/warehouse/ledger")
public class FinWarehouseLedgerController extends BaseController {
    @Resource
    private FinWarehouseLedgerServiceImpl finWarehouseLedgerService;
 
    /**
     * @Description 分页列表查询
     * @Author wh
     * @Date 2023/7/11 13:59
     */
    @RequestMapping("/getList")
    public ResponseValue getLedgerList() {
        LWhLedgerQry param = CommonUtil.getObjFromReq(LWhLedgerQry.class);
        LWhLedgerQry query = new LWhLedgerQry();
        CommonUtil.copyProperties(param, query);
        param = query;
        S_user_core currentUser = this.getCurrentUser();
        if (currentUser == null) {
            return ResponseValue.error("登录用户信息不存在");
        }
        /*当前登录人只能看到自己机构下的列表*/
        FinSysTenantUser sysInfo = this.getSysInfo();
        String tenantId = sysInfo.getTenantId();
        Long paramAgencyId = param.getAgencyId();
        if (paramAgencyId == null || !paramAgencyId.toString().startsWith(tenantId)) {
            param.setAgencyId(Long.valueOf(tenantId));
        }
        param.setStates((short) 1);
        param.setWarehouseType((short) 0);
        GenericPager pager = finWarehouseLedgerService.ledgerList(param);
        return ResponseValue.success(pager);
    }
 
    @RequestMapping("/getListExport")
    public void getListExport(HttpServletResponse response) throws Exception {
        LWhLedgerQry param = CommonUtil.getObjFromReq(LWhLedgerQry.class);
        LWhLedgerQry query = new LWhLedgerQry();
        CommonUtil.copyProperties(param, query);
        param = query;
        S_user_core currentUser = this.getCurrentUser();
        if (currentUser == null) {
            return;
        }
        /*当前登录人只能看到自己机构下的列表*/
        FinSysTenantUser sysInfo = this.getSysInfo();
        String tenantId = sysInfo.getTenantId();
        Long paramAgencyId = param.getAgencyId();
        if (paramAgencyId == null || !paramAgencyId.toString().startsWith(tenantId)) {
            param.setAgencyId(Long.valueOf(tenantId));
        }
        param.setStates((short) 1);
        param.setWarehouseType((short) 0);
        param.setPageNum(1);
        param.setPageSize(Integer.MAX_VALUE);
        GenericPager<Map<String, Object>> pager = finWarehouseLedgerService.ledgerList(param);
        List<Map<String, Object>> datas = pager.getDatas();
        org.springframework.core.io.Resource resource = new ClassPathResource("import/taiZhangExpTemp.xlsx");
        // 获取文件输入流
        InputStream inputStream = resource.getInputStream();
        Workbook wb = new XSSFWorkbook(inputStream);
        TemplateExportParams params = new TemplateExportParams();
        params.setTemplateWb(wb);
 
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("dataList", datas);
 
        Workbook workbook = ExcelExportUtil.exportExcel(params, map);
        // 设置响应头
        response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8");
        response.setHeader("Content-disposition", "attachment;filename=" + URLEncoder.encode("库存查询.xlsx", "utf-8"));
        try (OutputStream outputStream = response.getOutputStream()) {
            workbook.write(outputStream);
            workbook.close();
        }
 
    }
 
    /**
     * @Description 分页列表查询
     * @Author wh
     * @Date 2023/7/11 13:59
     */
    @RequestMapping("/getDeptLedgerList")
    public ResponseValue getDeptLedgerList() {
        LWhLedgerQry param = CommonUtil.getObjFromReq(LWhLedgerQry.class);
        LWhLedgerQry query = new LWhLedgerQry();
        CommonUtil.copyProperties(param, query);
        param = query;
        S_user_core currentUser = this.getCurrentUser();
        if (currentUser == null) {
            return ResponseValue.error("登录用户信息不存在");
        }
        /*当前登录人只能看到自己机构下的列表*/
        FinSysTenantUser sysInfo = this.getSysInfo();
        String tenantId = sysInfo.getTenantId();
        Long paramAgencyId = param.getAgencyId();
        if (paramAgencyId == null || !paramAgencyId.toString().startsWith(tenantId)) {
            param.setAgencyId(Long.valueOf(tenantId));
        }
        ArrayList<Short> statesList = new ArrayList<>();
        statesList.add((short)1);
        statesList.add((short)2);
        param.setStatesList(statesList);
        param.setWarehouseType((short) 1);
        GenericPager pager = finWarehouseLedgerService.depLedgerList(param);
        return ResponseValue.success(pager);
    }
 
    @RequestMapping("/getDeptListExport")
    public void getDeptListExport(HttpServletResponse response) throws Exception {
        LWhLedgerQry param = CommonUtil.getObjFromReq(LWhLedgerQry.class);
        LWhLedgerQry query = new LWhLedgerQry();
        CommonUtil.copyProperties(param, query);
        param = query;
        S_user_core currentUser = this.getCurrentUser();
        if (currentUser == null) {
            return;
        }
        /*当前登录人只能看到自己机构下的列表*/
        FinSysTenantUser sysInfo = this.getSysInfo();
        String tenantId = sysInfo.getTenantId();
        Long paramAgencyId = param.getAgencyId();
        if (paramAgencyId == null || !paramAgencyId.toString().startsWith(tenantId)) {
            param.setAgencyId(Long.valueOf(tenantId));
        }
        ArrayList<Short> statesList = new ArrayList<>();
        statesList.add((short)1);
        statesList.add((short)2);
        param.setStatesList(statesList);
        param.setWarehouseType((short) 1);
        param.setPageNum(1);
        param.setPageSize(Integer.MAX_VALUE);
        GenericPager<Map<String, Object>> pager = finWarehouseLedgerService.depLedgerList(param);
        List<Map<String, Object>> datas = pager.getDatas();
        org.springframework.core.io.Resource resource = new ClassPathResource("import/depTaiZhangExpTemp.xlsx");
        // 获取文件输入流
        InputStream inputStream = resource.getInputStream();
        Workbook wb = new XSSFWorkbook(inputStream);
        TemplateExportParams params = new TemplateExportParams();
        params.setTemplateWb(wb);
 
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("dataList", datas);
 
        Workbook workbook = ExcelExportUtil.exportExcel(params, map);
        // 设置响应头
        response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8");
        response.setHeader("Content-disposition", "attachment;filename=" + URLEncoder.encode("库存查询.xlsx", "utf-8"));
        try (OutputStream outputStream = response.getOutputStream()) {
            workbook.write(outputStream);
            workbook.close();
        }
 
    }
 
}