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 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 javax.annotation.Resource;
|
import javax.servlet.http.HttpServletResponse;
|
import java.io.InputStream;
|
import java.io.OutputStream;
|
import java.net.URLEncoder;
|
import java.util.HashMap;
|
import java.util.List;
|
import java.util.Map;
|
|
/**
|
* 部门台账
|
*/
|
@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();
|
}
|
|
}
|
}
|