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.Cools;
|
import com.core.common.R;
|
import com.core.exception.CoolException;
|
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.entity.Pakin;
|
import zy.cloud.wms.manager.service.LocDetlService;
|
import zy.cloud.wms.manager.service.MatService;
|
import zy.cloud.wms.manager.service.PakinService;
|
|
import javax.servlet.http.HttpServletResponse;
|
import java.io.IOException;
|
import java.net.URLEncoder;
|
import java.util.Calendar;
|
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 MatService matService;
|
@Autowired
|
private LocDetlService locDetlService;
|
@Autowired
|
private PakinService pakinService;
|
|
// 库存统计 ------------------------------------------------------------------------------------------
|
|
@RequestMapping(value = "/stock/statis/auth")
|
@ManagerAuth
|
public R stockStatis(@RequestParam(defaultValue = "1")Integer curr,
|
@RequestParam(defaultValue = "10")Integer limit,
|
@RequestParam Map<String, Object> param) {
|
Long hostId = getHostId();
|
if (hostId != null) {
|
param.put("host_id", hostId);
|
}
|
Page<LocDetl> stockStatis = locDetlService.getStockStatis(toPage(curr, limit, param, LocDetl.class));
|
for (LocDetl locDetl : stockStatis.getRecords()) {
|
Mat mat = matService.selectByMatnr(hostId, locDetl.getMatnr());
|
if (mat != null) {
|
VersionUtils.setLocDetl(locDetl, mat);
|
}
|
}
|
return R.ok().add(stockStatis);
|
}
|
|
@RequestMapping(value = "/stock/statis/export")
|
public void stockStatisExport(HttpServletResponse response, @RequestParam String token) throws IOException {
|
Long hostId = getHostId(token);
|
List<LocDetl> excel = locDetlService.getStockStatisExcel(hostId);
|
for (LocDetl locDetl : excel) {
|
Mat mat = matService.selectById(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);
|
}
|
|
// 月入库统计 ------------------------------------------------------------------------------------------
|
|
@RequestMapping(value = "/pakin/statis/auth")
|
@ManagerAuth
|
public R pakinStatis(@RequestParam(defaultValue = "1")Integer curr,
|
@RequestParam(defaultValue = "10")Integer limit,
|
@RequestParam Map<String, Object> param) {
|
Calendar calendar = Calendar.getInstance();
|
calendar.setTime(new Date());
|
if (Cools.isEmpty(param.get("year"))) {
|
param.remove("month");
|
param.put("year", calendar.get(Calendar.YEAR));
|
}
|
if (Cools.isEmpty(param.get("month"))) {
|
param.put("month", calendar.get(Calendar.MONTH) + 1);
|
}
|
Long hostId = getHostId();
|
if (hostId != null) {
|
param.put("host_id", hostId);
|
}
|
Page<Pakin> pakinStatis = pakinService.getPakinStatis(toPage(curr, limit, param, Pakin.class));
|
for (Pakin pakin : pakinStatis.getRecords()) {
|
Mat mat = matService.selectByMatnr(hostId, pakin.getMatnr());
|
if (mat != null) {
|
VersionUtils.setPakin(pakin, mat);
|
}
|
}
|
return R.ok().add(pakinStatis);
|
}
|
|
@RequestMapping(value = "/pakin/statis/export")
|
public void pakinStatisExport(@RequestParam("year") Integer year,
|
@RequestParam("month") Integer month,
|
@RequestParam String token,
|
HttpServletResponse response) throws IOException {
|
if (Cools.isEmpty(year, month)) {
|
throw new CoolException("年月不能为空");
|
}
|
Long hostId = getHostId(token);
|
List<Pakin> excel = pakinService.getPakinStatisExcel(year, month, hostId);
|
for (Pakin pakin : excel) {
|
Mat mat = matService.selectByMatnr(hostId, pakin.getMatnr());
|
if (mat != null) {
|
VersionUtils.setPakin(pakin, mat);
|
}
|
}
|
response.setContentType("application/vnd.ms-excel");
|
response.setCharacterEncoding("utf-8");
|
String fileName = URLEncoder.encode(year+"年" + month + "月入库统计报表", "UTF-8");
|
response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx");
|
EasyExcel.write(response.getOutputStream(), Pakin.class)
|
.registerWriteHandler(new LongestMatchColumnWidthStyleStrategy())
|
.sheet(year + "-" + month)
|
.doWrite(excel);
|
}
|
|
}
|