Commit 0f4fce8e23f2e61b6ca497abfc0c81075fba3c35

Authored by 房远帅
2 parents be50b053 3f423077

Merge branch 'master_chujiang' into master_warehouse

... ... @@ -687,6 +687,7 @@ CREATE TABLE IF NOT EXISTS `shipments_order_info` (
687 687 `destination` varchar(500) DEFAULT NULL COMMENT '目的地',
688 688 `payment_type` varchar(500) DEFAULT NULL COMMENT '付款方式',
689 689 `status` varchar(20) DEFAULT NULL COMMENT '状态',
  690 + `pushed` tinyint(1) NOT NULL DEFAULT 0 COMMENT '是否已推送出门凭证 0-未推送 1-已推送(推送后门卫可见)',
690 691 `receipts_id` varchar(32) DEFAULT NULL COMMENT '签收单据文件ID',
691 692 `receipts_name` varchar(50) DEFAULT NULL COMMENT '签收单据文件名称',
692 693 `create_by_id` varchar(32) NOT NULL COMMENT '创建人ID',
... ...
... ... @@ -105,6 +105,12 @@ public class QueryShipmentsOrderInfoBo extends BaseBo<ShipmentsOrderInfo> {
105 105 private String status;
106 106
107 107 /**
  108 + * 是否已推送出门凭证
  109 + */
  110 + @ApiModelProperty("是否已推送出门凭证")
  111 + private Boolean pushed;
  112 +
  113 + /**
108 114 * 是否当日发货
109 115 */
110 116 @ApiModelProperty("是否当日发货")
... ...
... ... @@ -11,6 +11,8 @@ import com.lframework.starter.web.inner.service.system.SysDeptService;
11 11 import com.lframework.starter.web.inner.service.system.SysRoleService;
12 12 import com.lframework.starter.web.inner.service.system.SysUserDeptService;
13 13 import com.lframework.starter.web.inner.service.system.SysUserService;
  14 +import com.lframework.xingyun.basedata.entity.Workshop;
  15 +import com.lframework.xingyun.basedata.service.workshop.WorkshopService;
14 16 import com.lframework.xingyun.sc.bo.shipments.order.GetShipmentsOrderInfoBo;
15 17 import com.lframework.xingyun.sc.bo.shipments.order.QueryShipmentsOrderInfoBo;
16 18 import com.lframework.xingyun.sc.bo.shipments.plan.ShipmentsPlanDetailBo;
... ... @@ -42,8 +44,13 @@ import io.swagger.annotations.Api;
42 44 import lombok.extern.slf4j.Slf4j;
43 45 import org.apache.commons.collections4.CollectionUtils;
44 46 import org.apache.commons.lang3.StringUtils;
  47 +import org.apache.poi.ss.usermodel.Cell;
  48 +import org.apache.poi.ss.usermodel.CellStyle;
  49 +import org.apache.poi.ss.usermodel.HorizontalAlignment;
  50 +import org.apache.poi.ss.usermodel.Row;
45 51 import org.apache.poi.ss.usermodel.Sheet;
46 52 import org.apache.poi.ss.usermodel.Workbook;
  53 +import org.apache.poi.ss.util.CellRangeAddress;
47 54 import org.apache.poi.xssf.usermodel.XSSFWorkbook;
48 55 import org.springframework.data.redis.core.RedisTemplate;
49 56 import org.springframework.scheduling.annotation.Scheduled;
... ... @@ -103,6 +110,8 @@ public class ShipmentsOrderInfoController extends DefaultBaseController {
103 110 private ContractDistributorLineService contractDistributorLineService;
104 111 @Resource
105 112 private ContractStdProcessingLineService contractStdProcessingLineService;
  113 + @Resource
  114 + private WorkshopService workshopService;
106 115
107 116
108 117 /**
... ... @@ -115,6 +124,10 @@ public class ShipmentsOrderInfoController extends DefaultBaseController {
115 124 // 业务员、办事处内勤、办事处主管按区域/办事处查看数据
116 125 PageResult<ShipmentsOrderInfo> pageResult;
117 126 List<String> roleCodes = getCurrentUserRoleCodes();
  127 + // 门卫只能查看已推送出门凭证的发货单
  128 + if (roleCodes.contains("mw")) {
  129 + vo.setPushed(true);
  130 + }
118 131 if (isDeptBasedRole(roleCodes)) {
119 132 applyQueryPermission(vo, roleCodes);
120 133 pageResult = shipmentsOrderInfoService.queryWithoutPermission(getPageIndex(vo), getPageSize(vo), vo);
... ... @@ -383,6 +396,17 @@ public class ShipmentsOrderInfoController extends DefaultBaseController {
383 396 return InvokeResultBuilder.success();
384 397 }
385 398
  399 + /**
  400 + * 推送发货单出门凭证(推送后门卫可见,并给门卫发送消息提醒)
  401 + */
  402 + @ApiOperation("推送发货单出门凭证")
  403 + @HasPermission({"shipping-plan-manage:invoice:push"})
  404 + @PostMapping("/push")
  405 + public InvokeResult<Void> push(@RequestBody List<String> ids) {
  406 + shipmentsOrderInfoService.push(ids);
  407 + return InvokeResultBuilder.success();
  408 + }
  409 +
386 410 @ApiModelProperty("数据处理")
387 411 @GetMapping("/dataHandler")
388 412 // @Scheduled(cron = "0 8 0 * * ?")
... ... @@ -551,8 +575,8 @@ public class ShipmentsOrderInfoController extends DefaultBaseController {
551 575 Set<String> set = new HashSet<>();
552 576 for (ShipmentsPlanDetail detail : detailList) {
553 577 BigDecimal quantity = detail.getQuantity() == null ? BigDecimal.ZERO : detail.getQuantity();
554   - BigDecimal actualQuantity = detail.getActualShipmentQuantity() == null ? BigDecimal.ZERO : new BigDecimal(detail.getActualShipmentQuantity());
555   - BigDecimal num = detail.getNum() == null ? BigDecimal.ZERO : new BigDecimal(detail.getNum());
  578 + BigDecimal actualQuantity = detail.getActualShipmentQuantity() == null ? BigDecimal.ZERO : BigDecimal.valueOf(detail.getActualShipmentQuantity());
  579 + BigDecimal num = detail.getNum() == null ? BigDecimal.ZERO : BigDecimal.valueOf(detail.getNum());
556 580 set.add(detail.getOrderSpecId());
557 581 totalQuantity = totalQuantity.add(quantity);
558 582 totalActualQuantity = totalActualQuantity.add(actualQuantity);
... ... @@ -653,7 +677,27 @@ public class ShipmentsOrderInfoController extends DefaultBaseController {
653 677 }
654 678 String latex = LatexFormulaExcelExporterUtil.convertToContractSpecLatexSingleLineFixed3(formulaComponentList);
655 679 if (StringUtils.isNotBlank(latex)) {
656   - LatexFormulaExcelExporterUtil.insertLatexImageToCellLeftAligned(workbook, sheet, latex, startRow, 2, 1, 7);
  680 + // 右侧预留 30px 给同列靠右展示的状态,避免图片遮挡
  681 + LatexFormulaExcelExporterUtil.insertLatexImageToCellLeftAligned(workbook, sheet, latex, startRow, 2, 1, 7, 30);
  682 + }
  683 + // 状态原值写入"规格状态"区域,右对齐到区域最右端(规格图片已预留右侧 30px,避免遮挡)
  684 + // 合并单元格的值只能写区域左上角(右对齐后显示在区域最右端);非合并直接写区域最后一列
  685 + int statusColIndex = 2 + 7 - 1;
  686 + for (int i = 0; i < sheet.getNumMergedRegions(); i++) {
  687 + CellRangeAddress merged = sheet.getMergedRegion(i);
  688 + if (merged.isInRange(startRow, 2)) {
  689 + statusColIndex = merged.getFirstColumn();
  690 + break;
  691 + }
  692 + }
  693 + ExcelUtil.setCellValue(sheet, startRow, statusColIndex, detail.getStatus());
  694 + Row statusRow = sheet.getRow(startRow);
  695 + Cell statusCell = statusRow.getCell(statusColIndex);
  696 + if (statusCell != null) {
  697 + CellStyle statusStyle = workbook.createCellStyle();
  698 + statusStyle.cloneStyleFrom(statusCell.getCellStyle());
  699 + statusStyle.setAlignment(HorizontalAlignment.RIGHT);
  700 + statusCell.setCellStyle(statusStyle);
657 701 }
658 702 String materialCode = resultMaterialMap.get(detail.getOrderSpecId());
659 703 ExcelUtil.setCellValue(sheet, startRow, 9, materialCode);
... ... @@ -722,6 +766,8 @@ public class ShipmentsOrderInfoController extends DefaultBaseController {
722 766 } else {
723 767 dataMap.put("regionName", "");
724 768 }
  769 + // 按分厂与联次填充固定审核人(审批/复核/司磅/提货/审核)
  770 + dataMap.putAll(getFixedAuditors(orderInfo.getWorkshopId(), type));
725 771 // 处理模板中的占位符
726 772 ExcelUtil.processTemplate(workbook, dataMap);
727 773 // 生成文件名
... ... @@ -739,6 +785,59 @@ public class ShipmentsOrderInfoController extends DefaultBaseController {
739 785 }
740 786
741 787 /**
  788 + * 按分厂与联次获取打印模板固定审核人(审批/复核/司磅/提货/审核):
  789 + * 司磅仅客户联有值;提货固定为空;未匹配的分厂全部为空
  790 + *
  791 + * @param workshopId 分厂ID
  792 + * @param type 打印类型 TYPE_1-记账联 TYPE_2-客户联
  793 + * @return approveUser/reviewUser/weighUser/pickupUser/auditUser
  794 + */
  795 + private Map<String, String> getFixedAuditors(String workshopId, String type) {
  796 + Map<String, String> auditors = new HashMap<>();
  797 + auditors.put("approveUser", "");
  798 + auditors.put("reviewUser", "");
  799 + auditors.put("weighUser", "");
  800 + auditors.put("pickupUser", "");
  801 + auditors.put("auditUser", "");
  802 +
  803 + Workshop workshop = workshopService.findById(workshopId);
  804 + if (workshop == null || StringUtils.isBlank(workshop.getCode())) {
  805 + return auditors;
  806 + }
  807 + // 司磅:客户联有值,记账联为空
  808 + boolean isCustomer = "TYPE_2".equals(type);
  809 + switch (workshop.getCode()) {
  810 + case "yfc":
  811 + auditors.put("approveUser", "周维龙");
  812 + auditors.put("reviewUser", "许夕海");
  813 + auditors.put("weighUser", isCustomer ? "汪进" : "");
  814 + auditors.put("auditUser", "李春华");
  815 + break;
  816 + case "efc":
  817 + auditors.put("approveUser", "周维龙");
  818 + auditors.put("reviewUser", "杨学平");
  819 + auditors.put("weighUser", isCustomer ? "李飞飞" : "");
  820 + auditors.put("auditUser", "顾兵");
  821 + break;
  822 + case "sfc":
  823 + auditors.put("approveUser", "刘建新");
  824 + auditors.put("reviewUser", "汤宗保");
  825 + auditors.put("weighUser", isCustomer ? "周月" : "");
  826 + auditors.put("auditUser", "");
  827 + break;
  828 + case "ztfc":
  829 + auditors.put("approveUser", "胡勇");
  830 + auditors.put("reviewUser", "后承荣");
  831 + auditors.put("weighUser", isCustomer ? "秦升红" : "");
  832 + auditors.put("auditUser", "");
  833 + break;
  834 + default:
  835 + break;
  836 + }
  837 + return auditors;
  838 + }
  839 +
  840 + /**
742 841 * 处理订单类型
743 842 *
744 843 * @param contractType 合同类型
... ...
... ... @@ -126,6 +126,11 @@ public class ShipmentsOrderInfo extends BaseEntity implements BaseDto {
126 126 private String status;
127 127
128 128 /**
  129 + * 是否已推送出门凭证 0-未推送 1-已推送(推送后门卫可见)
  130 + */
  131 + private Boolean pushed;
  132 +
  133 + /**
129 134 * 是否当日发货
130 135 */
131 136 private Boolean onTimeShipment;
... ...
... ... @@ -497,6 +497,16 @@ public class FlowTaskServiceImpl implements FlowTaskService {
497 497 }
498 498
499 499 @Override
  500 + public void updateWeighingTicketApprovalMap(Map<String, Object> map) {
  501 +
  502 + }
  503 +
  504 + @Override
  505 + public void updateAssayReportApprovalMap(Map<String, Object> map) {
  506 +
  507 + }
  508 +
  509 + @Override
500 510 public Map<String, Object> findById(String s) {
501 511 ProductSampleConfirmationSlip slip = productSampleConfirmationSlipService.findById(s);
502 512 Map<String, Object> map = new HashMap<>();
... ...
... ... @@ -727,6 +727,44 @@ public class ShipmentsOrderInfoServiceImpl extends BaseMpServiceImpl<ShipmentsOr
727 727 }
728 728
729 729 @Override
  730 + @Transactional(rollbackFor = Exception.class)
  731 + @OpLog(type = OtherOpLogType.class, name = "推送发货单出门凭证,ID:{}", params = {"#ids"})
  732 + public void push(List<String> ids) {
  733 + if (CollectionUtils.isEmpty(ids)) {
  734 + throw new DefaultClientException("请选择要推送的发货单!");
  735 + }
  736 + List<ShipmentsOrderInfo> orderList = getBaseMapper().queryByIds(ids);
  737 + if (CollectionUtils.isEmpty(orderList)) {
  738 + throw new DefaultClientException("发货单不存在!");
  739 + }
  740 + // 过滤已推送的,避免重复推送与重复提醒
  741 + List<ShipmentsOrderInfo> unPushedList = orderList.stream()
  742 + .filter(o -> o != null && !Boolean.TRUE.equals(o.getPushed()))
  743 + .collect(Collectors.toList());
  744 + if (CollectionUtils.isEmpty(unPushedList)) {
  745 + throw new DefaultClientException("所选发货单均已推送出门凭证,无需重复推送!");
  746 + }
  747 +
  748 + List<String> pushIds = unPushedList.stream().map(ShipmentsOrderInfo::getId).collect(Collectors.toList());
  749 + LambdaUpdateWrapper<ShipmentsOrderInfo> updateWrapper = Wrappers.lambdaUpdate(ShipmentsOrderInfo.class);
  750 + updateWrapper.set(ShipmentsOrderInfo::getPushed, true)
  751 + .in(ShipmentsOrderInfo::getId, pushIds);
  752 + getBaseMapper().update(updateWrapper);
  753 +
  754 + // 给门卫发送消息提醒(提醒哪些发货单推送了出门凭证)
  755 + List<String> codes = unPushedList.stream()
  756 + .map(ShipmentsOrderInfo::getCode)
  757 + .filter(StringUtils::isNotBlank)
  758 + .collect(Collectors.toList());
  759 + if (CollectionUtils.isNotEmpty(codes)) {
  760 + String content = "发货单 " + String.join("、", codes) + " 已推送出门凭证,请及时处理!";
  761 + List<String> userIds = sysUserRoleService.listUserIdByRoleCodes(Collections.singletonList("mw"));
  762 + // bizKey 数据库限制 32 字符,批量推送时取第一条单据ID
  763 + messageHandler.sendMsg(userIds, content, content, pushIds.get(0), null);
  764 + }
  765 + }
  766 +
  767 + @Override
730 768 public List<ShipmentsOrderInfo> queryByIds(List<String> ids) {
731 769 if (CollectionUtils.isEmpty(ids)) {
732 770 return Collections.emptyList();
... ...
... ... @@ -113,6 +113,13 @@ public interface ShipmentsOrderInfoService extends BaseMpService<ShipmentsOrderI
113 113 void updateStatus(String id, String status);
114 114
115 115 /**
  116 + * 推送发货单出门凭证(推送后门卫可见,并给门卫发送消息提醒)
  117 + *
  118 + * @param ids 发货单ID集合
  119 + */
  120 + void push(List<String> ids);
  121 +
  122 + /**
116 123 * 根据主键批量查询
117 124 *
118 125 * @param ids 主键集合
... ...
... ... @@ -324,7 +324,17 @@ public class LatexFormulaExcelExporterUtil {
324 324 */
325 325 public static void insertLatexImageToCellLeftAligned(Workbook workbook, Sheet sheet, String latex,
326 326 int rowIndex, int colIndex, int rowRange, int colRange) throws IOException {
327   - insertLatexImageToRegionLeftAligned(workbook, sheet, latex, rowIndex, colIndex, rowRange, colRange, 16, null);
  327 + insertLatexImageToCellLeftAligned(workbook, sheet, latex, rowIndex, colIndex, rowRange, colRange, 0);
  328 + }
  329 +
  330 + /**
  331 + * 将 LaTeX 公式作为图片左对齐插入到指定单元格区域内,并确保图片不会超出区域边界;
  332 + * 右侧预留 reserveRightPx 像素不占用(用于同列右对齐展示状态等文本内容)
  333 + */
  334 + public static void insertLatexImageToCellLeftAligned(Workbook workbook, Sheet sheet, String latex,
  335 + int rowIndex, int colIndex, int rowRange, int colRange,
  336 + int reserveRightPx) throws IOException {
  337 + insertLatexImageToRegionLeftAligned(workbook, sheet, latex, rowIndex, colIndex, rowRange, colRange, 16, null, reserveRightPx);
328 338 }
329 339
330 340 /**
... ... @@ -576,7 +586,7 @@ public class LatexFormulaExcelExporterUtil {
576 586 */
577 587 private static void insertLatexImageToRegionLeftAligned(Workbook workbook, Sheet sheet, String latex,
578 588 int rowIndex, int colIndex, int rowRange, int colRange,
579   - int fontSize, Double maxScale) throws IOException {
  589 + int fontSize, Double maxScale, int reserveRightPx) throws IOException {
580 590 byte[] imageBytes = latexToImageBytes(latex, fontSize);
581 591 BufferedImage image;
582 592 try (ByteArrayInputStream in = new ByteArrayInputStream(imageBytes)) {
... ... @@ -598,8 +608,10 @@ public class LatexFormulaExcelExporterUtil {
598 608
599 609 int paddingXPx = 6;
600 610 int paddingYPx = 2;
  611 + // 可用宽度扣除右侧预留(用于同列右对齐展示状态等文本,避免图片遮挡)
  612 + int availableWidthPx = Math.max(1, regionWidthPx - paddingXPx * 2 - Math.max(0, reserveRightPx));
601 613 double scale = Math.min(
602   - (double) (regionWidthPx - paddingXPx * 2) / Math.max(1, image.getWidth()),
  614 + (double) availableWidthPx / Math.max(1, image.getWidth()),
603 615 (double) (regionHeightPx - paddingYPx * 2) / Math.max(1, image.getHeight())
604 616 );
605 617 scale = Math.min(scale, 1.0);
... ...
... ... @@ -66,6 +66,12 @@ public class QueryShipmentsOrderInfoVo extends PageVo implements BaseVo, Seriali
66 66 private String status;
67 67
68 68 /**
  69 + * 是否已推送出门凭证(门卫只能查看已推送的)
  70 + */
  71 + @ApiModelProperty("是否已推送出门凭证 true-已推送 false-未推送(不传查全部)")
  72 + private Boolean pushed;
  73 +
  74 + /**
69 75 * 搜索关键字
70 76 * 移动端使用
71 77 * 根据发货单编号和订货单位模糊搜索
... ...
... ... @@ -53,6 +53,9 @@
53 53 <include refid="ShipmentsOrderInfo_sql"/>
54 54 <where>
55 55 AND tb.status != 'DRAFT'
  56 + <if test="vo.pushed != null">
  57 + AND tb.pushed = #{vo.pushed}
  58 + </if>
56 59 <if test="vo.workshopId != null and vo.workshopId != ''">
57 60 AND tb.workshop_id = #{vo.workshopId}
58 61 </if>
... ... @@ -92,6 +95,9 @@
92 95 <include refid="ShipmentsOrderInfo_sql"/>
93 96 <where>
94 97 AND tb.status != 'DRAFT'
  98 + <if test="vo.pushed != null">
  99 + AND tb.pushed = #{vo.pushed}
  100 + </if>
95 101 <if test="vo.workshopId != null and vo.workshopId != ''">
96 102 AND tb.workshop_id = #{vo.workshopId}
97 103 </if>
... ...