diff --git a/emis-biz-web/src/main/java/com/xdadan/erp/web/emis/EmisSpecialCalcWeightController.java b/emis-biz-web/src/main/java/com/xdadan/erp/web/emis/EmisSpecialCalcWeightController.java index 690a50ddb..0eb8c4c73 100644 --- a/emis-biz-web/src/main/java/com/xdadan/erp/web/emis/EmisSpecialCalcWeightController.java +++ b/emis-biz-web/src/main/java/com/xdadan/erp/web/emis/EmisSpecialCalcWeightController.java @@ -1,11 +1,11 @@ -/** +/** * @Project: emis * @Title: EmisSpecialCalcWeightController.java * @author linfso * @date 2024-01-10 06:50:43 * @Copyright: ShangHai Duta 2022 All rights reserved. - * @version v1.0 + * @version v1.0 * @Description:

特殊取重 控制器

*/ @@ -14,7 +14,16 @@ package com.xdadan.erp.web.emis; import java.util.List; import javax.servlet.http.HttpServletResponse; +import com.alibaba.fastjson.JSONObject; +import com.xdadan.erp.common.utils.DictUtils; import com.xdadan.erp.emis.domain.exception.EmisBizError; +import com.xdadan.erp.emis.domain.enumtype.EmisBizErrorType; +import com.xdadan.erp.emis.domain.EmisCountry; +import com.xdadan.erp.emis.domain.EmisSpecialCalcWeight; +import com.xdadan.erp.emis.domain.EmisTransLine; +import com.xdadan.erp.emis.domain.EmisTransProduct; +import com.xdadan.erp.emis.service.EmisBaseService; +import org.springframework.dao.DuplicateKeyException; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.web.bind.annotation.GetMapping; @@ -27,19 +36,17 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import com.xdadan.erp.common.annotation.Log; -import com.xdadan.erp.common.core.controller.BaseController; import com.xdadan.erp.common.core.domain.AjaxResult; import com.xdadan.erp.common.core.page.TableDataInfo; import com.xdadan.erp.common.enums.BusinessType; import com.xdadan.erp.common.utils.StringUtils; import com.xdadan.erp.common.utils.poi.ExcelUtil; -import com.xdadan.erp.emis.domain.EmisSpecialCalcWeight; import com.xdadan.erp.emis.service.IEmisSpecialCalcWeightService; /** * 特殊取重Controller - * + * * @author linfso * @date 2024-01-10 06:50:43 */ @@ -50,6 +57,9 @@ public class EmisSpecialCalcWeightController extends EmisBaseController @Autowired private IEmisSpecialCalcWeightService emisSpecialCalcWeightService; + @Autowired + private EmisBaseService emisBaseService; + /** * 查询特殊取重列表 */ @@ -137,4 +147,121 @@ public class EmisSpecialCalcWeightController extends EmisBaseController { return toAjax(emisSpecialCalcWeightService.deleteEmisSpecialCalcWeightByIds(ids)); } + + /** + * Excel草稿方式新增特殊取重(name->code) + */ + @PreAuthorize("@ss.hasPermi('emis:emisSpecialCalcWeight:draftSubmitSpecialCalcWeight')") + @PostMapping(value = "/draftSubmitSpecialCalcWeight") + public AjaxResult draftSubmitSpecialCalcWeight(@RequestBody EmisSpecialCalcWeight emisSpecialCalcWeight) + { + JSONObject jObjOut = new JSONObject(); + String result = "success"; + String msg = "提交成功"; + try + { + if (emisSpecialCalcWeight == null) + { + throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, "参数不能为空"); + } + if (StringUtils.isEmpty(emisSpecialCalcWeight.getProdCode())) + { + throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, "产品类型不能为空"); + } + if (StringUtils.isEmpty(emisSpecialCalcWeight.getCarryType())) + { + throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, "取重方式不能为空"); + } + if (emisSpecialCalcWeight.getBeginWeight() == null) + { + throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, "起始重量不能为空"); + } + if (emisSpecialCalcWeight.getEndWeight() == null) + { + throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, "结束重量不能为空"); + } + if (emisSpecialCalcWeight.getBeginDate() == null) + { + throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, "起始时间不能为空"); + } + if (emisSpecialCalcWeight.getEndDate() == null) + { + throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, "结束时间不能为空"); + } + + // country(查询emis_country):name -> code + if (StringUtils.isNotEmpty(emisSpecialCalcWeight.getCountry())) + { + EmisCountry country = emisBaseService.getCountryByName(emisSpecialCalcWeight.getCountry()); + if (country == null) + { + throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, + "国家未找到: " + emisSpecialCalcWeight.getCountry()); + } + emisSpecialCalcWeight.setCountry(country.getCode()); + emisSpecialCalcWeight.setCountryName(country.getName()); + } + + // transLineCode(查询emis_trans_line):name -> code + if (StringUtils.isNotEmpty(emisSpecialCalcWeight.getTransLineCode())) + { + EmisTransLine transLine = emisBaseService.getTransLineByName(emisSpecialCalcWeight.getTransLineCode()); + if (transLine == null) + { + throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, + "线路未找到: " + emisSpecialCalcWeight.getTransLineCode()); + } + emisSpecialCalcWeight.setTransLineCode(transLine.getLineCode()); + emisSpecialCalcWeight.setLineName(transLine.getLineName()); + } + + // prodCode(查询emis_trans_product):name -> code + EmisTransProduct transProduct = emisBaseService.getTransProductByName( + emisSpecialCalcWeight.getTransLineCode(), emisSpecialCalcWeight.getProdCode()); + if (transProduct == null) + { + throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, + "产品未找到: " + emisSpecialCalcWeight.getProdCode()); + } + emisSpecialCalcWeight.setProdCode(transProduct.getProdCode()); + emisSpecialCalcWeight.setProdName(transProduct.getProdName()); + + // carryType(字典emis_take_weight_method):name -> code + String carryTypeInput = emisSpecialCalcWeight.getCarryType(); + String carryTypeCode = DictUtils.getDictValue("emis_take_weight_method", carryTypeInput); + if (StringUtils.isEmpty(carryTypeCode)) + { + throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, "取重方式不正确: " + carryTypeInput); + } + emisSpecialCalcWeight.setCarryType(carryTypeCode); + + emisSpecialCalcWeightService.insertEmisSpecialCalcWeight(emisSpecialCalcWeight); + jObjOut.put("specialCalcWeightDetail", emisSpecialCalcWeight); + } + catch (EmisBizError ex) + { + ex.printStackTrace(); + result = "fail"; + msg = ex.getErrorCode() + ":" + ex.getMessage(); + } + catch (DuplicateKeyException e) + { + e.printStackTrace(); + result = "fail"; + msg = "数据重复"; + } + catch (Exception ex) + { + result = "fail"; + ex.printStackTrace(); + msg = "系统异常:" + ex.getMessage(); + if (ex instanceof EmisBizError) + { + msg = ((EmisBizError) ex).getErrorCode() + ":" + ex.getMessage(); + } + } + jObjOut.put("result", result); + jObjOut.put("msg", msg); + return AjaxResult.success("成功", jObjOut); + } }