Showing
13 changed files
with
267 additions
and
100 deletions
| ... | ... | @@ -10,10 +10,12 @@ import com.lframework.starter.web.core.components.resp.PageResult; |
| 10 | 10 | import com.lframework.xingyun.sc.bo.procurement.*; |
| 11 | 11 | import com.lframework.xingyun.sc.procurement.entity.contract.ProcurementContract; |
| 12 | 12 | import com.lframework.xingyun.sc.procurement.service.contract.ProcurementContractService; |
| 13 | +import com.lframework.xingyun.sc.procurement.service.plan.ProcurementPlanService; | |
| 13 | 14 | import com.lframework.xingyun.sc.procurement.vo.contract.CreateProcurementContractVo; |
| 14 | 15 | import com.lframework.xingyun.sc.procurement.vo.contract.QueryProcurementContractVo; |
| 15 | 16 | import com.lframework.xingyun.sc.procurement.vo.contract.UpdateProcurementContractVo; |
| 16 | 17 | import com.lframework.xingyun.sc.utils.ExcelUtil; |
| 18 | +import com.lframework.xingyun.sc.utils.ResponseUtil; | |
| 17 | 19 | import io.swagger.annotations.Api; |
| 18 | 20 | import io.swagger.annotations.ApiImplicitParam; |
| 19 | 21 | import io.swagger.annotations.ApiOperation; |
| ... | ... | @@ -29,14 +31,14 @@ import org.apache.poi.util.IOUtils; |
| 29 | 31 | import org.apache.poi.xssf.usermodel.XSSFWorkbook; |
| 30 | 32 | import org.springframework.validation.annotation.Validated; |
| 31 | 33 | import org.springframework.web.bind.annotation.*; |
| 32 | - | |
| 33 | -import java.io.FileNotFoundException; | |
| 34 | -import java.io.IOException; | |
| 35 | -import java.io.InputStream; | |
| 34 | +import java.io.*; | |
| 35 | +import java.math.BigDecimal; | |
| 36 | +import java.nio.file.Files; | |
| 36 | 37 | import java.time.format.DateTimeFormatter; |
| 37 | 38 | import java.util.HashMap; |
| 38 | 39 | import java.util.List; |
| 39 | 40 | import java.util.Map; |
| 41 | +import java.util.stream.Collectors; | |
| 40 | 42 | |
| 41 | 43 | @Api(tags = "采购合同管理") |
| 42 | 44 | @Slf4j |
| ... | ... | @@ -47,6 +49,8 @@ public class ProcurementContractController extends DefaultBaseController { |
| 47 | 49 | |
| 48 | 50 | @Resource |
| 49 | 51 | private ProcurementContractService procurementContractService; |
| 52 | + @Resource | |
| 53 | + private ProcurementPlanService procurementPlanService; | |
| 50 | 54 | |
| 51 | 55 | @ApiOperation("分页查询采购合同") |
| 52 | 56 | @HasPermission({"agreement-manage:domestic-agreement:query"}) |
| ... | ... | @@ -73,7 +77,7 @@ public class ProcurementContractController extends DefaultBaseController { |
| 73 | 77 | |
| 74 | 78 | @ApiOperation("修改采购合同") |
| 75 | 79 | @HasPermission({"agreement-manage:domestic-agreement:modify","agreement-manage:domestic-agreement:approve"}) |
| 76 | - @PutMapping("/update") | |
| 80 | + @PutMapping("") | |
| 77 | 81 | public InvokeResult<Void> update(@RequestBody @Valid UpdateProcurementContractVo vo) { |
| 78 | 82 | procurementContractService.update(vo); |
| 79 | 83 | return InvokeResultBuilder.success(); |
| ... | ... | @@ -108,93 +112,206 @@ public class ProcurementContractController extends DefaultBaseController { |
| 108 | 112 | |
| 109 | 113 | @ApiOperation("打印合同") |
| 110 | 114 | @GetMapping("/export") |
| 111 | - public void export(@NotBlank(message = "ID不能为空!") String id, | |
| 115 | + public void export(@NotBlank(message = "ID不能为空!") String id, String exportType, | |
| 112 | 116 | HttpServletResponse response) throws IOException { |
| 113 | 117 | |
| 114 | -// GetProcurementContractBo detail = procurementContractService.findDetail(id); | |
| 115 | -// if (detail == null) { | |
| 116 | -// throw new DefaultClientException("采购合同不存在!"); | |
| 117 | -// } | |
| 118 | -// ExcelUtil.setupResponse(response, detail.getProcurementPlanCode() + "_" + detail.getCompanyFullName() + "-采购合同.xlsx"); | |
| 119 | -// | |
| 120 | -// ClassPathResource templateResource = new ClassPathResource("templates/planTemplate.xlsx"); | |
| 121 | -// try { | |
| 122 | -// try (InputStream inputStream = templateResource.getStream(); | |
| 123 | -// Workbook workbook = new XSSFWorkbook(inputStream)) { | |
| 124 | -// try { | |
| 125 | -// DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); | |
| 126 | -// Sheet sheet = workbook.getSheetAt(0); | |
| 127 | -// | |
| 128 | -// List<GetProcurementContractLineBo> procurementContractLineList = detail.getProcurementContractLineList(); | |
| 129 | -// int planStartRow = 4; // 合同计划子表开始行,可根据模板调整 | |
| 130 | -// if (CollectionUtils.isNotEmpty(procurementContractLineList)) { | |
| 131 | -// for (int i = 0; i < procurementContractLineList.size(); i++) { | |
| 132 | -// GetProcurementContractLineBo line = procurementContractLineList.get(i); | |
| 133 | -// ExcelUtil.setCellValue(sheet, planStartRow, 0, line.getProductName()); | |
| 134 | -// ExcelUtil.setCellValue(sheet, planStartRow, 1, line.getMaterialType()); | |
| 135 | -// ExcelUtil.setCellValue(sheet, planStartRow, 2, line.getQuantity()); | |
| 136 | -// ExcelUtil.setCellValue(sheet, planStartRow, 3, line.getActualPurchasePrice()); | |
| 137 | -// ExcelUtil.setCellValue(sheet, planStartRow, 4, line.getIncludingShippingPrice()); | |
| 138 | -// ExcelUtil.setCellValue(sheet, planStartRow, 5, line.getPriceListPrices()); | |
| 139 | -// ExcelUtil.setCellValue(sheet, planStartRow, 6, line.getCoordinationRange()); | |
| 140 | -// ExcelUtil.setCellValue(sheet, planStartRow, 7, line.getEstimatedLoss()); | |
| 141 | -// ExcelUtil.setCellValue(sheet, planStartRow, 8, line.getWorkshopName()); | |
| 142 | -// planStartRow++; | |
| 143 | -// } | |
| 144 | -// } | |
| 145 | -// | |
| 146 | -// Map<String, Object> planDataMap = new HashMap<>(); | |
| 147 | -// planDataMap.put("code", nvl(plan.getCode()) + nvl(plan.getPlanType())); | |
| 148 | -// planDataMap.put("companyShortName", nvl(plan.getCompanyShortName())); | |
| 149 | -// planDataMap.put("workshopName", nvl(plan.getWorkshopName())); | |
| 150 | -// planDataMap.put("purchaseDepartmentName", nvl(plan.getPurchaseDepartmentName())); | |
| 151 | -// planDataMap.put("regionName", nvl(plan.getRegionName())); | |
| 152 | -// planDataMap.put("date", plan.getDate() == null ? "" : plan.getDate().format(dateFormatter)); | |
| 153 | -// planDataMap.put("supplierName", nvl(plan.getSupplierName())); | |
| 154 | -// planDataMap.put("commodityBuyout", plan.getCommodityBuyout() == null ? "□" : (plan.getCommodityBuyout() ? "■" : "□")); | |
| 155 | -// planDataMap.put("qualityBuyout", plan.getQualityBuyout() == null ? "□" : (plan.getQualityBuyout() ? "■" : "□")); | |
| 156 | -// planDataMap.put("quantityBuyout", plan.getQuantityBuyout() == null ? "□" : (plan.getQuantityBuyout() ? "■" : "□")); | |
| 157 | -// planDataMap.put("doorDelivery", plan.getDoorDelivery() == null ? "□" : (plan.getDoorDelivery() ? "■" : "□")); | |
| 158 | -// planDataMap.put("longTermOperation", plan.getLongTermOperation() == null ? "□" : (plan.getLongTermOperation() ? "■" : "□")); | |
| 159 | -// planDataMap.put("terminalCustomer", plan.getTerminalCustomer() == null ? "□" : (plan.getTerminalCustomer() ? "■" : "□")); | |
| 160 | -// planDataMap.put("shippingCostB", plan.getShippingCost() == null ? "□" : "■"); | |
| 161 | -// planDataMap.put("shippingCost", formatDecimal(plan.getShippingCost())); | |
| 162 | -// planDataMap.put("loadingFeeB", plan.getLoadingFee() == null ? "□" : "■"); | |
| 163 | -// planDataMap.put("loadingFee", formatDecimal(plan.getLoadingFee())); | |
| 164 | -// planDataMap.put("otherExpenseSettlement", plan.getOtherExpenseSettlement() == null ? "□" : (plan.getOtherExpenseSettlement() ? "■" : "□")); | |
| 165 | -// planDataMap.put("remark", nvl(plan.getRemark())); | |
| 166 | -// planDataMap.put("totalQuantity", formatDecimal(plan.getTotalQuantity())); | |
| 167 | -// planDataMap.put("coordinationReason", nvl(plan.getCoordinationReason())); | |
| 168 | -// planDataMap.put("invoiceTypeStatus", nvl(plan.getInvoiceTypeStatus())); | |
| 169 | -// planDataMap.put("invoiceProductName", nvl(plan.getInvoiceProductName())); | |
| 170 | -// //制单人 | |
| 171 | -// planDataMap.put("createBy", nvl(plan.getCreateBy())); | |
| 172 | -// //采购处主管 | |
| 173 | -// planDataMap.put("purchaseDeptName", nvl(plan.getPurchaseDeptName())); | |
| 174 | -// //供应管理科主管 | |
| 175 | -// planDataMap.put("managementDeptName", nvl(plan.getManagementDeptName())); | |
| 176 | -// //供应部主管 | |
| 177 | -// planDataMap.put("supplyManagerName", nvl(plan.getSupplyManagerName())); | |
| 178 | -// //营销分管 | |
| 179 | -// planDataMap.put("marketingManagerName", nvl(plan.getMarketingManagerName())); | |
| 180 | -// //总经理 | |
| 181 | -// planDataMap.put("generalManagerName", nvl(plan.getGeneralManagerName())); | |
| 182 | -// ExcelUtil.processTemplateSheet(sheet, planDataMap); | |
| 183 | -// | |
| 184 | -// workbook.write(response.getOutputStream()); | |
| 185 | -// response.getOutputStream().flush(); | |
| 186 | -// } finally { | |
| 187 | -// IOUtils.closeQuietly(workbook); | |
| 188 | -// } | |
| 189 | -// | |
| 190 | -// } catch (FileNotFoundException e) { | |
| 191 | -// throw new RuntimeException("模板文件不存在: templates/planAndBuyoutTemplate.xlsx", e); | |
| 192 | -// } catch (IOException e) { | |
| 193 | -// throw new RuntimeException("无法读取模板文件: templates/planAndBuyoutTemplate.xlsx", e); | |
| 194 | -// } | |
| 195 | -// } catch (Exception e) { | |
| 196 | -// log.error("导出采购合同失败, id={}, {}", id, e.getMessage(), e); | |
| 197 | -// throw e; | |
| 198 | -// } | |
| 118 | + GetProcurementContractBo detail = procurementContractService.findDetail(id); | |
| 119 | + if (detail == null) { | |
| 120 | + throw new DefaultClientException("采购合同不存在!"); | |
| 121 | + } | |
| 122 | + GetProcurementPlanBo planBo = procurementPlanService.getDetail(detail.getProcurementPlanId()); | |
| 123 | + if (planBo == null) { | |
| 124 | + throw new DefaultClientException("采购计划不存在!"); | |
| 125 | + } | |
| 126 | + List<GetProcurementContractLineBo> procurementContractLineList = detail.getProcurementContractLineList(); | |
| 127 | + if (procurementContractLineList == null) { | |
| 128 | + throw new DefaultClientException("采购合同明细数据不存在!"); | |
| 129 | + } | |
| 130 | + List<String> productNames = procurementContractLineList.stream() | |
| 131 | + .map(GetProcurementContractLineBo::getProductName) | |
| 132 | + .filter(name -> name != null && !name.trim().isEmpty()) // 过滤掉 null 和空白字符串 | |
| 133 | + .collect(Collectors.toList()); | |
| 134 | + //交提货方式 | |
| 135 | + String deliveryMode = planBo.getDeliveryMode(); | |
| 136 | + //是否暂定价 | |
| 137 | + Boolean temporaryPrice = planBo.getTemporaryPrice(); | |
| 138 | + //是否未点价 | |
| 139 | + Boolean priced = planBo.getPriced(); | |
| 140 | + //结算比例 | |
| 141 | + BigDecimal settlementRatio = detail.getSettlementRatio(); | |
| 142 | + //合同类型 | |
| 143 | + String contractType = null; | |
| 144 | + ClassPathResource templateResource = new ClassPathResource("templates/electricCopperTemplate.xlsx"); | |
| 145 | + if (productNames.stream() | |
| 146 | + .anyMatch(name -> name != null && name.contains("电铜"))) { | |
| 147 | + contractType = "电铜"; | |
| 148 | + } else if (productNames.stream() | |
| 149 | + .anyMatch(name -> name != null && name.contains("锡锭"))) { | |
| 150 | + contractType = "锡锭"; | |
| 151 | + templateResource = new ClassPathResource("templates/tinIngotTemplate.xlsx"); | |
| 152 | + } else if (productNames.stream() | |
| 153 | + .anyMatch(name -> name != null && name.contains("锌锭"))) { | |
| 154 | + contractType = "锌锭"; | |
| 155 | + templateResource = new ClassPathResource("templates/zincIngotTemplate.xlsx"); | |
| 156 | + } else { | |
| 157 | + if (priced && "PICK_UP".equals(deliveryMode)) { | |
| 158 | + contractType = "未点价提货"; | |
| 159 | + templateResource = new ClassPathResource("templates/notPricedPickUp.xlsx"); | |
| 160 | + } else if (priced && "FACTORY_DELIVERY".equals(deliveryMode)) { | |
| 161 | + contractType = "未点价送货到厂"; | |
| 162 | + templateResource = new ClassPathResource("templates/notPricedDeliveryFactory.xlsx"); | |
| 163 | + } else if (!priced && "PICK_UP".equals(deliveryMode)) { | |
| 164 | + contractType = "已点价提货"; | |
| 165 | + templateResource = new ClassPathResource("templates/pricedPickUp.xlsx"); | |
| 166 | + } else if (!priced && "FACTORY_DELIVERY".equals(deliveryMode)) { | |
| 167 | + contractType = "已点价送货到厂"; | |
| 168 | + templateResource = new ClassPathResource("templates/pricedDeliveryFactory.xlsx"); | |
| 169 | + } | |
| 170 | + } | |
| 171 | + | |
| 172 | + | |
| 173 | + try { | |
| 174 | + try (InputStream inputStream = templateResource.getStream(); | |
| 175 | + Workbook workbook = new XSSFWorkbook(inputStream)) { | |
| 176 | + try { | |
| 177 | + DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); | |
| 178 | + Sheet sheet = workbook.getSheet("ERP合同模板电铜"); | |
| 179 | + if ("电铜".equals(contractType)) { | |
| 180 | + sheet = workbook.getSheet("ERP合同模板电铜"); | |
| 181 | + } else if ("锡锭".equals(contractType)) { | |
| 182 | + sheet = workbook.getSheet("ERP合同模板锡锭"); | |
| 183 | + } else if ("锌锭".equals(contractType)) { | |
| 184 | + sheet = workbook.getSheet("ERP合同模板锌锭"); | |
| 185 | + } else if ("未点价提货".equals(contractType)) { | |
| 186 | + sheet = workbook.getSheet("ERP合同模板未点价提货"); | |
| 187 | + } else if ("未点价送货到厂".equals(contractType)) { | |
| 188 | + sheet = workbook.getSheet("ERP合同模板未点价送货到厂"); | |
| 189 | + } else if ("已点价提货".equals(contractType)) { | |
| 190 | + sheet = workbook.getSheet("ERP合同模板已点价提货"); | |
| 191 | + } else if ("已点价送货到厂".equals(contractType)) { | |
| 192 | + sheet = workbook.getSheet("ERP合同模板已点价送货到厂"); | |
| 193 | + } | |
| 194 | + | |
| 195 | + int startRow = 6; // 合同计划子表开始行,可根据模板调整 | |
| 196 | + if (CollectionUtils.isNotEmpty(procurementContractLineList)) { | |
| 197 | + for (int i = 0; i < procurementContractLineList.size(); i++) { | |
| 198 | + GetProcurementContractLineBo line = procurementContractLineList.get(i); | |
| 199 | + ExcelUtil.setCellValue(sheet, startRow, 0, line.getInvoiceProductName()); | |
| 200 | + ExcelUtil.setCellValue(sheet, startRow, 2, line.getProductName()); | |
| 201 | + ExcelUtil.setCellValue(sheet, startRow, 4, formatDecimal(line.getQuantity())); | |
| 202 | + ExcelUtil.setCellValue(sheet, startRow, 6, formatDecimal(line.getUnitPrice())); | |
| 203 | + ExcelUtil.setCellValue(sheet, startRow, 7, formatDecimal(line.getExcludingTaxAmount())); | |
| 204 | + ExcelUtil.setCellValue(sheet, startRow, 8, formatDecimal(line.getTaxAmount())); | |
| 205 | + ExcelUtil.setCellValue(sheet, startRow, 9, formatDecimal(line.getTotalAmount())); | |
| 206 | + ExcelUtil.setCellValue(sheet, startRow, 10, line.getDeliveryTime() == null ? "" : line.getDeliveryTime().format(dateFormatter)); | |
| 207 | + startRow++; | |
| 208 | + } | |
| 209 | + } | |
| 210 | + | |
| 211 | + Map<String, Object> planDataMap = new HashMap<>(); | |
| 212 | + planDataMap.put("supplierName", nvl(detail.getSupplierName())); | |
| 213 | + planDataMap.put("companyFullName", nvl(detail.getCompanyFullName())); | |
| 214 | + planDataMap.put("signTime", detail.getSignTime() == null ? "" : detail.getSignTime().format(dateFormatter)); | |
| 215 | + planDataMap.put("totalQuantity", formatDecimal(detail.getTotalQuantity())); | |
| 216 | + planDataMap.put("totalExcludingTaxAmount", formatDecimal(detail.getTotalExcludingTaxAmount())); | |
| 217 | + planDataMap.put("totalTaxAmount", formatDecimal(detail.getTotalTaxAmount())); | |
| 218 | + planDataMap.put("totalAmount", formatDecimal(detail.getTotalAmount())); | |
| 219 | + planDataMap.put("settlementRatio", formatDecimal(detail.getSettlementRatio())); | |
| 220 | + planDataMap.put("planCode", nvl(detail.getProcurementPlanCode())); | |
| 221 | + planDataMap.put("specialAgreement", nvl(detail.getSpecialAgreement())); | |
| 222 | + //定价方式 | |
| 223 | + planDataMap.put("pricingMethod", ""); | |
| 224 | + if ("电铜".equals(contractType)) { | |
| 225 | + if (temporaryPrice) { | |
| 226 | + planDataMap.put("pricingMethod", "沪铜2604盘面价格 +升贴水(未定)为最终到厂增票结算价,其中升贴水在 月 日前确定。"); | |
| 227 | + } else { | |
| 228 | + planDataMap.put("pricingMethod", "按照双方协议价格。"); | |
| 229 | + } | |
| 230 | + } else if ("锡锭".equals(contractType)) { | |
| 231 | + if (temporaryPrice) { | |
| 232 | + planDataMap.put("pricingMethod", "需方在20 年 月 日前点上海有色网SMM1#锡日度价格的平均价即为到厂增票结算价," + | |
| 233 | + "同时用《确认函》双方盖章确认价格、数量;"); | |
| 234 | + } else { | |
| 235 | + planDataMap.put("pricingMethod", "按双方议价价格为到厂结算价。"); | |
| 236 | + } | |
| 237 | + } else if ("锌锭".equals(contractType)) { | |
| 238 | + if (temporaryPrice) { | |
| 239 | + planDataMap.put("pricingMethod", "按沪锌2605合约卖出价需方点价,成交价+ " + | |
| 240 | + "为到厂结算价,点价期限20 年 月 日 时前,点价后用(价格确认函)确认价格;"); | |
| 241 | + } else { | |
| 242 | + planDataMap.put("pricingMethod", "按双方议价价格为到厂结算价。"); | |
| 243 | + } | |
| 244 | + } | |
| 245 | + //付款、结算方式及期限 | |
| 246 | + planDataMap.put("deliveryMethod", ""); | |
| 247 | + if ("未点价提货".equals(contractType) || "已点价提货".equals(contractType)) { | |
| 248 | + if (settlementRatio.compareTo(new BigDecimal("100")) == 0) { | |
| 249 | + planDataMap.put("deliveryMethod", "电汇,提货当日根据供方开具的实际数量出库单预付全款,全额增值税发票及加盖印章的出库单原件,随车同行。"); | |
| 250 | + } else { | |
| 251 | + planDataMap.put("deliveryMethod", "电汇,提货当日根据供方开具的实际数量出库单预付" + settlementRatio + "%的货款," + | |
| 252 | + "余款待需方验收入库后凭《仓库收料单》,供方开具全额增值税发票及加盖印章的出库单原件到位后结清。"); | |
| 253 | + } | |
| 254 | + } | |
| 255 | + | |
| 256 | + ExcelUtil.processTemplateSheet(sheet, planDataMap); | |
| 257 | + | |
| 258 | + if ("PDF".equals(exportType)) { | |
| 259 | + ResponseUtil.setPDFResponseHead(response, detail.getProcurementPlanCode() + "_" + detail.getCompanyFullName() + "-采购合同.pdf"); | |
| 260 | + | |
| 261 | + // === 写入临时 .xlsx 文件 === | |
| 262 | + File tempExcel = File.createTempFile("plan_code_" + detail.getProcurementPlanCode(), ".xlsx"); | |
| 263 | + try (FileOutputStream fos = new FileOutputStream(tempExcel)) { | |
| 264 | + workbook.write(fos); | |
| 265 | + } | |
| 266 | + | |
| 267 | + // === 调用 LibreOffice 转 PDF === | |
| 268 | + File pdfFile = ExcelUtil.convertExcelToPdf(tempExcel, "/usr/bin/libreoffice --headless --convert-to pdf --outdir %s %s"); | |
| 269 | + | |
| 270 | + // === 输出 PDF 到浏览器 === | |
| 271 | + try (InputStream pdfIn = new FileInputStream(pdfFile)) { | |
| 272 | + byte[] buffer = new byte[8192]; | |
| 273 | + int len; | |
| 274 | + while ((len = pdfIn.read(buffer)) != -1) { | |
| 275 | + response.getOutputStream().write(buffer, 0, len); | |
| 276 | + } | |
| 277 | + response.getOutputStream().flush(); | |
| 278 | + } finally { | |
| 279 | + if (tempExcel.exists()) { | |
| 280 | + Files.delete(tempExcel.toPath()); | |
| 281 | + } | |
| 282 | + if (pdfFile.exists()) { | |
| 283 | + Files.delete(pdfFile.toPath()); | |
| 284 | + } | |
| 285 | + } | |
| 286 | + } else { | |
| 287 | + ExcelUtil.setupResponse(response, detail.getProcurementPlanCode() + "_" + detail.getCompanyFullName() + "-采购合同.xlsx"); | |
| 288 | + // 写入响应流 | |
| 289 | + workbook.write(response.getOutputStream()); | |
| 290 | + response.getOutputStream().flush(); | |
| 291 | + } | |
| 292 | + } finally { | |
| 293 | + IOUtils.closeQuietly(workbook); | |
| 294 | + } | |
| 295 | + | |
| 296 | + } catch (FileNotFoundException e) { | |
| 297 | + throw new RuntimeException("模板文件不存在: templates/Template.xlsx", e); | |
| 298 | + } catch (IOException e) { | |
| 299 | + throw new RuntimeException("无法读取模板文件: templates/Template.xlsx", e); | |
| 300 | + } | |
| 301 | + } catch (Exception e) { | |
| 302 | + log.error("采购合同导出失败: {}", e.getMessage(), e); | |
| 303 | + throw new RuntimeException("采购合同导出失败:", e); | |
| 304 | + } | |
| 305 | + } | |
| 306 | + | |
| 307 | + private String nvl(Object o) { | |
| 308 | + return o == null ? "" : o.toString(); | |
| 309 | + } | |
| 310 | + | |
| 311 | + private String formatDecimal(BigDecimal bd) { | |
| 312 | + if (bd == null) { | |
| 313 | + return ""; | |
| 314 | + } | |
| 315 | + return bd.stripTrailingZeros().toPlainString(); | |
| 199 | 316 | } |
| 200 | 317 | } | ... | ... |
| ... | ... | @@ -57,6 +57,8 @@ import java.time.LocalDateTime; |
| 57 | 57 | import java.util.*; |
| 58 | 58 | import java.util.stream.Collectors; |
| 59 | 59 | import javax.annotation.Resource; |
| 60 | + | |
| 61 | +import org.apache.commons.collections.CollectionUtils; | |
| 60 | 62 | import org.apache.commons.lang3.StringUtils; |
| 61 | 63 | import org.springframework.stereotype.Service; |
| 62 | 64 | import org.springframework.transaction.annotation.Transactional; |
| ... | ... | @@ -160,7 +162,7 @@ public class ProcurementPlanChangeServiceImpl extends |
| 160 | 162 | procurementBuyoutApplyService.create(vo1); |
| 161 | 163 | } else { |
| 162 | 164 | //todo 开票品名变更会改到 |
| 163 | - //变更的是主计划(开票品名 公司名称 另付运费) 直接修改主计划的数据、合同数据、子计划数据,子计划买断操作申请单(如果只有主计划就只生成主计划的买断操作申请单) | |
| 165 | + //变更的是主计划(开票品名 公司名称 另付运费) 直接修改主计划的数据、合同数据、子计划数据(含运到厂价),子计划买断操作申请单(如果只有主计划就只生成主计划的买断操作申请单) | |
| 164 | 166 | Wrapper<ProcurementPlan> queryWrapper = Wrappers.lambdaQuery(ProcurementPlan.class) |
| 165 | 167 | .eq(ProcurementPlan::getFrozen, false) |
| 166 | 168 | .eq(ProcurementPlan::getParentId, vo.getProcurementPlanId()); |
| ... | ... | @@ -184,6 +186,22 @@ public class ProcurementPlanChangeServiceImpl extends |
| 184 | 186 | .set(ProcurementPlan::getPlanType, planType) |
| 185 | 187 | .eq(ProcurementPlan::getId, vo.getProcurementPlanId()); |
| 186 | 188 | procurementPlanService.update(parentWrapper); |
| 189 | + //修改含运到厂价 | |
| 190 | + List<ProcurementPlanLine> lineList = procurementPlanLineService.list( | |
| 191 | + Wrappers.lambdaQuery(ProcurementPlanLine.class) | |
| 192 | + .eq(ProcurementPlanLine::getProcurementPlanId, vo.getProcurementPlanId()) | |
| 193 | + ); | |
| 194 | + if (CollectionUtils.isNotEmpty(lineList)) { | |
| 195 | + BigDecimal shippingCost = vo.getShippingCost(); | |
| 196 | + for (ProcurementPlanLine line : lineList) { | |
| 197 | + BigDecimal newPrice = line.getActualPurchasePrice().add(shippingCost); | |
| 198 | + | |
| 199 | + Wrapper<ProcurementPlanLine> updateWrapper = Wrappers.lambdaUpdate(ProcurementPlanLine.class) | |
| 200 | + .set(ProcurementPlanLine::getIncludingShippingPrice, newPrice) | |
| 201 | + .eq(ProcurementPlanLine::getId, line.getId()); | |
| 202 | + procurementPlanLineService.update(updateWrapper); | |
| 203 | + } | |
| 204 | + } | |
| 187 | 205 | |
| 188 | 206 | //修改子计划 开票品名 公司名称 另付运费 |
| 189 | 207 | Wrapper<ProcurementPlan> sonWrapper = Wrappers.lambdaUpdate(ProcurementPlan.class) |
| ... | ... | @@ -198,6 +216,22 @@ public class ProcurementPlanChangeServiceImpl extends |
| 198 | 216 | procurementPlanService.update(sonWrapper); |
| 199 | 217 | |
| 200 | 218 | for (ProcurementPlan procurementPlan : list) { |
| 219 | + //修改含运到厂价 | |
| 220 | + List<ProcurementPlanLine> lineList1 = procurementPlanLineService.list( | |
| 221 | + Wrappers.lambdaQuery(ProcurementPlanLine.class) | |
| 222 | + .eq(ProcurementPlanLine::getProcurementPlanId, procurementPlan.getId()) | |
| 223 | + ); | |
| 224 | + if (CollectionUtils.isNotEmpty(lineList1)) { | |
| 225 | + BigDecimal shippingCost = vo.getShippingCost(); | |
| 226 | + for (ProcurementPlanLine line : lineList1) { | |
| 227 | + BigDecimal newPrice = line.getActualPurchasePrice().add(shippingCost); | |
| 228 | + | |
| 229 | + Wrapper<ProcurementPlanLine> updateWrapper = Wrappers.lambdaUpdate(ProcurementPlanLine.class) | |
| 230 | + .set(ProcurementPlanLine::getIncludingShippingPrice, newPrice) | |
| 231 | + .eq(ProcurementPlanLine::getId, line.getId()); | |
| 232 | + procurementPlanLineService.update(updateWrapper); | |
| 233 | + } | |
| 234 | + } | |
| 201 | 235 | //先删除子计划买断操作申请单 |
| 202 | 236 | procurementBuyoutApplyService.deleteByPlanId(procurementPlan.getId()); |
| 203 | 237 | //重新生成子计划买断操作申请单 |
| ... | ... | @@ -217,6 +251,22 @@ public class ProcurementPlanChangeServiceImpl extends |
| 217 | 251 | .set(ProcurementPlan::getProcessNode, null) |
| 218 | 252 | .eq(ProcurementPlan::getId, vo.getProcurementPlanId()); |
| 219 | 253 | procurementPlanService.update(parentWrapper); |
| 254 | + //修改含运到厂价 | |
| 255 | + List<ProcurementPlanLine> lineList = procurementPlanLineService.list( | |
| 256 | + Wrappers.lambdaQuery(ProcurementPlanLine.class) | |
| 257 | + .eq(ProcurementPlanLine::getProcurementPlanId, vo.getProcurementPlanId()) | |
| 258 | + ); | |
| 259 | + if (CollectionUtils.isNotEmpty(lineList)) { | |
| 260 | + BigDecimal shippingCost = vo.getShippingCost(); | |
| 261 | + for (ProcurementPlanLine line : lineList) { | |
| 262 | + BigDecimal newPrice = line.getActualPurchasePrice().add(shippingCost); | |
| 263 | + | |
| 264 | + Wrapper<ProcurementPlanLine> updateWrapper = Wrappers.lambdaUpdate(ProcurementPlanLine.class) | |
| 265 | + .set(ProcurementPlanLine::getIncludingShippingPrice, newPrice) | |
| 266 | + .eq(ProcurementPlanLine::getId, line.getId()); | |
| 267 | + procurementPlanLineService.update(updateWrapper); | |
| 268 | + } | |
| 269 | + } | |
| 220 | 270 | //先删除买断操作申请单 |
| 221 | 271 | procurementBuyoutApplyService.deleteByPlanId(vo.getProcurementPlanId()); |
| 222 | 272 | //重新生成买断操作申请单 | ... | ... |
| ... | ... | @@ -194,6 +194,9 @@ public class ProcurementContractServiceImpl |
| 194 | 194 | if (entity == null || (entity.getDeleted() != null && entity.getDeleted() == 1)) { |
| 195 | 195 | throw new DefaultClientException("采购合同不存在或已废弃!"); |
| 196 | 196 | } |
| 197 | + this.update(Wrappers.lambdaUpdate(ProcurementContract.class) | |
| 198 | + .set(ProcurementContract::getApprovalStatus, "AUDIT") | |
| 199 | + .eq(ProcurementContract::getProcurementPlanId, id)); | |
| 197 | 200 | |
| 198 | 201 | flowInstanceWrapperService.startInstance(BPM_FLAG, id, BPM_FLAG, entity); |
| 199 | 202 | |
| ... | ... | @@ -206,17 +209,12 @@ public class ProcurementContractServiceImpl |
| 206 | 209 | @OpLog(type = OtherOpLogType.class, name = "根据计划ID废弃采购合同,ID:{}", params = {"#id"}) |
| 207 | 210 | public void deleteById(String id) { |
| 208 | 211 | Assert.notBlank(id); |
| 209 | - ProcurementContract entity = this.getById(id); | |
| 210 | - if (entity == null) { | |
| 211 | - return; | |
| 212 | - } | |
| 213 | 212 | |
| 214 | 213 | this.update(Wrappers.lambdaUpdate(ProcurementContract.class) |
| 215 | 214 | .set(ProcurementContract::getDeleted, 1) |
| 216 | 215 | .eq(ProcurementContract::getProcurementPlanId, id)); |
| 217 | 216 | |
| 218 | 217 | OpLogUtil.setVariable("id", id); |
| 219 | - OpLogUtil.setExtra(entity); | |
| 220 | 218 | } |
| 221 | 219 | |
| 222 | 220 | @Override | ... | ... |
| ... | ... | @@ -204,7 +204,7 @@ public class ProcurementPlanServiceImpl extends BaseMpServiceImpl<ProcurementPla |
| 204 | 204 | plan.setCreateBy(SecurityUtil.getCurrentUser().getName()); |
| 205 | 205 | } |
| 206 | 206 | if (StringUtils.isEmpty(plan.getCreateById())) { |
| 207 | - plan.setCreateBy(SecurityUtil.getCurrentUser().getId()); | |
| 207 | + plan.setCreateById(SecurityUtil.getCurrentUser().getId()); | |
| 208 | 208 | } |
| 209 | 209 | getBaseMapper().insert(plan); |
| 210 | 210 | ... | ... |
| ... | ... | @@ -71,7 +71,6 @@ |
| 71 | 71 | <select id="query" resultMap="ProcurementContractResult"> |
| 72 | 72 | <include refid="PC_sql"/> |
| 73 | 73 | <where> |
| 74 | - pc.deleted = 0 | |
| 75 | 74 | <if test="vo.procurementPlanCode != null and vo.procurementPlanCode != ''"> |
| 76 | 75 | AND pc.procurement_plan_code LIKE CONCAT('%', #{vo.procurementPlanCode}, '%') |
| 77 | 76 | </if> |
| ... | ... | @@ -96,12 +95,15 @@ |
| 96 | 95 | <if test="vo.endDeliveryTime != null"> |
| 97 | 96 | AND pc.delivery_time <![CDATA[ <= ]]> #{vo.endDeliveryTime} |
| 98 | 97 | </if> |
| 98 | + <if test="vo.deleted != null"> | |
| 99 | + AND pc.deleted = #{vo.deleted} | |
| 100 | + </if> | |
| 99 | 101 | </where> |
| 100 | 102 | ORDER BY pc.create_time DESC |
| 101 | 103 | </select> |
| 102 | 104 | |
| 103 | 105 | <select id="findById" resultMap="ProcurementContractResult"> |
| 104 | 106 | <include refid="PC_sql"/> |
| 105 | - WHERE pc.id = #{id} AND pc.deleted = 0 | |
| 107 | + WHERE pc.id = #{id} | |
| 106 | 108 | </select> |
| 107 | 109 | </mapper> | ... | ... |
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type