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
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.HashMap;
import java.util.List;
import java.util.Map;
 
/**
 * 部门台账
 */
// @Api(value = "部门台账", tags = "部门台账")
@RestController
@RequestMapping("/pc/fin/warehouse/departLedger")
public class FinDepartLedgerController 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) 1);
        GenericPager pager = finWarehouseLedgerService.departLedgerList(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) 1);
        param.setPageNum(1);
        param.setPageSize(Integer.MAX_VALUE);
        GenericPager<Map<String, Object>> pager = finWarehouseLedgerService.departLedgerList(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();
        }
 
    }
}