|
@@ -1,34 +1,36 @@
|
|
|
package cn.ezhizao.project.business.controller;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
+import java.io.StringWriter;
|
|
|
+import java.io.Writer;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.List;
|
|
|
-import java.util.StringTokenizer;
|
|
|
+import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
import javax.annotation.Resource;
|
|
|
+import javax.servlet.ServletOutputStream;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
|
+import cn.ezhizao.common.utils.PdfUtil;
|
|
|
import cn.ezhizao.framework.redis.RedisCache;
|
|
|
import cn.ezhizao.project.business.domain.*;
|
|
|
import cn.ezhizao.project.business.service.*;
|
|
|
|
|
|
+import cn.hutool.extra.template.TemplateException;
|
|
|
+import freemarker.template.Template;
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
+import lombok.Data;
|
|
|
+import lombok.EqualsAndHashCode;
|
|
|
+import lombok.ToString;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
-import org.springframework.web.bind.annotation.GetMapping;
|
|
|
-import org.springframework.web.bind.annotation.PostMapping;
|
|
|
-import org.springframework.web.bind.annotation.PutMapping;
|
|
|
-import org.springframework.web.bind.annotation.DeleteMapping;
|
|
|
-import org.springframework.web.bind.annotation.PathVariable;
|
|
|
-import org.springframework.web.bind.annotation.RequestBody;
|
|
|
-import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
-import org.springframework.web.bind.annotation.RestController;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
import cn.ezhizao.framework.aspectj.lang.annotation.Log;
|
|
|
import cn.ezhizao.framework.aspectj.lang.enums.BusinessType;
|
|
|
import cn.ezhizao.framework.web.controller.BaseController;
|
|
|
import cn.ezhizao.framework.web.domain.AjaxResult;
|
|
|
|
|
|
import cn.ezhizao.framework.web.page.TableDataInfo;
|
|
|
+import org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer;
|
|
|
|
|
|
/**
|
|
|
* 外协单主
|
|
@@ -37,6 +39,7 @@ import cn.ezhizao.framework.web.page.TableDataInfo;
|
|
|
* @author 庄德政
|
|
|
* date 2024-04-26
|
|
|
*/
|
|
|
+@Data
|
|
|
@RestController
|
|
|
@RequestMapping("/business/outsource")
|
|
|
public class BizOutsourcedOrderController extends BaseController {
|
|
@@ -61,6 +64,12 @@ public class BizOutsourcedOrderController extends BaseController {
|
|
|
@Resource
|
|
|
private IBizDayworkCarrierService iBizDayworkCarrierService;
|
|
|
|
|
|
+ /**
|
|
|
+ * 生成pdf
|
|
|
+ */
|
|
|
+ @Autowired
|
|
|
+ private FreeMarkerConfigurer freeMarkerConfigurer;
|
|
|
+
|
|
|
@Resource
|
|
|
private IBizCarrierRejectService iBizCarrierRejectService;
|
|
|
|
|
@@ -84,7 +93,7 @@ public class BizOutsourcedOrderController extends BaseController {
|
|
|
* 导出外协单主 带箱方式,是整单的。如果换新箱子,明细中,都需要更换箱子列表
|
|
|
*/
|
|
|
// @PreAuthorize("@ss.hasPermi('business:outsource:export')")
|
|
|
- @Log(title = "外协单主带箱方式,是整单的。如果换新箱子,明细中,都需要更换箱子", businessType = BusinessType.EXPORT)
|
|
|
+ @Log(title = "外协单导出", businessType = BusinessType.EXPORT)
|
|
|
@PostMapping("/export")
|
|
|
public void export(HttpServletResponse response, BizOutsourcedOrder bizOutsourcedOrder) throws NoSuchFieldException, IllegalAccessException, IOException {
|
|
|
bizOutsourcedOrder = bizOutsourcedOrderService.getById(bizOutsourcedOrder);
|
|
@@ -95,6 +104,180 @@ public class BizOutsourcedOrderController extends BaseController {
|
|
|
bizOutsourcedOrderService.exportTemplateProvinceAreaData(response, bizOutsourcedOrder);
|
|
|
}
|
|
|
|
|
|
+ @Log(title = "外协打印", businessType = BusinessType.EXPORT)
|
|
|
+ @PostMapping("/printDetailPdf")
|
|
|
+ public void SocialSecurityPdf(BizOutsourcedOrder bizOutsourcedOrder, HttpServletResponse response) throws IOException, TemplateException, freemarker.template.TemplateException {
|
|
|
+
|
|
|
+ /** 按照产品进行区分 **/
|
|
|
+ bizOutsourcedOrder = bizOutsourcedOrderService.getById(bizOutsourcedOrder);
|
|
|
+ BizOutsourcedOrderDetail bizOutsourcedOrderDetail = new BizOutsourcedOrderDetail();
|
|
|
+ bizOutsourcedOrderDetail.setMasterId(bizOutsourcedOrder.getId());
|
|
|
+
|
|
|
+ //该发出单所有明细
|
|
|
+ List<BizOutsourcedOrderDetail> outsourcedOrderDetails = bizOutsourcedOrderDetailService.getList(bizOutsourcedOrderDetail);
|
|
|
+ // 创建SimpleDateFormat对象,并设置日期格式
|
|
|
+ SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
+ bizOutsourcedOrder.setStringDate(dateFormat.format(bizOutsourcedOrder.getFormDate()));
|
|
|
+
|
|
|
+ List<List<BizOutsourcedOrderDetail> > list = new ArrayList<>();
|
|
|
+
|
|
|
+ //打印数据时每页14条
|
|
|
+ if(outsourcedOrderDetails.size() > 14){
|
|
|
+ // 用于临时存储每组数据的列表
|
|
|
+ List<BizOutsourcedOrderDetail> group = new ArrayList<>();
|
|
|
+ // 遍历 outsourcedOrderDetails 列表
|
|
|
+ for (BizOutsourcedOrderDetail detail : outsourcedOrderDetails) {
|
|
|
+ group.add(detail);
|
|
|
+ // 每添加 14 个元素后,将其添加到 list 中,并重置 group
|
|
|
+ if (group.size() == 14) {
|
|
|
+ // 使用流过滤出 productNum 不为空的元素,并对其 productNum 值求和
|
|
|
+ Integer sum = group.stream()
|
|
|
+ .filter(item -> item.getProductNum() != null) // 过滤出 productNum 不为空的元素
|
|
|
+ .mapToInt(BizOutsourcedOrderDetail::getProductNum) // 映射到 productNum 属性
|
|
|
+ .sum(); // 计算总和
|
|
|
+ // 然后,给每个对象的 sum 属性赋值
|
|
|
+ for (BizOutsourcedOrderDetail item : group) {
|
|
|
+ detail.setSum(sum);
|
|
|
+ detail.setOriginalCarrierCount(item.getNewCarrierCount()==null?item.getOriginalCarrierCount():item.getNewCarrierCount());
|
|
|
+ }
|
|
|
+ list.add(new ArrayList<>(group));
|
|
|
+ group = new ArrayList<>();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 如果最后一组不足 14 个元素,也将其添加到 list 中
|
|
|
+ if (!group.isEmpty()) {
|
|
|
+ BizOutsourcedOrderDetail orderDetail=new BizOutsourcedOrderDetail();
|
|
|
+ while (group.size() < 14) {
|
|
|
+ group.add(orderDetail); // 添加默认元素直到总数为14
|
|
|
+ }
|
|
|
+ list.add(group);
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ BizOutsourcedOrderDetail orderDetail=new BizOutsourcedOrderDetail();
|
|
|
+ while (outsourcedOrderDetails.size() < 14) {
|
|
|
+ outsourcedOrderDetails.add(orderDetail); // 添加默认元素直到总数为14
|
|
|
+ }
|
|
|
+ // 使用流过滤出 productNum 不为空的元素,并对其 productNum 值求和
|
|
|
+ Integer sum = outsourcedOrderDetails.stream()
|
|
|
+ .filter(detail -> detail.getProductNum() != null) // 过滤出 productNum 不为空的元素
|
|
|
+ .mapToInt(BizOutsourcedOrderDetail::getProductNum) // 映射到 productNum 属性
|
|
|
+ .sum(); // 计算总和
|
|
|
+ // 然后,给每个对象的 sum 属性赋值
|
|
|
+ for (BizOutsourcedOrderDetail detail : outsourcedOrderDetails) {
|
|
|
+ detail.setSum(sum);
|
|
|
+ detail.setOriginalCarrierCount(detail.getNewCarrierCount()==null?detail.getOriginalCarrierCount():detail.getNewCarrierCount());
|
|
|
+ }
|
|
|
+
|
|
|
+ list.add(outsourcedOrderDetails);
|
|
|
+ }
|
|
|
+ bizOutsourcedOrder.setDetailLists(list);
|
|
|
+
|
|
|
+
|
|
|
+ Map<String, Object> paramMap = new HashMap<>();
|
|
|
+ paramMap.put("outsourcedOrder" , bizOutsourcedOrder);
|
|
|
+ Writer out = new StringWriter();
|
|
|
+ //获取模板地址
|
|
|
+ Template template = freeMarkerConfigurer.getConfiguration().getTemplate("outSourcedPdf.html");
|
|
|
+ template.process(paramMap, out);
|
|
|
+ out.flush();
|
|
|
+ out.close();
|
|
|
+ String templateContent = out.toString();
|
|
|
+ response.setCharacterEncoding("UTF-8");
|
|
|
+ response.setContentType("application/pdf");
|
|
|
+ String fileName ="外协发出明细";
|
|
|
+ response.setHeader("Content-Disposition", "filename=" + new String(fileName.getBytes()));
|
|
|
+ byte[] resources = PdfUtil.html2Pdf(templateContent);
|
|
|
+ ServletOutputStream outputStream = response.getOutputStream();
|
|
|
+ outputStream.write(resources);
|
|
|
+ outputStream.close();
|
|
|
+ }
|
|
|
+
|
|
|
+// @Log(title = "外协打印", businessType = BusinessType.EXPORT)
|
|
|
+// @PostMapping("/printDetailPdf")
|
|
|
+// public void SocialSecurityPdf(BizOutsourcedOrder bizOutsourcedOrder, HttpServletResponse response) throws IOException, TemplateException, freemarker.template.TemplateException {
|
|
|
+//
|
|
|
+// /** 正常打印 **/
|
|
|
+// bizOutsourcedOrder = bizOutsourcedOrderService.getById(bizOutsourcedOrder);
|
|
|
+// BizOutsourcedOrderDetail bizOutsourcedOrderDetail = new BizOutsourcedOrderDetail();
|
|
|
+// bizOutsourcedOrderDetail.setMasterId(bizOutsourcedOrder.getId());
|
|
|
+// List<BizOutsourcedOrderDetail> outsourcedOrderDetails = bizOutsourcedOrderDetailService.getList(bizOutsourcedOrderDetail);
|
|
|
+// // 创建SimpleDateFormat对象,并设置日期格式
|
|
|
+// SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
+// bizOutsourcedOrder.setStringDate(dateFormat.format(bizOutsourcedOrder.getFormDate()));
|
|
|
+//
|
|
|
+// List<List<BizOutsourcedOrderDetail> > list = new ArrayList<>();
|
|
|
+//
|
|
|
+// //打印数据时每页14条
|
|
|
+// if(outsourcedOrderDetails.size() > 14){
|
|
|
+// // 用于临时存储每组数据的列表
|
|
|
+// List<BizOutsourcedOrderDetail> group = new ArrayList<>();
|
|
|
+// // 遍历 outsourcedOrderDetails 列表
|
|
|
+// for (BizOutsourcedOrderDetail detail : outsourcedOrderDetails) {
|
|
|
+// group.add(detail);
|
|
|
+// // 每添加 14 个元素后,将其添加到 list 中,并重置 group
|
|
|
+// if (group.size() == 14) {
|
|
|
+// // 使用流过滤出 productNum 不为空的元素,并对其 productNum 值求和
|
|
|
+// Integer sum = group.stream()
|
|
|
+// .filter(item -> item.getProductNum() != null) // 过滤出 productNum 不为空的元素
|
|
|
+// .mapToInt(BizOutsourcedOrderDetail::getProductNum) // 映射到 productNum 属性
|
|
|
+// .sum(); // 计算总和
|
|
|
+// // 然后,给每个对象的 sum 属性赋值
|
|
|
+// for (BizOutsourcedOrderDetail item : group) {
|
|
|
+// detail.setSum(sum);
|
|
|
+// detail.setOriginalCarrierCount(item.getNewCarrierCount()==null?item.getOriginalCarrierCount():item.getNewCarrierCount());
|
|
|
+// }
|
|
|
+// list.add(new ArrayList<>(group));
|
|
|
+// group = new ArrayList<>();
|
|
|
+// }
|
|
|
+// }
|
|
|
+// // 如果最后一组不足 14 个元素,也将其添加到 list 中
|
|
|
+// if (!group.isEmpty()) {
|
|
|
+// BizOutsourcedOrderDetail orderDetail=new BizOutsourcedOrderDetail();
|
|
|
+// while (group.size() < 14) {
|
|
|
+// group.add(orderDetail); // 添加默认元素直到总数为14
|
|
|
+// }
|
|
|
+// list.add(group);
|
|
|
+// }
|
|
|
+// }else{
|
|
|
+// BizOutsourcedOrderDetail orderDetail=new BizOutsourcedOrderDetail();
|
|
|
+// while (outsourcedOrderDetails.size() < 14) {
|
|
|
+// outsourcedOrderDetails.add(orderDetail); // 添加默认元素直到总数为14
|
|
|
+// }
|
|
|
+// // 使用流过滤出 productNum 不为空的元素,并对其 productNum 值求和
|
|
|
+// Integer sum = outsourcedOrderDetails.stream()
|
|
|
+// .filter(detail -> detail.getProductNum() != null) // 过滤出 productNum 不为空的元素
|
|
|
+// .mapToInt(BizOutsourcedOrderDetail::getProductNum) // 映射到 productNum 属性
|
|
|
+// .sum(); // 计算总和
|
|
|
+// // 然后,给每个对象的 sum 属性赋值
|
|
|
+// for (BizOutsourcedOrderDetail detail : outsourcedOrderDetails) {
|
|
|
+// detail.setSum(sum);
|
|
|
+// detail.setOriginalCarrierCount(detail.getNewCarrierCount()==null?detail.getOriginalCarrierCount():detail.getNewCarrierCount());
|
|
|
+// }
|
|
|
+//
|
|
|
+// list.add(outsourcedOrderDetails);
|
|
|
+// }
|
|
|
+// bizOutsourcedOrder.setDetailLists(list);
|
|
|
+//
|
|
|
+//
|
|
|
+// Map<String, Object> paramMap = new HashMap<>();
|
|
|
+// paramMap.put("outsourcedOrder" , bizOutsourcedOrder);
|
|
|
+// Writer out = new StringWriter();
|
|
|
+// //获取模板地址
|
|
|
+// Template template = freeMarkerConfigurer.getConfiguration().getTemplate("outSourcedPdf.html");
|
|
|
+// template.process(paramMap, out);
|
|
|
+// out.flush();
|
|
|
+// out.close();
|
|
|
+// String templateContent = out.toString();
|
|
|
+// response.setCharacterEncoding("UTF-8");
|
|
|
+// response.setContentType("application/pdf");
|
|
|
+// String fileName ="外协发出明细";
|
|
|
+// response.setHeader("Content-Disposition", "filename=" + new String(fileName.getBytes()));
|
|
|
+// byte[] resources = PdfUtil.html2Pdf(templateContent);
|
|
|
+// ServletOutputStream outputStream = response.getOutputStream();
|
|
|
+// outputStream.write(resources);
|
|
|
+// outputStream.close();
|
|
|
+// }
|
|
|
+//
|
|
|
|
|
|
/**
|
|
|
* 获取外协单主
|