From 6d4a80b03e6d0eb590b7c3330452fabceffad470 Mon Sep 17 00:00:00 2001 From: liujie <1793218484@qq.com> Date: 星期五, 05 九月 2025 16:20:35 +0800 Subject: [PATCH] 供应商erp --- ruoyi-admin/src/main/java/com/ruoyi/web/core/config/DataUpdateHandlerConfig.java | 4 ruoyi-common/src/main/java/com/ruoyi/common/core/domain/BaseModel.java | 1 ruoyi-system/src/main/java/com/ruoyi/system/model/TErpGoods.java | 2 ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TErpGoodsController.java | 156 +++++++++++++++++++++++++++++++++++++++++++++++++-- ruoyi-system/src/main/java/com/ruoyi/system/importExcel/TErpGoodsExcel.java | 6 - 5 files changed, 153 insertions(+), 16 deletions(-) diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TErpGoodsController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TErpGoodsController.java index fe94611..4ecd195 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TErpGoodsController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TErpGoodsController.java @@ -6,6 +6,8 @@ import cn.afterturn.easypoi.excel.entity.ExportParams; import cn.afterturn.easypoi.excel.entity.ImportParams; import com.alibaba.fastjson2.JSONObject; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.ruoyi.common.basic.PageInfo; import com.ruoyi.common.core.domain.AjaxResult; @@ -19,8 +21,12 @@ import com.ruoyi.system.dto.TErpGoodsUpdateStatusDto; import com.ruoyi.system.importExcel.TErpGoodsExcel; import com.ruoyi.system.model.TErpGoods; +import com.ruoyi.system.model.TErpGoodsType; +import com.ruoyi.system.model.TErpGoodsUnit; import com.ruoyi.system.query.TErpGoodsQuery; import com.ruoyi.system.service.TErpGoodsService; +import com.ruoyi.system.service.TErpGoodsTypeService; +import com.ruoyi.system.service.TErpGoodsUnitService; import com.ruoyi.system.vo.TErpGoodsVO; import com.ruoyi.web.controller.tool.ImportExcelUtil; import io.swagger.annotations.Api; @@ -38,10 +44,13 @@ import javax.validation.Valid; import java.io.IOException; import java.io.InputStream; +import java.math.BigDecimal; +import java.math.RoundingMode; import java.net.URLEncoder; import java.text.SimpleDateFormat; import java.time.LocalDate; import java.util.*; +import java.util.stream.Collectors; /** * <p> @@ -59,11 +68,15 @@ private final TErpGoodsService erpGoodsService; private final TokenService tokenService; + private final TErpGoodsTypeService erpGoodsTypeService; + private final TErpGoodsUnitService erpGoodsUnitService; @Autowired - public TErpGoodsController(TErpGoodsService erpGoodsService, TokenService tokenService) { + public TErpGoodsController(TErpGoodsService erpGoodsService, TokenService tokenService, TErpGoodsTypeService erpGoodsTypeService, TErpGoodsUnitService erpGoodsUnitService) { this.erpGoodsService = erpGoodsService; this.tokenService = tokenService; + this.erpGoodsTypeService = erpGoodsTypeService; + this.erpGoodsUnitService = erpGoodsUnitService; } @@ -179,19 +192,144 @@ JSONObject jsonObject = new JSONObject(); ImportParams params = new ImportParams(); params.setHeadRows(1); //表头行数 - String msg = null; InputStream inputStream = null; - TErpGoods goods = new TErpGoods(); + ArrayList<String> names = new ArrayList<>(); + ArrayList<TErpGoods> tErpGoods = new ArrayList<>(); + try { inputStream = file.getInputStream(); List<TErpGoodsExcel> carAnnuallyImportExcels = ExcelImportUtil.importExcel(inputStream, TErpGoodsExcel.class, params); - // 处理车辆数据 + Set<String> collect = carAnnuallyImportExcels.stream().map(TErpGoodsExcel::getGoodsIdCode).collect(Collectors.toSet()); + if (collect.size() != carAnnuallyImportExcels.size()) { + return AjaxResult.error("导入数据中商品标识码重复"); + } for (TErpGoodsExcel erpGoodsExcel : carAnnuallyImportExcels) { - System.out.println(erpGoodsExcel); + TErpGoods goods = new TErpGoods(); + goods.setSupplierClinicId(user.getUserId().toString()); + goods.setGoodsSource(1); + + // 判空 + if(erpGoodsExcel.getGoodsName()==null || erpGoodsExcel.getGoodsName().isEmpty()){ + names.add("商品名称不能为空"); + continue; + } + if(erpGoodsExcel.getGoodsIdCode()==null || erpGoodsExcel.getGoodsIdCode().isEmpty() + || erpGoodsExcel.getQuasiNumber() ==null || erpGoodsExcel.getQuasiNumber().isEmpty() + || erpGoodsExcel.getManufacturer()==null || erpGoodsExcel.getManufacturer().isEmpty() + || erpGoodsExcel.getFormulationSpec()==null || erpGoodsExcel.getFormulationSpec().isEmpty() + || erpGoodsExcel.getPackingSpec()==null || erpGoodsExcel.getPackingSpec().isEmpty() + || erpGoodsExcel.getClinicPurchasePrice()==null|| erpGoodsExcel.getClinicPurchasePrice().isEmpty() + || erpGoodsExcel.getWarningInventory()==null|| erpGoodsExcel.getWarningInventory().isEmpty() + || erpGoodsExcel.getTypeName()==null|| erpGoodsExcel.getTypeName().isEmpty()){ + names.add(erpGoodsExcel.getGoodsName()+" :信息有误,请检查后重新提交。"); + continue; + } + goods.setGoodsName(erpGoodsExcel.getGoodsName()); + // 判断数据是否正确 + // 判断标识码是否重复 + long count = erpGoodsService.count(new QueryWrapper<TErpGoods>().eq("goods_id_code", erpGoodsExcel.getGoodsIdCode())); + if(count>0){ + names.add(erpGoodsExcel.getGoodsName() + " :标识码重复"); + continue; + } + goods.setGoodsIdCode(erpGoodsExcel.getGoodsIdCode()); + goods.setQuasiNumber(erpGoodsExcel.getQuasiNumber()); + goods.setManufacturer(erpGoodsExcel.getManufacturer()); + goods.setFormulationSpec(erpGoodsExcel.getFormulationSpec()); + goods.setPackingSpec(erpGoodsExcel.getPackingSpec()); + + // 商品类型 + TErpGoodsType one = erpGoodsTypeService.getOne(new LambdaQueryWrapper<TErpGoodsType>().eq(TErpGoodsType::getTypeName, erpGoodsExcel.getTypeName())); + if(one==null){ + names.add(erpGoodsExcel.getGoodsName() + " :商品类型不存在"); + continue; + } + goods.setTypeId(one.getId()); + + // 采购价 + try { + goods.setClinicPurchasePrice(new BigDecimal(erpGoodsExcel.getClinicPurchasePrice()).setScale(2, RoundingMode.HALF_UP)); + }catch (Exception e){ + names.add(erpGoodsExcel.getGoodsName() + " :采购价有误"); + continue; + } + // 预警库存 + try { + goods.setWarningInventory(Integer.valueOf(erpGoodsExcel.getWarningInventory())); + }catch (Exception e){ + names.add(erpGoodsExcel.getGoodsName() + " :预警库存有误"); + continue; + } + goods.setGoodsYards(erpGoodsExcel.getGoodsYards()); + try { + if(erpGoodsExcel.getMaintenanceInterval()!=null && !erpGoodsExcel.getMaintenanceInterval().isEmpty()){ + Integer i = Integer.valueOf(erpGoodsExcel.getMaintenanceInterval()); + } + }catch (Exception e){ + names.add(erpGoodsExcel.getGoodsName() + " :保养周期有误"); + continue; + } + goods.setMaintenanceInterval(erpGoodsExcel.getMaintenanceInterval()); + + try { + if(erpGoodsExcel.getLowPurchaseQuantity()!=null && !erpGoodsExcel.getLowPurchaseQuantity().isEmpty()){ + goods.setLowPurchaseQuantity(Integer.valueOf(erpGoodsExcel.getLowPurchaseQuantity())); + } + }catch (Exception e){ + names.add(erpGoodsExcel.getGoodsName() + " :最低采购数量有误"); + continue; + } + + if(erpGoodsExcel.getLowUnitName()!=null && !erpGoodsExcel.getLowUnitName().isEmpty()){ + TErpGoodsUnit one1 = erpGoodsUnitService.getOne(new LambdaQueryWrapper<TErpGoodsUnit>().eq(TErpGoodsUnit::getUnitName, erpGoodsExcel.getLowUnitName())); + if (one1 == null) { + names.add(erpGoodsExcel.getGoodsName() + " :最低采购单位有误"); + continue; + } + goods.setLowUnitId(one1.getId()); + } + + + if(erpGoodsExcel.getIsPrescriptionDrug() !=null && !erpGoodsExcel.getIsPrescriptionDrug().isEmpty()){ + if(erpGoodsExcel.getIsPrescriptionDrug().equals("是")){ + goods.setIsPrescriptionDrug(1); + }else if (erpGoodsExcel.getIsPrescriptionDrug().equals("否")){ + goods.setIsPrescriptionDrug(2); + }else { + names.add(erpGoodsExcel.getGoodsName() + " :是否为处方药有误"); + continue; + } + } + + if(erpGoodsExcel.getPackingUnitName() !=null && !erpGoodsExcel.getPackingUnitName().isEmpty()){ + TErpGoodsUnit unit = erpGoodsUnitService.getOne(new LambdaQueryWrapper<TErpGoodsUnit>().eq(TErpGoodsUnit::getUnitName, erpGoodsExcel.getPackingUnitName())); + if(unit != null){ + goods.setPackingUnitId(unit.getId()); + }else { + names.add(erpGoodsExcel.getGoodsName() + " :包装单位有误"); + continue; + } + } + + goods.setInstructionsUse(erpGoodsExcel.getInstructionsUse()); + goods.setSideEffect(erpGoodsExcel.getSideEffect()); + goods.setSimplifiedCode(erpGoodsExcel.getSimplifiedCode()); + goods.setDosageForm(erpGoodsExcel.getDosageForm()); + goods.setUsageClassification(erpGoodsExcel.getUsageClassification()); + goods.setProductBrand(erpGoodsExcel.getProductBrand()); + goods.setPlaceOfOrigin(erpGoodsExcel.getPlaceOfOrigin()); + goods.setIngredient(erpGoodsExcel.getIngredient()); + goods.setTrait(erpGoodsExcel.getTrait()); + goods.setIndication(erpGoodsExcel.getIndication()); + goods.setTaboo(erpGoodsExcel.getTaboo()); + goods.setPrecautions(erpGoodsExcel.getPrecautions()); + goods.setInteraction(erpGoodsExcel.getInteraction()); + goods.setStorage(erpGoodsExcel.getStorage()); + tErpGoods.add( goods); } } catch (Exception e) { e.printStackTrace(); - return AjaxResult.error("车辆年检记录导入失败!"); + return AjaxResult.error("记录导入失败!"); }finally { try { inputStream.close(); @@ -199,7 +337,11 @@ throw new ServiceException(e.getMessage()); } } - return AjaxResult.success(jsonObject); + if(names.size()>0){ + return AjaxResult.error("导入失败记录如下:",names); + } + erpGoodsService.saveBatch(tErpGoods); + return AjaxResult.success(); } diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/core/config/DataUpdateHandlerConfig.java b/ruoyi-admin/src/main/java/com/ruoyi/web/core/config/DataUpdateHandlerConfig.java index 607f8ea..28d5d31 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/core/config/DataUpdateHandlerConfig.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/core/config/DataUpdateHandlerConfig.java @@ -33,11 +33,11 @@ Long userId = SecurityUtils.getUserId(); if (StringUtils.isNotBlank(userName)) { this.setFieldValByName("createBy", userName, metaObject); - this.setFieldValByName("createId", userId, metaObject); +// this.setFieldValByName("createId", userId, metaObject); this.setFieldValByName("updateBy", userName, metaObject); } else { this.setFieldValByName("createBy", userName, metaObject); - this.setFieldValByName("createId", userId, metaObject); +// this.setFieldValByName("createId", userId, metaObject); this.setFieldValByName("updateBy", userName, metaObject); } diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/BaseModel.java b/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/BaseModel.java index 3c572e0..08bed43 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/BaseModel.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/BaseModel.java @@ -66,7 +66,6 @@ * 新增执行 */ @ApiModelProperty(value = "记录创建人id,前端忽略") - @JsonIgnore @TableField(value = "create_id", fill = FieldFill.INSERT) private String createId; diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/importExcel/TErpGoodsExcel.java b/ruoyi-system/src/main/java/com/ruoyi/system/importExcel/TErpGoodsExcel.java index 2590d67..39b3bf4 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/importExcel/TErpGoodsExcel.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/importExcel/TErpGoodsExcel.java @@ -42,12 +42,8 @@ @Excel(width = 30,name = "最低采购单位") private String lowUnitName; - @Excel(width = 30,name = "是否为处方药",replace = {"1_是","2_否"}) + @Excel(width = 30,name = "是否为处方药") private String isPrescriptionDrug; - - @ApiModelProperty(value = "商品规格") - @TableField("goods_spec") - private String goodsSpec; @Excel(width = 30,name = "*预警库存") diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/model/TErpGoods.java b/ruoyi-system/src/main/java/com/ruoyi/system/model/TErpGoods.java index 9cf22fa..972de08 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/model/TErpGoods.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/model/TErpGoods.java @@ -38,7 +38,7 @@ @ApiModelProperty(value = "商品来源 1=平台添加 2=线下添加") @TableField("goods_source") - private String goodsSource; + private Integer goodsSource; @ApiModelProperty(value = "商品名称") @TableField("goods_name") -- Gitblit v1.7.1