修改导出 及明细

This commit is contained in:
haozq 2024-11-11 10:29:40 +08:00
parent acaa99650e
commit 255a8e0b63
8 changed files with 358 additions and 175 deletions

View File

@ -0,0 +1,265 @@
package com.bonus.gzgqj.business.plan.controller;
import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.entity.ExportParams;
import cn.afterturn.easypoi.excel.entity.enmus.ExcelType;
import com.bonus.gzgqj.business.plan.entity.PlanApplyBean;
import com.bonus.gzgqj.business.plan.entity.PlanDataDetailBean;
import com.bonus.gzgqj.business.plan.entity.ProNeedInfo;
import com.bonus.gzgqj.business.plan.entity.ProPlanInfoVo;
import com.bonus.gzgqj.business.plan.service.PlanApplicationService;
import com.bonus.gzgqj.business.plan.service.PlanOutService;
import com.bonus.gzgqj.business.utils.FileUploadService;
import com.bonus.gzgqj.business.utils.SystemUtils;
import com.bonus.gzgqj.manager.webResult.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.FileUtils;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.List;
/**
* @author 黑子
*/
@RestController
@RequestMapping("/backstage/export")
@Slf4j
public class ExportController {
@Autowired
private PlanOutService service;
@Autowired
private PlanApplicationService planService;
@Autowired
private FileUploadService fileUploadService;
/**
* 导出需求计划
* @param
* @param
* @param o
*/
@PostMapping("export")
public void export(HttpServletRequest request, HttpServletResponse response, PlanApplyBean o) {
try {
List<PlanApplyBean> list = service.getProPlanListByProId(o);
if(StringUtils.isEmpty(list)){
list=new ArrayList<>();
}
list.forEach(vo->{
vo.setStatusName(getStatus(o.getStatusType(),o.getStatus()));
});
ExportParams exportParams = new ExportParams("需求计划申请", "需求计划申请", ExcelType.XSSF);
Workbook workbook = ExcelExportUtil.exportExcel(exportParams, PlanApplyBean.class, list);
response.setContentType("application/vnd.ms-excel");
response.setHeader("content-disposition", "attachment;fileName=" + URLEncoder.encode("需求计划申请" + ".xlsx", "UTF-8"));
ServletOutputStream outputStream = response.getOutputStream();
workbook.write(outputStream);
outputStream.close();
workbook.close();
} catch (Exception e) {
log.error(e.toString(), e);
}
}
/**
* 导出需求计划详情
* @param request
* @param response
* @param o
*/
@PostMapping("exportDetail")
public void exportDetail(HttpServletRequest request, HttpServletResponse response,PlanApplyBean o) {
try {
List<PlanDataDetailBean> results = planService.getDetailsList(o);
ExportParams exportParams = new ExportParams("机具明细", "机具明细", ExcelType.XSSF);
Workbook workbook = ExcelExportUtil.exportExcel(exportParams, PlanApplyBean.class, results);
response.setContentType("application/vnd.ms-excel");
response.setHeader("content-disposition", "attachment;fileName=" + URLEncoder.encode("机具明细" + ".xlsx", "UTF-8"));
ServletOutputStream outputStream = response.getOutputStream();
workbook.write(outputStream);
outputStream.close();
workbook.close();
} catch (Exception e) {
log.error(e.toString(), e);
}
}
/**
* 导出发货--主页查询
* @param request
* @param response
* @param o
*/
@PostMapping("exportFhList")
public void exportFhList(HttpServletRequest request, HttpServletResponse response, ProPlanInfoVo o) {
try {
List<ProPlanInfoVo> results = service.getProPlanPage(o);
results.forEach(vo->{
if(vo.getStatus()==0){
vo.setStatusName("未发货");
}else if(vo.getStatus()==1){
vo.setStatusName("部分发货");
}else if(vo.getStatus()==2){
vo.setStatusName("全部发货");
}
vo.setProgress(vo.getProgress()+"%");
});
ExportParams exportParams = new ExportParams("发货统计", "发货统计", ExcelType.XSSF);
Workbook workbook = ExcelExportUtil.exportExcel(exportParams, PlanApplyBean.class, results);
response.setContentType("application/vnd.ms-excel");
response.setHeader("content-disposition", "attachment;fileName=" + URLEncoder.encode("发货统计" + ".xlsx", "UTF-8"));
ServletOutputStream outputStream = response.getOutputStream();
workbook.write(outputStream);
outputStream.close();
workbook.close();
} catch (Exception e) {
log.error(e.toString(), e);
}
}
/**
* 导出 全部发货 -接口
* @param request
* @param response
* @param o
*/
@PostMapping("exportAllFhList")
public void exportAllFhList(HttpServletRequest request, HttpServletResponse response, ProNeedInfo o) {
try {
List<ProNeedInfo> list = service.getPorInfoDetail2(o);;
ExportParams exportParams = new ExportParams("全部发货", "全部发货", ExcelType.XSSF);
Workbook workbook = ExcelExportUtil.exportExcel(exportParams, PlanApplyBean.class, list);
response.setContentType("application/vnd.ms-excel");
response.setHeader("content-disposition", "attachment;fileName=" + URLEncoder.encode("全部发货" + ".xlsx", "UTF-8"));
ServletOutputStream outputStream = response.getOutputStream();
workbook.write(outputStream);
outputStream.close();
workbook.close();
} catch (Exception e) {
log.error(e.toString(), e);
}
}
/**
* 文件统一下载
*/
@GetMapping("/download")
public ResponseEntity<byte[]> fileDownload(HttpServletRequest request, String fileId) throws Exception{
//指定下载的文件根路径
String dirPath = SystemUtils.getUploadPath();
String filename=fileUploadService.getFilePath(fileId);
//创建该文件对象
File file = new File(dirPath +filename);
//设置响应头
HttpHeaders headers = new HttpHeaders();
//通知浏览器以下载方式打开(下载前对文件名进行转码)
filename=getFilename(request,filename);
headers.setContentDispositionFormData("attachment",filename);
//定义以流的形式下载返回文件数据
headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
try {return new ResponseEntity<>(FileUtils.readFileToByteArray(file),
headers, HttpStatus.OK);} catch (Exception e) {e.printStackTrace();
return new ResponseEntity<byte[]>(e.getMessage().getBytes(),
HttpStatus.EXPECTATION_FAILED);
}
}
//根据浏览器的不同进行编码设置返回编码后的文件名
private String getFilename(HttpServletRequest request,String filename)
throws Exception {
//IE不同版本User-Agent中出现的关键词
String[] IEBrowserKeyWords = {"MSIE", "Trident", "Edge"};
//获取请求头代理信息
String userAgent = request.getHeader("User-Agent");
for (String keyWord : IEBrowserKeyWords) {
if (userAgent.contains(keyWord)) {
//IE内核浏览器统一为UTF-8编码显示并对转换的+进行更正
return URLEncoder.encode(filename, "UTF-8").replace("+"," ");
}}
//火狐等其他浏览器统一为ISO-8859-1编码显示
return new String(filename.getBytes("UTF-8"), "ISO-8859-1");
}
/**
* 获取审核状态
* @param statusType
* @param status
* @return
*/
private String getStatus(String statusType,String status) {
try {
String company ="";
if("1".equals(statusType)) {
return "审核通过";
}else if("2".equals(statusType)) {
company="分公司";
}else if("3".equals(statusType)) {
company="项目管理中心";
}else if("4".equals(statusType)) {
company="机具公司";
}
if("1".equals(status)) {
return ""+company+"审核";
}else if("2".equals(status)) {
return "审核通过";
}else if("3".equals(status)) {
return company+"审核驳回";
}
}catch (Exception e) {
log.error(e.toString(), e);
}
return "待审核";
}
}

View File

@ -51,8 +51,7 @@ public class PlanOutController {
@Autowired
private PlanApplicationService planService;
@Autowired
private FileUploadService fileUploadService;
/**
* 发货 统计查询
* @return
@ -70,7 +69,8 @@ public class PlanOutController {
@DecryptAndVerify(decryptedClass = ProPlanInfoVo.class)
public PageInfo<ProPlanInfoVo> getProPlanPage(EncryptedReq<ProPlanInfoVo> dto) {
PageHelper.startPage(dto.getPageNum(),dto.getPageSize());
PageInfo<ProPlanInfoVo> pageInfo = service.getProPlanPage(dto.getData());;
List<ProPlanInfoVo> list = service.getProPlanPage(dto.getData());
PageInfo<ProPlanInfoVo> pageInfo = new PageInfo<>(list);
return pageInfo;
}
/**
@ -82,7 +82,8 @@ public class PlanOutController {
@DecryptAndVerify(decryptedClass = ProNeedInfo.class)
public PageInfo<ProNeedInfo> getPorInfoDetail(EncryptedReq<ProNeedInfo> dto) {
PageHelper.startPage(dto.getPageNum(),dto.getPageSize());
PageInfo<ProNeedInfo> pageInfo = service.getPorInfoDetail(dto.getData());;
List<ProNeedInfo> list = service.getPorInfoDetail(dto.getData());
PageInfo<ProNeedInfo> pageInfo = new PageInfo<>(list);
return pageInfo;
}
/**
@ -94,7 +95,8 @@ public class PlanOutController {
@DecryptAndVerify(decryptedClass = ProNeedInfo.class)
public PageInfo<ProNeedInfo> getPorInfoDetail2(EncryptedReq<ProNeedInfo> dto) {
PageHelper.startPage(dto.getPageNum(),dto.getPageSize());
PageInfo<ProNeedInfo> pageInfo = service.getPorInfoDetail2(dto.getData());;
List<ProNeedInfo> list = service.getPorInfoDetail2(dto.getData());;
PageInfo<ProNeedInfo> pageInfo = new PageInfo<>(list);
return pageInfo;
}
/**
@ -160,7 +162,7 @@ public class PlanOutController {
}
/**
* 查询工程 -需求计划 列表
* 查询工程 -需求计划 列表
* @param dto
* @return
*/
@ -185,82 +187,6 @@ public class PlanOutController {
return planService.getPlanDetails(dto.getData());
}
@PostMapping("export")
public void export(HttpServletRequest request, HttpServletResponse response, PlanApplyBean o) {
try {
List<PlanApplyBean> list = service.getProPlanListByProId(o);
if(StringUtils.isEmpty(list)){
list=new ArrayList<>();
}
list.forEach(vo->{
vo.setStatusName(getStatus(o.getStatusType(),o.getStatus()));
});
ExportParams exportParams = new ExportParams("需求计划申请", "需求计划申请", ExcelType.XSSF);
Workbook workbook = ExcelExportUtil.exportExcel(exportParams, PlanApplyBean.class, list);
response.setContentType("application/vnd.ms-excel");
response.setHeader("content-disposition", "attachment;fileName=" + URLEncoder.encode("需求计划申请" + ".xlsx", "UTF-8"));
ServletOutputStream outputStream = response.getOutputStream();
workbook.write(outputStream);
outputStream.close();
workbook.close();
} catch (Exception e) {
log.error(e.toString(), e);
}
}
@PostMapping("exportDetail")
public void exportDetail(HttpServletRequest request, HttpServletResponse response,PlanApplyBean o) {
try {
List<PlanDataDetailBean> results = planService.getDetailsList(o);
ExportParams exportParams = new ExportParams("机具明细", "机具明细", ExcelType.XSSF);
Workbook workbook = ExcelExportUtil.exportExcel(exportParams, PlanApplyBean.class, results);
response.setContentType("application/vnd.ms-excel");
response.setHeader("content-disposition", "attachment;fileName=" + URLEncoder.encode("机具明细" + ".xlsx", "UTF-8"));
ServletOutputStream outputStream = response.getOutputStream();
workbook.write(outputStream);
outputStream.close();
workbook.close();
} catch (Exception e) {
log.error(e.toString(), e);
}
}
/**
* 获取审核状态
* @param statusType
* @param status
* @return
*/
private String getStatus(String statusType,String status) {
try {
String company ="";
if("1".equals(statusType)) {
return "审核通过";
}else if("2".equals(statusType)) {
company="分公司";
}else if("3".equals(statusType)) {
company="项目管理中心";
}else if("4".equals(statusType)) {
company="机具公司";
}
if("1".equals(status)) {
return ""+company+"审核";
}else if("2".equals(status)) {
return "审核通过";
}else if("3".equals(status)) {
return company+"审核驳回";
}
}catch (Exception e) {
log.error(e.toString(), e);
}
return "待审核";
}
/**
* 数据总览-查询
@ -305,46 +231,6 @@ public class PlanOutController {
}
/**
* "中文名称"文件下载
*/
@GetMapping("/download")
public ResponseEntity<byte[]> fileDownload(HttpServletRequest request, String fileId) throws Exception{
//指定下载的文件根路径
String dirPath = SystemUtils.getUploadPath();
String filename=fileUploadService.getFilePath(fileId);
//创建该文件对象
File file = new File(dirPath +filename);
//设置响应头
HttpHeaders headers = new HttpHeaders();
//通知浏览器以下载方式打开(下载前对文件名进行转码)
filename=getFilename(request,filename);
headers.setContentDispositionFormData("attachment",filename);
//定义以流的形式下载返回文件数据
headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
try {return new ResponseEntity<>(FileUtils.readFileToByteArray(file),
headers, HttpStatus.OK);} catch (Exception e) {e.printStackTrace();
return new ResponseEntity<byte[]>(e.getMessage().getBytes(),
HttpStatus.EXPECTATION_FAILED);
}
}
//根据浏览器的不同进行编码设置返回编码后的文件名
private String getFilename(HttpServletRequest request,String filename)
throws Exception {
//IE不同版本User-Agent中出现的关键词
String[] IEBrowserKeyWords = {"MSIE", "Trident", "Edge"};
//获取请求头代理信息
String userAgent = request.getHeader("User-Agent");
for (String keyWord : IEBrowserKeyWords) {
if (userAgent.contains(keyWord)) {
//IE内核浏览器统一为UTF-8编码显示并对转换的+进行更正
return URLEncoder.encode(filename, "UTF-8").replace("+"," ");
}}
//火狐等其他浏览器统一为ISO-8859-1编码显示
return new String(filename.getBytes("UTF-8"), "ISO-8859-1");
}
/**
* 告警内容详情

View File

@ -96,8 +96,9 @@ public class PlanApplyBean {
private String statusType;
private String moduleId;
private String jsonData;
private List<PlanDataDetailBean> details;

View File

@ -1,5 +1,6 @@
package com.bonus.gzgqj.business.plan.entity;
import cn.afterturn.easypoi.excel.annotation.Excel;
import lombok.Data;
import lombok.EqualsAndHashCode;
@ -13,7 +14,13 @@ public class ProNeedInfo extends PageInfo {
/**
* 主键
*/
@Excel(name = "序号", width = 10.0, orderNum = "0")
private String id;
/**
* 计划内外
*/
@Excel(name = "计划内/计划外", width = 10.0,height = 20.0, orderNum = "2")
private String typeName;
/**
* 工程id
*/
@ -26,15 +33,30 @@ public class ProNeedInfo extends PageInfo {
/**
* 类型
*/
@Excel(name = "物机类型", width = 10.0,height = 20.0, orderNum = "3")
private String type;
/**
* 名称
*/
@Excel(name = "物机名称", width = 10.0,height = 20.0, orderNum = "4")
private String name;
/**
* 规格型号
*/
@Excel(name = "规格型号", width = 10.0,height = 20.0, orderNum = "5")
private String module;
/**
* 单位
*/
@Excel(name = "单位", width = 10.0,height = 20.0, orderNum = "6")
private String unit;
/**
* 进度
*/
@Excel(name = "进度", width = 10.0,height = 20.0, orderNum = "7")
private String progress;
/**
* 规格id
*/
@ -43,35 +65,36 @@ public class ProNeedInfo extends PageInfo {
* 需求类型 1计划 2新增
*/
private String needType;
/**
* 计划内外
*/
private String typeName;
/**
* 单位
*/
private String unit;
/**
* 需要数量
*/
@Excel(name = "需要量", width = 10.0,height = 20.0, orderNum = "8")
private int needNum;
/**
* 发货数量
*/
@Excel(name = "已发货量", width = 10.0,height = 20.0, orderNum = "9")
private int fhNum;
/**
* 差额
*/
@Excel(name = "待发货量", width = 10.0,height = 20.0, orderNum = "10")
private int diff;
/**
* 调整量
*/
@Excel(name = "调整量", width = 10.0,height = 20.0, orderNum = "11")
private int tzNum;
/**
* 备注
*/
@Excel(name = "备注", width = 10.0,height = 20.0, orderNum = "12")
private String remarks;
/**
* 差额
*/
private String diff;
/**
* 备注
@ -89,10 +112,7 @@ public class ProNeedInfo extends PageInfo {
*/
private int num;
/**
* 进度
*/
private String progress;
/**
* 计划数量
*/

View File

@ -1,5 +1,6 @@
package com.bonus.gzgqj.business.plan.entity;
import cn.afterturn.easypoi.excel.annotation.Excel;
import lombok.Data;
@Data
@ -9,19 +10,45 @@ public class ProPlanInfoVo extends PageInfo {
/**
* 工程id
*/
@Excel(name = "序号", width = 10.0, orderNum = "0")
private String proId;
/**
* 工程名称
*/
@Excel(name = "工程名称", width = 10.0,height = 20.0, orderNum = "2")
private String proName;
/**
* 计划
*/
@Excel(name = "需求计划数量", width = 10.0,height = 20.0, orderNum = "3")
private int planNum;
/**
* 出库单量
*/
@Excel(name = "出库单量", width = 10.0,height = 20.0, orderNum = "4")
private int recordNum;
/**
* 出库单量
* 状态
*/
private int status;
@Excel(name = "发货状态", width = 10.0,height = 20.0, orderNum = "5")
private String statusName;
/**
* 最后发货时间
*/
@Excel(name = "最后发货时间", width = 10.0,height = 20.0, orderNum = "6")
private String lastDay;
/**
* 进度
*/
@Excel(name = "进度", width = 10.0,height = 20.0, orderNum = "6")
private String progress;
/**
* 非计划-出库单量
*/
private int recordNum2;
@ -43,23 +70,11 @@ public class ProPlanInfoVo extends PageInfo {
* 出库量
*/
private int tzNum;
/**
* 状态
*/
private int status;
/**
* 最后发货时间
*/
private String lastDay;
/**
* 进度
*/
private String progress;
/**
* 工程名称
*/
private String proName;

View File

@ -17,14 +17,14 @@ public interface PlanOutService {
* @param data
* @return
*/
PageInfo<ProPlanInfoVo> getProPlanPage(ProPlanInfoVo data);
List<ProPlanInfoVo> getProPlanPage(ProPlanInfoVo data);
/**
* 分页查询工程发货信息
* @param data
* @return
*/
PageInfo<ProNeedInfo> getPorInfoDetail(ProNeedInfo data);
List<ProNeedInfo> getPorInfoDetail(ProNeedInfo data);
/**
* 查询工程下拉选
@ -67,7 +67,7 @@ public interface PlanOutService {
* @param data
* @return
*/
PageInfo<ProNeedInfo> getPorInfoDetail2(ProNeedInfo data);
List<ProNeedInfo> getPorInfoDetail2(ProNeedInfo data);
/**
* 批次详情查询

View File

@ -47,18 +47,15 @@ public class PlanOutServiceImpl implements PlanOutService{
* @return
*/
@Override
public PageInfo<ProPlanInfoVo> getProPlanPage(ProPlanInfoVo data) {
public List<ProPlanInfoVo> getProPlanPage(ProPlanInfoVo data) {
List<ProPlanInfoVo> list = new ArrayList<>();
try {
long userId= UserUtil.getLoginUser().getUserId();
String userName=UserUtil.getLoginUser().getUsername();
System.err.println("us===="+userId+"========="+userName);
list = mapper.getProPlanPage(data);
} catch (Exception e) {
log.error(e.toString(),e);
}
PageInfo<ProPlanInfoVo> pageInfo = new PageInfo<>(list);
return pageInfo;
return list;
}
/**
@ -67,15 +64,14 @@ public class PlanOutServiceImpl implements PlanOutService{
* @return
*/
@Override
public PageInfo<ProNeedInfo> getPorInfoDetail(ProNeedInfo data) {
public List<ProNeedInfo> getPorInfoDetail(ProNeedInfo data) {
List<ProNeedInfo> list = new ArrayList<>();
try {
list = mapper.getPorInfoDetail(data);
} catch (Exception e) {
log.error(e.toString(),e);
}
PageInfo<ProNeedInfo> pageInfo = new PageInfo<>(list);
return pageInfo;
return list;
}
/**
* 分页查询 工程 发货详情
@ -83,15 +79,15 @@ public class PlanOutServiceImpl implements PlanOutService{
* @return
*/
@Override
public PageInfo<ProNeedInfo> getPorInfoDetail2(ProNeedInfo data) {
public List<ProNeedInfo> getPorInfoDetail2(ProNeedInfo data) {
List<ProNeedInfo> list = new ArrayList<>();
try {
list = mapper.getPorInfoDetail2(data);
} catch (Exception e) {
log.error(e.toString(),e);
}
PageInfo<ProNeedInfo> pageInfo = new PageInfo<>(list);
return pageInfo;
return list;
}
/**

View File

@ -305,9 +305,9 @@
</select>
<select id="getWarnInfoPage" resultType="com.bonus.gzgqj.business.plan.entity.ProNeedInfo">
select tni.pro_id,tni.type,tni.`name`,tni.module,tni.module_id moduleId ,tni.unit,tni.need_num needNum,tni.id ,mt.num,
( tni.need_num-mt.num) diff
FLOOR(tni.need_num-mt.num) diff
from t_pro_need_info tni
left join mm_type mt on mt.id=tni.module_id and mt.`LEVEL`=4
left join mm_type mt on mt.id=tni.module_id and mt.`LEVEL`=4
where tni.need_num-mt.NUM>0
<if test="module!=null and module!=''">
and pni.`module` like concat('%',#{module},'%')