diff --git a/nursing-unit-invoicing/nu-invoicing-biz/src/main/java/com/nu/modules/ConfigMaterial/controller/ConfigMaterialInfoController.java b/nursing-unit-invoicing/nu-invoicing-biz/src/main/java/com/nu/modules/ConfigMaterial/controller/ConfigMaterialInfoController.java index 90b2ff36..180c0a12 100644 --- a/nursing-unit-invoicing/nu-invoicing-biz/src/main/java/com/nu/modules/ConfigMaterial/controller/ConfigMaterialInfoController.java +++ b/nursing-unit-invoicing/nu-invoicing-biz/src/main/java/com/nu/modules/ConfigMaterial/controller/ConfigMaterialInfoController.java @@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.nu.modules.ConfigMaterial.entity.ConfigMaterialInfo; +import com.nu.modules.ConfigMaterial.entity.ConfigMaterialTypeImportEntity; import com.nu.modules.ConfigMaterial.service.IConfigMaterialInfoService; import com.nu.modules.configSuppliersInfo.service.IConfigSuppliersInfoService; import com.nu.modules.utils.PinyinUtils; @@ -17,46 +18,53 @@ import org.jeecg.common.aspect.annotation.AutoLog; import org.jeecg.common.system.base.controller.JeecgController; import org.jeecg.common.system.query.QueryGenerator; import org.jeecg.common.system.query.QueryRuleEnum; +import org.jeecgframework.poi.excel.ExcelImportUtil; +import org.jeecgframework.poi.excel.entity.ImportParams; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; +import org.springframework.web.multipart.MultipartHttpServletRequest; import org.springframework.web.servlet.ModelAndView; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import java.io.IOException; import java.util.Arrays; import java.util.HashMap; +import java.util.List; import java.util.Map; - /** +/** * @Description: 物料信息 * @Author: jeecg-boot - * @Date: 2025-03-13 + * @Date: 2025-03-13 * @Version: V1.0 */ -@Api(tags="物料信息") +@Api(tags = "物料信息") @RestController //@RequestMapping("/configMaterialInfo/configMaterialInfo") @RequestMapping("/invoicing/configMaterialInfo") @Slf4j public class ConfigMaterialInfoController extends JeecgController { - @Autowired - private IConfigMaterialInfoService configMaterialInfoService; - /** - * 分页列表查询 - * - * @param configMaterialInfo - * @param pageNo - * @param pageSize - * @param req - * @return - */ - //@AutoLog(value = "物料信息-分页列表查询") - @ApiOperation(value="物料信息-分页列表查询", notes="物料信息-分页列表查询") - @GetMapping(value = "/list") - public Result> queryPageList(ConfigMaterialInfo configMaterialInfo, - @RequestParam(name="pageNo", defaultValue="1") Integer pageNo, - @RequestParam(name="pageSize", defaultValue="10") Integer pageSize, - HttpServletRequest req) { + @Autowired + private IConfigMaterialInfoService configMaterialInfoService; + + /** + * 分页列表查询 + * + * @param configMaterialInfo + * @param pageNo + * @param pageSize + * @param req + * @return + */ + //@AutoLog(value = "物料信息-分页列表查询") + @ApiOperation(value = "物料信息-分页列表查询", notes = "物料信息-分页列表查询") + @GetMapping(value = "/list") + public Result> queryPageList(ConfigMaterialInfo configMaterialInfo, + @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo, + @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize, + HttpServletRequest req) { // 自定义查询规则 Map customeRuleMap = new HashMap<>(); // 自定义多选的查询规则为:LIKE_WITH_OR @@ -66,165 +74,182 @@ public class ConfigMaterialInfoController extends JeecgController queryWrapper = QueryGenerator.initQueryWrapper(configMaterialInfo, req.getParameterMap(),customeRuleMap); - if(StringUtils.isNotBlank(configMaterialInfo.getTreeId())){ - queryWrapper.apply(" (category_id = '"+configMaterialInfo.getTreeId()+"' or type_id = '"+configMaterialInfo.getTreeId()+"' or medication_id = '"+configMaterialInfo.getTreeId()+"' )"); - } - if (StringUtils.isNotBlank(configMaterialInfo.getKeyWord())) { - String value = configMaterialInfo.getKeyWord(); - queryWrapper.and(c -> c.like("material_name", value).or().like("pinyin", value).or().like("material_no", value)); - } - Page page = new Page(pageNo, pageSize); - IPage pageList = configMaterialInfoService.page(page, queryWrapper); - return Result.OK(pageList); - } - - /** - * 添加 - * - * @param configMaterialInfo - * @return - */ - @AutoLog(value = "物料信息-添加") - @ApiOperation(value="物料信息-添加", notes="物料信息-添加") - @RequiresPermissions("configMaterialInfo:config_material_info:add") - @PostMapping(value = "/add") - public Result add(@RequestBody ConfigMaterialInfo configMaterialInfo) { - - String chinese = configMaterialInfo.getMaterialName(); - String firstLetter = PinyinUtils.getFirstLetter(chinese); - configMaterialInfo.setPinyin(firstLetter); - configMaterialInfoService.save(configMaterialInfo); - return Result.OK("添加成功!"); - } - - /** - * 编辑 - * - * @param configMaterialInfo - * @return - */ - @AutoLog(value = "物料信息-编辑") - @ApiOperation(value="物料信息-编辑", notes="物料信息-编辑") - @RequiresPermissions("configMaterialInfo:config_material_info:edit") - @RequestMapping(value = "/edit", method = {RequestMethod.PUT,RequestMethod.POST}) - public Result edit(@RequestBody ConfigMaterialInfo configMaterialInfo) { - if(StringUtils.isNotBlank(configMaterialInfo.getMaterialName())){ - String chinese = configMaterialInfo.getMaterialName(); - String firstLetter = PinyinUtils.getFirstLetter(chinese); - configMaterialInfo.setPinyin(firstLetter); - } - configMaterialInfoService.updateById(configMaterialInfo); - return Result.OK("操作成功!"); - } - - @AutoLog(value = "物料信息-编辑") - @ApiOperation(value="物料信息-编辑", notes="物料信息-编辑") - @RequiresPermissions("configMaterialInfo:config_material_info:edit") - @RequestMapping(value = "/editInfo", method = {RequestMethod.PUT,RequestMethod.POST}) - public Result editInfo(@RequestBody ConfigMaterialInfo configMaterialInfo) { - if(StringUtils.isNotBlank(configMaterialInfo.getMaterialName())){ - String chinese = configMaterialInfo.getMaterialName(); - String firstLetter = PinyinUtils.getFirstLetter(chinese); - configMaterialInfo.setPinyin(firstLetter); - } - configMaterialInfoService.updateOneTwoPrice(configMaterialInfo); - configMaterialInfoService.updateById(configMaterialInfo); - return Result.OK("操作成功!"); - } - - /** - * 通过id删除 - * - * @param id - * @return - */ - @AutoLog(value = "物料信息-通过id删除") - @ApiOperation(value="物料信息-通过id删除", notes="物料信息-通过id删除") - @RequiresPermissions("configMaterialInfo:config_material_info:delete") - @DeleteMapping(value = "/delete") - public Result delete(@RequestParam(name="id",required=true) String id) { - configMaterialInfoService.removeById(id); - return Result.OK("删除成功!"); - } - - /** - * 批量删除 - * - * @param ids - * @return - */ - @AutoLog(value = "物料信息-批量删除") - @ApiOperation(value="物料信息-批量删除", notes="物料信息-批量删除") - @RequiresPermissions("configMaterialInfo:config_material_info:deleteBatch") - @DeleteMapping(value = "/deleteBatch") - public Result deleteBatch(@RequestParam(name="ids",required=true) String ids) { - this.configMaterialInfoService.removeByIds(Arrays.asList(ids.split(","))); - return Result.OK("批量删除成功!"); - } - - /** - * 通过id查询 - * - * @param id - * @return - */ - //@AutoLog(value = "物料信息-通过id查询") - @ApiOperation(value="物料信息-通过id查询", notes="物料信息-通过id查询") - @GetMapping(value = "/queryById") - public Result queryById(@RequestParam(name="id",required=true) String id) { - ConfigMaterialInfo configMaterialInfo = configMaterialInfoService.getById(id); - if(configMaterialInfo==null) { - return Result.error("未找到对应数据"); - } - return Result.OK(configMaterialInfo); - } - - /** - * 导出excel - * - * @param request - * @param configMaterialInfo - */ - @RequestMapping(value = "/exportXls") - public ModelAndView exportXls(HttpServletRequest request, ConfigMaterialInfo configMaterialInfo) { - return super.exportXls(request, configMaterialInfo, ConfigMaterialInfo.class, "物料信息"); + QueryWrapper queryWrapper = QueryGenerator.initQueryWrapper(configMaterialInfo, req.getParameterMap(), customeRuleMap); + if (StringUtils.isNotBlank(configMaterialInfo.getTreeId())) { + queryWrapper.apply(" (category_id = '" + configMaterialInfo.getTreeId() + "' or type_id = '" + configMaterialInfo.getTreeId() + "' or medication_id = '" + configMaterialInfo.getTreeId() + "' )"); + } + if (StringUtils.isNotBlank(configMaterialInfo.getKeyWord())) { + String value = configMaterialInfo.getKeyWord(); + queryWrapper.and(c -> c.like("material_name", value).or().like("pinyin", value).or().like("material_no", value)); + } + Page page = new Page(pageNo, pageSize); + IPage pageList = configMaterialInfoService.page(page, queryWrapper); + return Result.OK(pageList); } /** - * 通过excel导入数据 - * - * @param request - * @param response - * @return - */ - @RequiresPermissions("configMaterialInfo:config_material_info:importExcel") - @RequestMapping(value = "/importExcel", method = RequestMethod.POST) - public Result importExcel(HttpServletRequest request, HttpServletResponse response) { - return super.importExcel(request, response, ConfigMaterialInfo.class); + * 添加 + * + * @param configMaterialInfo + * @return + */ + @AutoLog(value = "物料信息-添加") + @ApiOperation(value = "物料信息-添加", notes = "物料信息-添加") + @RequiresPermissions("configMaterialInfo:config_material_info:add") + @PostMapping(value = "/add") + public Result add(@RequestBody ConfigMaterialInfo configMaterialInfo) { + + String chinese = configMaterialInfo.getMaterialName(); + String firstLetter = PinyinUtils.getFirstLetter(chinese); + configMaterialInfo.setPinyin(firstLetter); + configMaterialInfoService.save(configMaterialInfo); + return Result.OK("添加成功!"); + } + + /** + * 编辑 + * + * @param configMaterialInfo + * @return + */ + @AutoLog(value = "物料信息-编辑") + @ApiOperation(value = "物料信息-编辑", notes = "物料信息-编辑") + @RequiresPermissions("configMaterialInfo:config_material_info:edit") + @RequestMapping(value = "/edit", method = {RequestMethod.PUT, RequestMethod.POST}) + public Result edit(@RequestBody ConfigMaterialInfo configMaterialInfo) { + if (StringUtils.isNotBlank(configMaterialInfo.getMaterialName())) { + String chinese = configMaterialInfo.getMaterialName(); + String firstLetter = PinyinUtils.getFirstLetter(chinese); + configMaterialInfo.setPinyin(firstLetter); + } + configMaterialInfoService.updateById(configMaterialInfo); + return Result.OK("操作成功!"); + } + + @AutoLog(value = "物料信息-编辑") + @ApiOperation(value = "物料信息-编辑", notes = "物料信息-编辑") + @RequiresPermissions("configMaterialInfo:config_material_info:edit") + @RequestMapping(value = "/editInfo", method = {RequestMethod.PUT, RequestMethod.POST}) + public Result editInfo(@RequestBody ConfigMaterialInfo configMaterialInfo) { + if (StringUtils.isNotBlank(configMaterialInfo.getMaterialName())) { + String chinese = configMaterialInfo.getMaterialName(); + String firstLetter = PinyinUtils.getFirstLetter(chinese); + configMaterialInfo.setPinyin(firstLetter); + } + configMaterialInfoService.updateOneTwoPrice(configMaterialInfo); + configMaterialInfoService.updateById(configMaterialInfo); + return Result.OK("操作成功!"); + } + + /** + * 通过id删除 + * + * @param id + * @return + */ + @AutoLog(value = "物料信息-通过id删除") + @ApiOperation(value = "物料信息-通过id删除", notes = "物料信息-通过id删除") + @RequiresPermissions("configMaterialInfo:config_material_info:delete") + @DeleteMapping(value = "/delete") + public Result delete(@RequestParam(name = "id", required = true) String id) { + configMaterialInfoService.removeById(id); + return Result.OK("删除成功!"); + } + + /** + * 批量删除 + * + * @param ids + * @return + */ + @AutoLog(value = "物料信息-批量删除") + @ApiOperation(value = "物料信息-批量删除", notes = "物料信息-批量删除") + @RequiresPermissions("configMaterialInfo:config_material_info:deleteBatch") + @DeleteMapping(value = "/deleteBatch") + public Result deleteBatch(@RequestParam(name = "ids", required = true) String ids) { + this.configMaterialInfoService.removeByIds(Arrays.asList(ids.split(","))); + return Result.OK("批量删除成功!"); + } + + /** + * 通过id查询 + * + * @param id + * @return + */ + //@AutoLog(value = "物料信息-通过id查询") + @ApiOperation(value = "物料信息-通过id查询", notes = "物料信息-通过id查询") + @GetMapping(value = "/queryById") + public Result queryById(@RequestParam(name = "id", required = true) String id) { + ConfigMaterialInfo configMaterialInfo = configMaterialInfoService.getById(id); + if (configMaterialInfo == null) { + return Result.error("未找到对应数据"); + } + return Result.OK(configMaterialInfo); + } + + /** + * 导出类型excel模板 + * + */ + @RequestMapping(value = "/exportTypeExcel") + public ModelAndView exportTypeExcel() { + return configMaterialInfoService.exportTypeExcel(); + } + + /** + * 导出物料信息excel模板 + * + */ + @RequestMapping(value = "/exportMateriallInfoExcel") + public ModelAndView exportMateriallInfoExcel() { + return configMaterialInfoService.exportMateriallInfoExcel(); + } + + /** + * 通过excel导入物料信息数据 + * + * @param request + * @param response + * @return + */ + @RequestMapping(value = "/importMateriallInfo", method = RequestMethod.POST) + public Result importMateriallInfo(HttpServletRequest request, HttpServletResponse response) { + return configMaterialInfoService.importMateriallInfo(request); + } + + /** + * 导入物料类别 + * + * @param request + * @param response + * @return + */ + @RequestMapping(value = "/importType", method = RequestMethod.POST) + public Result importType(HttpServletRequest request, HttpServletResponse response) { + return configMaterialInfoService.importType(request); } - @AutoLog(value = "物料信息-单个物料迁移") - @ApiOperation(value="物料信息-单个物料迁移", notes="物料信息-单个物料迁移") - @RequiresPermissions("configMaterialInfo:config_material_info:edit") - @RequestMapping(value = "/wlqianyi", method = {RequestMethod.PUT,RequestMethod.POST}) - public Result wlqianyi(@RequestBody ConfigMaterialInfo configMaterialInfo) { - configMaterialInfoService.wlqianyi(configMaterialInfo); - return Result.OK("操作成功!"); - } + @AutoLog(value = "物料信息-单个物料迁移") + @ApiOperation(value = "物料信息-单个物料迁移", notes = "物料信息-单个物料迁移") + @RequiresPermissions("configMaterialInfo:config_material_info:edit") + @RequestMapping(value = "/wlqianyi", method = {RequestMethod.PUT, RequestMethod.POST}) + public Result wlqianyi(@RequestBody ConfigMaterialInfo configMaterialInfo) { + configMaterialInfoService.wlqianyi(configMaterialInfo); + return Result.OK("操作成功!"); + } - @ApiOperation(value="可配置物料的列表", notes="可配置物料的列表") - @GetMapping(value = "/getConfiguredList") - public Result> getConfiguredList(ConfigMaterialInfo configMaterialInfo, - @RequestParam(name="pageNo", defaultValue="1") Integer pageNo, - @RequestParam(name="pageSize", defaultValue="10") Integer pageSize, - HttpServletRequest req) { - // 自定义查询规则 - Page page = new Page(pageNo, pageSize); - IPage pageList = configMaterialInfoService.getConfiguredList(page, configMaterialInfo); - return Result.OK(pageList); - } + @ApiOperation(value = "可配置物料的列表", notes = "可配置物料的列表") + @GetMapping(value = "/getConfiguredList") + public Result> getConfiguredList(ConfigMaterialInfo configMaterialInfo, + @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo, + @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize, + HttpServletRequest req) { + // 自定义查询规则 + Page page = new Page(pageNo, pageSize); + IPage pageList = configMaterialInfoService.getConfiguredList(page, configMaterialInfo); + return Result.OK(pageList); + } } diff --git a/nursing-unit-invoicing/nu-invoicing-biz/src/main/java/com/nu/modules/ConfigMaterial/entity/ConfigMaterialInfo.java b/nursing-unit-invoicing/nu-invoicing-biz/src/main/java/com/nu/modules/ConfigMaterial/entity/ConfigMaterialInfo.java index 5a27530b..e8c471e3 100644 --- a/nursing-unit-invoicing/nu-invoicing-biz/src/main/java/com/nu/modules/ConfigMaterial/entity/ConfigMaterialInfo.java +++ b/nursing-unit-invoicing/nu-invoicing-biz/src/main/java/com/nu/modules/ConfigMaterial/entity/ConfigMaterialInfo.java @@ -36,79 +36,75 @@ public class ConfigMaterialInfo implements Serializable { @TableId(type = IdType.ASSIGN_ID) @ApiModelProperty(value = "id") private java.lang.String id; - /**物料类别*/ - @Excel(name = "物料类别", width = 15, dictTable = "nu_config_material_category", dicText = "category_name", dicCode = "id") + /**一级分类*/ + @Excel(name = "一级分类", width = 15, dictTable = "nu_config_material_category", dicText = "category_name", dicCode = "id") @Dict(dictTable = "nu_config_material_category", dicText = "category_name", dicCode = "id") - @ApiModelProperty(value = "物料类别") + @ApiModelProperty(value = "一级分类") private java.lang.String categoryId; - /**物料类型*/ - @Excel(name = "物料类型", width = 15, dictTable = "nu_config_material_type", dicText = "type_name", dicCode = "id") + /**二级分类*/ + @Excel(name = "二级分类", width = 15, dictTable = "nu_config_material_type", dicText = "type_name", dicCode = "id") @Dict(dictTable = "nu_config_material_type", dicText = "type_name", dicCode = "id") - @ApiModelProperty(value = "物料类型") + @ApiModelProperty(value = "二级分类") private java.lang.String typeId; - /**用药类型*/ - @Excel(name = "用药类型", width = 15, dictTable = "nu_config_material_medication", dicText = "medication_name", dicCode = "id") + /**三级分类*/ + @Excel(name = "三级分类", width = 15, dictTable = "nu_config_material_medication", dicText = "medication_name", dicCode = "id") @Dict(dictTable = "nu_config_material_medication", dicText = "medication_name", dicCode = "id") - @ApiModelProperty(value = "用药类型") + @ApiModelProperty(value = "三级分类") private java.lang.String medicationId; - /**货品名称*/ - @Excel(name = "货品名称", width = 15) - @ApiModelProperty(value = "货品名称") + /**物料名称*/ + @Excel(name = "物料名称", width = 15) + @ApiModelProperty(value = "物料名称") private java.lang.String materialName; - /**货品编码*/ - @Excel(name = "货品编码", width = 15) - @ApiModelProperty(value = "货品编码") + /**物料编码*/ + @Excel(name = "物料编码", width = 15) + @ApiModelProperty(value = "物料编码") private java.lang.String materialNo; /**规格型号*/ @Excel(name = "规格型号", width = 15) @ApiModelProperty(value = "规格型号") private java.lang.String specificationModel; + /**品牌型号*/ + @Excel(name = "品牌型号", width = 15) + @ApiModelProperty(value = "品牌型号") + private String brandType; + /**生产厂家*/ + @Excel(name = "生产厂家", width = 15) + @ApiModelProperty(value = "生产厂家") + private String manufacturer; /**销售单价*/ - @Excel(name = "销售单价", width = 15) @ApiModelProperty(value = "销售单价") private java.math.BigDecimal salesUnitPrice; /**参考单价*/ - @Excel(name = "参考单价", width = 15) @ApiModelProperty(value = "参考单价") private java.math.BigDecimal referenceUnitPrice; /**货品单位*/ - @Excel(name = "货品单位", width = 15) @ApiModelProperty(value = "货品单位") private java.lang.String materialUnits; /**多单位开关 0关 1开*/ - @Excel(name = "多单位开关", width = 15,replace = {"开_Y","关_N"} ) @ApiModelProperty(value = "多单位开关 0关 1开") private java.lang.String multiUnitSwitch; /**父级单位*/ - @Excel(name = "父级单位", width = 15) @ApiModelProperty(value = "父级单位") private java.lang.String oneUnit; /**父级单位兑换比例*/ - @Excel(name = "父级单位兑换比例", width = 15) @ApiModelProperty(value = "父级单位兑换比例") private java.lang.Integer oneUnitProportion; /**父级单位价格*/ - @Excel(name = "父级单位价格", width = 15) @ApiModelProperty(value = "父级单位价格") private java.math.BigDecimal oneUnitPrice; /**爷级单位*/ - @Excel(name = "爷级单位", width = 15) @ApiModelProperty(value = "爷级单位") private java.lang.String twoUnit; /**爷级单位兑换比例*/ - @Excel(name = "爷级单位兑换比例", width = 15) @ApiModelProperty(value = "爷级单位兑换比例") private java.lang.Integer twoUnitProportion; /**爷级单位价格*/ - @Excel(name = "爷级单位价格", width = 15) @ApiModelProperty(value = "爷级单位价格") private java.math.BigDecimal twoUnitPrice; /**多单位采购默认使用 0子集 1父级 2爷级*/ - @Excel(name = "多单位采购默认使用", width = 15) @ApiModelProperty(value = "多单位采购默认使用 0子集 1父级 2爷级") private java.lang.String multiUnitType; /**供应商*/ - @Excel(name = "供应商", width = 15,dictTable = "nu_config_suppliers_info" , dicCode = "id" , dicText = "suppliers_name") @ApiModelProperty(value = "供应商") @Dict(dictTable = "nu_config_suppliers_info" , dicCode = "id" , dicText = "suppliers_name") private java.lang.String suppliers; @@ -155,9 +151,6 @@ public class ConfigMaterialInfo implements Serializable { @Dict(dicCode = "wl_tag_type") private String tagType; - private String brandType;//品牌 - private String manufacturer;//生产厂家 - /**是否医保报销 0否 1是*/ @Dict(dicCode = "yn") private java.lang.String izYbbx; diff --git a/nursing-unit-invoicing/nu-invoicing-biz/src/main/java/com/nu/modules/ConfigMaterial/entity/ConfigMaterialInfoImportEntity.java b/nursing-unit-invoicing/nu-invoicing-biz/src/main/java/com/nu/modules/ConfigMaterial/entity/ConfigMaterialInfoImportEntity.java new file mode 100644 index 00000000..22323e60 --- /dev/null +++ b/nursing-unit-invoicing/nu-invoicing-biz/src/main/java/com/nu/modules/ConfigMaterial/entity/ConfigMaterialInfoImportEntity.java @@ -0,0 +1,195 @@ +package com.nu.modules.ConfigMaterial.entity; + +import com.baomidou.mybatisplus.annotation.*; +import com.fasterxml.jackson.annotation.JsonFormat; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.experimental.Accessors; +import org.jeecg.common.aspect.annotation.Dict; +import org.jeecgframework.poi.excel.annotation.Excel; +import org.springframework.format.annotation.DateTimeFormat; + +import java.io.Serializable; +import java.math.BigDecimal; +import java.util.Date; + +/** + * @Description: 物料信息 + * @Author: jeecg-boot + * @Date: 2025-03-13 + * @Version: V1.0 + */ +@Data +@TableName("nu_config_material_info") +@Accessors(chain = true) +@EqualsAndHashCode(callSuper = false) +@ApiModel(value="config_material_info对象", description="物料信息") +public class ConfigMaterialInfoImportEntity implements Serializable { + private static final long serialVersionUID = 1L; + + /**id*/ + @TableId(type = IdType.ASSIGN_ID) + @ApiModelProperty(value = "id") + private String id; + /**一级分类*/ + @Excel(name = "一级分类", width = 15) + @Dict(dictTable = "nu_config_material_category", dicText = "category_name", dicCode = "id") + @ApiModelProperty(value = "一级分类") + private String categoryId; + /**二级分类*/ + @Excel(name = "二级分类", width = 15) + @Dict(dictTable = "nu_config_material_type", dicText = "type_name", dicCode = "id") + @ApiModelProperty(value = "二级分类") + private String typeId; + /**三级分类*/ + @Excel(name = "三级分类", width = 15) + @Dict(dictTable = "nu_config_material_medication", dicText = "medication_name", dicCode = "id") + @ApiModelProperty(value = "三级分类") + private String medicationId; + /**物料名称*/ + @Excel(name = "物料名称", width = 15) + @ApiModelProperty(value = "物料名称") + private String materialName; + /**物料编码*/ + @Excel(name = "物料编码", width = 15) + @ApiModelProperty(value = "物料编码") + private String materialNo; + /**规格型号*/ + @Excel(name = "规格型号", width = 15) + @ApiModelProperty(value = "规格型号") + private String specificationModel; + /**品牌型号*/ + @Excel(name = "品牌型号", width = 15) + @ApiModelProperty(value = "品牌型号") + private String brandType; + /**生产厂家*/ + @Excel(name = "生产厂家", width = 15) + @ApiModelProperty(value = "生产厂家") + private String manufacturer; + /**销售单价*/ + @ApiModelProperty(value = "销售单价") + private BigDecimal salesUnitPrice; + /**参考单价*/ + @ApiModelProperty(value = "参考单价") + private BigDecimal referenceUnitPrice; + /**货品单位*/ + @ApiModelProperty(value = "货品单位") + private String materialUnits; + /**多单位开关 0关 1开*/ + @ApiModelProperty(value = "多单位开关 0关 1开") + private String multiUnitSwitch; + /**父级单位*/ + @ApiModelProperty(value = "父级单位") + private String oneUnit; + /**父级单位兑换比例*/ + @ApiModelProperty(value = "父级单位兑换比例") + private Integer oneUnitProportion; + /**父级单位价格*/ + @ApiModelProperty(value = "父级单位价格") + private BigDecimal oneUnitPrice; + /**爷级单位*/ + @ApiModelProperty(value = "爷级单位") + private String twoUnit; + /**爷级单位兑换比例*/ + @ApiModelProperty(value = "爷级单位兑换比例") + private Integer twoUnitProportion; + /**爷级单位价格*/ + @ApiModelProperty(value = "爷级单位价格") + private BigDecimal twoUnitPrice; + /**多单位采购默认使用 0子集 1父级 2爷级*/ + @ApiModelProperty(value = "多单位采购默认使用 0子集 1父级 2爷级") + private String multiUnitType; + /**供应商*/ + @ApiModelProperty(value = "供应商") + @Dict(dictTable = "nu_config_suppliers_info" , dicCode = "id" , dicText = "suppliers_name") + private String suppliers; + /**物料图片*/ + @ApiModelProperty(value = "物料图片") + private String materialImg; + /**物料标识*/ + @ApiModelProperty(value = "物料标识") + private String materialIdent; + /**是否启用 Y启用 N未启用*/ + @Dict(dicCode = "iz_enabled") + @ApiModelProperty(value = "是否启用 Y启用 N未启用") + private String izEnabled; + /**是否删除 0未删除 1删除*/ + @ApiModelProperty(value = "是否删除 0未删除 1删除") + @TableLogic + private String delFlag; + /**创建人*/ + @ApiModelProperty(value = "创建人") + private String createBy; + /**创建日期*/ + @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss") + @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss") + @ApiModelProperty(value = "创建日期") + private Date createTime; + /**更新人*/ + @ApiModelProperty(value = "更新人") + private String updateBy; + /**更新日期*/ + @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss") + @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss") + @ApiModelProperty(value = "更新日期") + private Date updateTime; + /**所属部门*/ + @ApiModelProperty(value = "所属部门") + private String sysOrgCode; + /**拼音*/ + private String pinyin; + /**物料上限*/ + private String upperLimit; + /**物料下县*/ + private String lowerLimit; + /**物料标签*/ + @Dict(dicCode = "wl_tag_type") + private String tagType; + + /**是否医保报销 0否 1是*/ + @Dict(dicCode = "yn") + private String izYbbx; + /**是否机构优惠 0否 1是*/ + @Dict(dicCode = "yn") + private String izJgyh; + @TableField(exist = false) + private String izYbbxName; + @TableField(exist = false) + private String izJgyhName; + @TableField(exist = false) + private String izEnabledName; + + @TableField(exist = false) + private String treeId;//树id,用于查询 + + @TableField(exist = false) + private String kcsl;//库存数量 + + @TableField(exist = false) + private String checkId;//当前选择的物料id,主要用于物料分配的时候当前选择的物料 + + @TableField(exist = false) + private String paramWlxx;//选择物料的时候物料查询信息 + + @TableField(exist = false) + private String categoryName; + @TableField(exist = false) + private String typeName; + @TableField(exist = false) + private String medicationName; + @TableField(exist = false) + private String tagName; + + //综合搜索 + @TableField(exist = false) + private String keyWord; + @TableField(exist = false) + private String suppliersName; + + @TableField(exist = false) + private Integer wlNum;//累计入库物料数量 + @TableField(exist = false) + private Integer qlNum;//购物车请领数量 +} diff --git a/nursing-unit-invoicing/nu-invoicing-biz/src/main/java/com/nu/modules/ConfigMaterial/entity/ConfigMaterialTypeImportEntity.java b/nursing-unit-invoicing/nu-invoicing-biz/src/main/java/com/nu/modules/ConfigMaterial/entity/ConfigMaterialTypeImportEntity.java new file mode 100644 index 00000000..24d4fb55 --- /dev/null +++ b/nursing-unit-invoicing/nu-invoicing-biz/src/main/java/com/nu/modules/ConfigMaterial/entity/ConfigMaterialTypeImportEntity.java @@ -0,0 +1,149 @@ +package com.nu.modules.ConfigMaterial.entity; + +import com.baomidou.mybatisplus.annotation.*; +import com.fasterxml.jackson.annotation.JsonFormat; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.experimental.Accessors; +import org.jeecg.common.aspect.annotation.Dict; +import org.jeecgframework.poi.excel.annotation.Excel; +import org.springframework.format.annotation.DateTimeFormat; + +import java.io.Serializable; +import java.math.BigDecimal; +import java.util.Date; + +/** + * @Description: 物料信息 + * @Author: jeecg-boot + * @Date: 2025-03-13 + * @Version: V1.0 + */ +@Data +@TableName("nu_config_material_info") +@Accessors(chain = true) +@EqualsAndHashCode(callSuper = false) +@ApiModel(value="config_material_info对象", description="物料分类") +public class ConfigMaterialTypeImportEntity implements Serializable { + private static final long serialVersionUID = 1L; + + /**id*/ + @TableId(type = IdType.ASSIGN_ID) + @ApiModelProperty(value = "id") + private String id; + /**一级分类*/ + @Excel(name = "一级分类", width = 15) + @Dict(dictTable = "nu_config_material_category", dicText = "category_name", dicCode = "id") + @ApiModelProperty(value = "一级分类") + private String categoryId; + /**二级分类*/ + @Excel(name = "二级分类", width = 15) + @Dict(dictTable = "nu_config_material_type", dicText = "type_name", dicCode = "id") + @ApiModelProperty(value = "二级分类") + private String typeId; + /**三级分类*/ + @Excel(name = "三级分类", width = 15) + @Dict(dictTable = "nu_config_material_medication", dicText = "medication_name", dicCode = "id") + @ApiModelProperty(value = "三级分类") + private String medicationId; + /**货品名称*/ + @ApiModelProperty(value = "货品名称") + private String materialName; + /**货品编码*/ + @ApiModelProperty(value = "货品编码") + private String materialNo; + /**规格型号*/ + @ApiModelProperty(value = "规格型号") + private String specificationModel; + /**销售单价*/ + @ApiModelProperty(value = "销售单价") + private BigDecimal salesUnitPrice; + /**参考单价*/ + @ApiModelProperty(value = "参考单价") + private BigDecimal referenceUnitPrice; + /**货品单位*/ + @ApiModelProperty(value = "货品单位") + private String materialUnits; + /**多单位开关 0关 1开*/ + @ApiModelProperty(value = "多单位开关 0关 1开") + private String multiUnitSwitch; + /**父级单位*/ + @ApiModelProperty(value = "父级单位") + private String oneUnit; + /**父级单位兑换比例*/ + @ApiModelProperty(value = "父级单位兑换比例") + private Integer oneUnitProportion; + /**父级单位价格*/ + @ApiModelProperty(value = "父级单位价格") + private BigDecimal oneUnitPrice; + /**爷级单位*/ + @ApiModelProperty(value = "爷级单位") + private String twoUnit; + /**爷级单位兑换比例*/ + @ApiModelProperty(value = "爷级单位兑换比例") + private Integer twoUnitProportion; + /**爷级单位价格*/ + @ApiModelProperty(value = "爷级单位价格") + private BigDecimal twoUnitPrice; + /**多单位采购默认使用 0子集 1父级 2爷级*/ + @ApiModelProperty(value = "多单位采购默认使用 0子集 1父级 2爷级") + private String multiUnitType; + /**供应商*/ + @ApiModelProperty(value = "供应商") + @Dict(dictTable = "nu_config_suppliers_info" , dicCode = "id" , dicText = "suppliers_name") + private String suppliers; + /**物料图片*/ + @ApiModelProperty(value = "物料图片") + private String materialImg; + /**物料标识*/ + @ApiModelProperty(value = "物料标识") + private String materialIdent; + /**是否启用 Y启用 N未启用*/ + @Dict(dicCode = "iz_enabled") + @ApiModelProperty(value = "是否启用 Y启用 N未启用") + private String izEnabled; + /**是否删除 0未删除 1删除*/ + @ApiModelProperty(value = "是否删除 0未删除 1删除") + @TableLogic + private String delFlag; + /**创建人*/ + @ApiModelProperty(value = "创建人") + private String createBy; + /**创建日期*/ + @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss") + @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss") + @ApiModelProperty(value = "创建日期") + private Date createTime; + /**更新人*/ + @ApiModelProperty(value = "更新人") + private String updateBy; + /**更新日期*/ + @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss") + @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss") + @ApiModelProperty(value = "更新日期") + private Date updateTime; + /**所属部门*/ + @ApiModelProperty(value = "所属部门") + private String sysOrgCode; + /**拼音*/ + private String pinyin; + /**物料上限*/ + private String upperLimit; + /**物料下县*/ + private String lowerLimit; + /**物料标签*/ + @Dict(dicCode = "wl_tag_type") + private String tagType; + + private String brandType;//品牌 + private String manufacturer;//生产厂家 + + /**是否医保报销 0否 1是*/ + @Dict(dicCode = "yn") + private String izYbbx; + /**是否机构优惠 0否 1是*/ + @Dict(dicCode = "yn") + private String izJgyh; +} diff --git a/nursing-unit-invoicing/nu-invoicing-biz/src/main/java/com/nu/modules/ConfigMaterial/mapper/ConfigMaterialInfoMapper.java b/nursing-unit-invoicing/nu-invoicing-biz/src/main/java/com/nu/modules/ConfigMaterial/mapper/ConfigMaterialInfoMapper.java index 62974139..7a7579c3 100644 --- a/nursing-unit-invoicing/nu-invoicing-biz/src/main/java/com/nu/modules/ConfigMaterial/mapper/ConfigMaterialInfoMapper.java +++ b/nursing-unit-invoicing/nu-invoicing-biz/src/main/java/com/nu/modules/ConfigMaterial/mapper/ConfigMaterialInfoMapper.java @@ -40,4 +40,10 @@ public interface ConfigMaterialInfoMapper extends BaseMapper void updateOneTwoPrice(@Param("params") ConfigMaterialInfo configMaterialInfo); List queryByWlids(@Param("ids") List ids); + + List selectAllErType(); + + List selectAllSanType(); + + List selectAllData(); } diff --git a/nursing-unit-invoicing/nu-invoicing-biz/src/main/java/com/nu/modules/ConfigMaterial/mapper/xml/ConfigMaterialInfoMapper.xml b/nursing-unit-invoicing/nu-invoicing-biz/src/main/java/com/nu/modules/ConfigMaterial/mapper/xml/ConfigMaterialInfoMapper.xml index 2f87921d..5c69f570 100644 --- a/nursing-unit-invoicing/nu-invoicing-biz/src/main/java/com/nu/modules/ConfigMaterial/mapper/xml/ConfigMaterialInfoMapper.xml +++ b/nursing-unit-invoicing/nu-invoicing-biz/src/main/java/com/nu/modules/ConfigMaterial/mapper/xml/ConfigMaterialInfoMapper.xml @@ -140,4 +140,42 @@ + + + + + diff --git a/nursing-unit-invoicing/nu-invoicing-biz/src/main/java/com/nu/modules/ConfigMaterial/service/IConfigMaterialInfoService.java b/nursing-unit-invoicing/nu-invoicing-biz/src/main/java/com/nu/modules/ConfigMaterial/service/IConfigMaterialInfoService.java index c015a9b5..f8d72514 100644 --- a/nursing-unit-invoicing/nu-invoicing-biz/src/main/java/com/nu/modules/ConfigMaterial/service/IConfigMaterialInfoService.java +++ b/nursing-unit-invoicing/nu-invoicing-biz/src/main/java/com/nu/modules/ConfigMaterial/service/IConfigMaterialInfoService.java @@ -4,6 +4,11 @@ import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.IService; import com.nu.modules.ConfigMaterial.entity.ConfigMaterialInfo; +import org.apache.poi.ss.formula.functions.T; +import org.jeecg.common.api.vo.Result; +import org.springframework.web.servlet.ModelAndView; + +import javax.servlet.http.HttpServletRequest; /** * @Description: 物料信息 @@ -18,4 +23,12 @@ public interface IConfigMaterialInfoService extends IService IPage getConfiguredList(Page page, ConfigMaterialInfo configMaterialInfo); void updateOneTwoPrice(ConfigMaterialInfo configMaterialInfo); + + Result importMateriallInfo(HttpServletRequest request); + + Result importType(HttpServletRequest request); + + ModelAndView exportTypeExcel(); + + ModelAndView exportMateriallInfoExcel(); } diff --git a/nursing-unit-invoicing/nu-invoicing-biz/src/main/java/com/nu/modules/ConfigMaterial/service/impl/ConfigMaterialInfoServiceImpl.java b/nursing-unit-invoicing/nu-invoicing-biz/src/main/java/com/nu/modules/ConfigMaterial/service/impl/ConfigMaterialInfoServiceImpl.java index 813dca1a..62211960 100644 --- a/nursing-unit-invoicing/nu-invoicing-biz/src/main/java/com/nu/modules/ConfigMaterial/service/impl/ConfigMaterialInfoServiceImpl.java +++ b/nursing-unit-invoicing/nu-invoicing-biz/src/main/java/com/nu/modules/ConfigMaterial/service/impl/ConfigMaterialInfoServiceImpl.java @@ -1,42 +1,923 @@ package com.nu.modules.ConfigMaterial.service.impl; +import cn.hutool.core.util.IdUtil; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; -import com.nu.modules.ConfigMaterial.entity.ConfigMaterialInfo; -import com.nu.modules.ConfigMaterial.mapper.ConfigMaterialInfoMapper; -import com.nu.modules.ConfigMaterial.service.IConfigMaterialInfoService; -import org.apache.commons.lang.StringUtils; -import org.springframework.stereotype.Service; - import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.nu.modules.ConfigMaterial.entity.*; +import com.nu.modules.ConfigMaterial.mapper.ConfigMaterialInfoMapper; +import com.nu.modules.ConfigMaterial.service.IConfigMaterialCategoryService; +import com.nu.modules.ConfigMaterial.service.IConfigMaterialInfoService; +import com.nu.modules.ConfigMaterial.service.IConfigMaterialMedicationService; +import com.nu.modules.ConfigMaterial.service.IConfigMaterialTypeService; +import com.nu.modules.utils.PinyinUtils; +import org.apache.commons.lang.StringUtils; +import org.apache.poi.ss.formula.functions.T; +import org.apache.shiro.SecurityUtils; +import org.jeecg.common.api.vo.Result; +import org.jeecg.common.system.query.QueryGenerator; +import org.jeecg.common.system.vo.LoginUser; +import org.jeecg.common.util.oConvertUtils; +import org.jeecg.config.JeecgBaseConfig; +import org.jeecgframework.poi.excel.ExcelImportUtil; +import org.jeecgframework.poi.excel.def.NormalExcelConstants; +import org.jeecgframework.poi.excel.entity.ExportParams; +import org.jeecgframework.poi.excel.entity.ImportParams; +import org.jeecgframework.poi.excel.view.JeecgEntityExcelView; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.web.multipart.MultipartFile; +import org.springframework.web.multipart.MultipartHttpServletRequest; +import org.springframework.web.servlet.ModelAndView; + +import javax.annotation.Resource; +import javax.servlet.http.HttpServletRequest; +import java.io.IOException; +import java.util.*; /** * @Description: 物料信息 * @Author: jeecg-boot - * @Date: 2025-03-13 + * @Date: 2025-03-13 * @Version: V1.0 */ @Service public class ConfigMaterialInfoServiceImpl extends ServiceImpl implements IConfigMaterialInfoService { + @Autowired + private IConfigMaterialMedicationService medicationService; + @Autowired + private IConfigMaterialCategoryService categoryService; + @Autowired + private IConfigMaterialTypeService typeService; + @Resource + private JeecgBaseConfig jeecgBaseConfig; + @Override public void wlqianyi(ConfigMaterialInfo configMaterialInfo) { - if (StringUtils.isEmpty(configMaterialInfo.getTypeId())){ + if (StringUtils.isEmpty(configMaterialInfo.getTypeId())) { configMaterialInfo.setTypeId(""); } - if (StringUtils.isEmpty(configMaterialInfo.getMedicationId())){ - configMaterialInfo.setMedicationId( ""); + if (StringUtils.isEmpty(configMaterialInfo.getMedicationId())) { + configMaterialInfo.setMedicationId(""); } baseMapper.updateById(configMaterialInfo); } @Override public IPage getConfiguredList(Page page, ConfigMaterialInfo configMaterialInfo) { - return baseMapper.getConfiguredList(page,configMaterialInfo); + return baseMapper.getConfiguredList(page, configMaterialInfo); } @Override public void updateOneTwoPrice(ConfigMaterialInfo configMaterialInfo) { baseMapper.updateOneTwoPrice(configMaterialInfo); } + + /** + * 一级没有的话直接新增 + * 二级需要看 一级+二级组合是否存在 不存在才新增 + * 三级需要看 一级+二级+三级组合是否存在 不存在才新增 + * 物料:前三级+物料名称+物料编码+规格型号组合是否存在 不存在才新增 + * + * @param request + * @return + */ + @Override + public Result importMateriallInfo(HttpServletRequest request) { + // 查询现有的所有分类组合数据 + List currErTypes = baseMapper.selectAllErType(); + List currSanTypes = baseMapper.selectAllSanType(); + // 查询现有的所有物料信息 + List currWl = baseMapper.selectAllData(); + + // 查询现有的所有分类 + List yiHasList = categoryService.list(); + + // 构建缓存Map + Map existingCategoryMap = new HashMap<>(); + int maxCategorySort = 0; + for (ConfigMaterialCategory category : yiHasList) { + if (category.getCategoryName() != null) { + existingCategoryMap.put(category.getCategoryName(), category.getId()); + } + if (category.getSort() != null && category.getSort() > maxCategorySort) { + maxCategorySort = category.getSort(); + } + } + + // 二级分类:一级分类名称|二级分类名称 -> ID + Map existingTypeMap = new HashMap<>(); + for (ConfigMaterialInfo info : currErTypes) { + String categoryName = info.getCategoryName() != null ? info.getCategoryName() : ""; + if (info.getTypeName() != null && info.getTypeId() != null) { + String typeKey = categoryName + "|" + info.getTypeName(); + existingTypeMap.put(typeKey, info.getTypeId()); + } + } + + // 三级分类:一级分类名称|二级分类名称|三级分类名称 -> ID + Map existingMedicationMap = new HashMap<>(); + for (ConfigMaterialInfo info : currSanTypes) { + String categoryName = info.getCategoryName() != null ? info.getCategoryName() : ""; + String typeName = info.getTypeName() != null ? info.getTypeName() : ""; + if (info.getMedicationName() != null && info.getMedicationId() != null) { + String medicationKey = categoryName + "|" + typeName + "|" + info.getMedicationName(); + existingMedicationMap.put(medicationKey, info.getMedicationId()); + } + } + + // 构建物料缓存Map:一级分类名称|二级分类名称|三级分类名称|物料名称|物料编码|规格型号 -> 物料ID + Map existingMaterialMap = new HashMap<>(); + for (ConfigMaterialInfo material : currWl) { + if (material.getMaterialName() != null && material.getMaterialNo() != null && material.getSpecificationModel() != null) { + String categoryName = material.getCategoryName() != null ? material.getCategoryName() : ""; + String typeName = material.getTypeName() != null ? material.getTypeName() : ""; + String medicationName = material.getMedicationName() != null ? material.getMedicationName() : ""; + String materialKey = categoryName + "|" + typeName + "|" + medicationName + "|" + + material.getMaterialName() + "|" + material.getMaterialNo() + "|" + + material.getSpecificationModel(); + existingMaterialMap.put(materialKey, material.getId()); + } + } + + MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request; + Map fileMap = multipartRequest.getFileMap(); + + for (Map.Entry entity : fileMap.entrySet()) { + MultipartFile file = entity.getValue(); + if (file == null) { + break; + } + + ImportParams params = new ImportParams(); + params.setTitleRows(2); + params.setHeadRows(1); + params.setNeedSave(true); + + try { + List list = ExcelImportUtil.importExcel( + file.getInputStream(), ConfigMaterialInfoImportEntity.class, params); + + // 校验数据 + List errorMessages = new ArrayList<>(); + int rowNum = 4; + for (ConfigMaterialInfoImportEntity importEntity : list) { + String categoryName = importEntity.getCategoryId(); + String typeName = importEntity.getTypeId(); + String medicationName = importEntity.getMedicationId(); + String materialName = importEntity.getMaterialName(); + String materialNo = importEntity.getMaterialNo(); + String specificationModel = importEntity.getSpecificationModel(); + + String errorMsg = validateAllData(categoryName, typeName, medicationName, + materialName, materialNo, specificationModel, rowNum); + if (errorMsg != null) { + errorMessages.add(errorMsg); + } + rowNum++; + } + + if (!errorMessages.isEmpty()) { + return Result.error("文件导入失败,请检查以下数据:\n" + String.join("\n", errorMessages)); + } + + // 收集需要新增的数据 + Map newCategoryMap = new LinkedHashMap<>(); + Map newTypeMap = new LinkedHashMap<>(); + Map newMedicationMap = new LinkedHashMap<>(); + List newMaterialList = new ArrayList<>(); + + // 临时存储新增的一级分类ID + Map tempCategoryIdMap = new HashMap<>(); + + rowNum = 3; + for (ConfigMaterialInfoImportEntity importEntity : list) { + String categoryName = importEntity.getCategoryId(); + String typeName = importEntity.getTypeId(); + String medicationName = importEntity.getMedicationId(); + String materialName = importEntity.getMaterialName(); + String materialNo = importEntity.getMaterialNo(); + String specificationModel = importEntity.getSpecificationModel(); + String brandType = importEntity.getBrandType(); + String manufacturer = importEntity.getManufacturer(); + + // 处理空值 + if (brandType == null || brandType.trim().isEmpty()) { + brandType = "无"; + } + if (manufacturer == null) { + manufacturer = ""; + } + + String categoryId = null; + String typeId = null; + String medicationId = null; + + // 处理空值 + String safeCategoryName = categoryName != null ? categoryName : ""; + String safeTypeName = typeName != null ? typeName : ""; + String safeMedicationName = medicationName != null ? medicationName : ""; + + // 1. 处理一级分类(完全复制importType的逻辑) + if (categoryName != null && !categoryName.trim().isEmpty()) { + if (existingCategoryMap.containsKey(categoryName)) { + categoryId = existingCategoryMap.get(categoryName); + } else if (tempCategoryIdMap.containsKey(categoryName)) { + categoryId = tempCategoryIdMap.get(categoryName); + } else { + ConfigMaterialCategory newCategory = new ConfigMaterialCategory(); + newCategory.setId(IdUtil.simpleUUID()); + newCategory.setCategoryName(categoryName); + newCategory.setIzEnabled("Y"); + newCategory.setCreateTime(new Date()); + newCategory.setSort(++maxCategorySort); + newCategoryMap.put(categoryName, newCategory); + categoryId = newCategory.getId(); + tempCategoryIdMap.put(categoryName, categoryId); + } + } + + // 2. 处理二级分类(完全复制importType的逻辑) + if (typeName != null && !typeName.trim().isEmpty() && categoryId != null) { + String typeKey = safeCategoryName + "|" + safeTypeName; + if (existingTypeMap.containsKey(typeKey)) { + typeId = existingTypeMap.get(typeKey); + } else { + // 检查是否已经在本次新增中 + boolean found = false; + for (ConfigMaterialType newType : newTypeMap.values()) { + String newTypeCategoryName = ""; + for (Map.Entry entry : tempCategoryIdMap.entrySet()) { + if (entry.getValue().equals(newType.getCategoryId())) { + newTypeCategoryName = entry.getKey(); + break; + } + } + String newTypeKey = newTypeCategoryName + "|" + newType.getTypeName(); + if (newTypeKey.equals(typeKey)) { + typeId = newType.getId(); + found = true; + break; + } + } + if (!found) { + ConfigMaterialType newType = new ConfigMaterialType(); + newType.setId(IdUtil.simpleUUID()); + newType.setCategoryId(categoryId); + newType.setTypeName(typeName); + newType.setIzEnabled("Y"); + newType.setCreateTime(new Date()); + newTypeMap.put(typeKey, newType); + typeId = newType.getId(); + } + } + } + + // 3. 处理三级分类(完全复制importType的逻辑) + if (medicationName != null && !medicationName.trim().isEmpty() && categoryId != null && typeId != null) { + String medicationKey = safeCategoryName + "|" + safeTypeName + "|" + safeMedicationName; + if (!existingMedicationMap.containsKey(medicationKey)) { + // 检查是否已经在本次新增中 + boolean found = false; + for (ConfigMaterialMedication newMedication : newMedicationMap.values()) { + String newMedicationCategoryName = ""; + String newMedicationTypeName = ""; + + for (Map.Entry entry : tempCategoryIdMap.entrySet()) { + if (entry.getValue().equals(newMedication.getCategoryId())) { + newMedicationCategoryName = entry.getKey(); + break; + } + } + + for (ConfigMaterialType newType : newTypeMap.values()) { + if (newType.getId().equals(newMedication.getTypeId())) { + newMedicationTypeName = newType.getTypeName(); + break; + } + } + + String newKey = newMedicationCategoryName + "|" + newMedicationTypeName + "|" + newMedication.getMedicationName(); + if (newKey.equals(medicationKey)) { + medicationId = newMedication.getId(); + found = true; + break; + } + } + if (!found) { + ConfigMaterialMedication newMedication = new ConfigMaterialMedication(); + newMedication.setId(IdUtil.simpleUUID()); + newMedication.setCategoryId(categoryId); + newMedication.setTypeId(typeId); + newMedication.setMedicationName(medicationName); + newMedication.setIzEnabled("Y"); + newMedication.setCreateTime(new Date()); + newMedicationMap.put(medicationKey, newMedication); + medicationId = newMedication.getId(); + } + } else { + medicationId = existingMedicationMap.get(medicationKey); + } + } + + // 4. 处理物料信息(新增的部分) + String materialKey = safeCategoryName + "|" + safeTypeName + "|" + safeMedicationName + "|" + + materialName + "|" + materialNo + "|" + specificationModel; + + if (!existingMaterialMap.containsKey(materialKey)) { + // 检查是否已经在本次新增中 + boolean materialExists = false; + for (ConfigMaterialInfo newMaterial : newMaterialList) { + String newMaterialKey = (newMaterial.getCategoryName() != null ? newMaterial.getCategoryName() : "") + "|" + + (newMaterial.getTypeName() != null ? newMaterial.getTypeName() : "") + "|" + + (newMaterial.getMedicationName() != null ? newMaterial.getMedicationName() : "") + "|" + + newMaterial.getMaterialName() + "|" + newMaterial.getMaterialNo() + "|" + + newMaterial.getSpecificationModel(); + if (newMaterialKey.equals(materialKey)) { + materialExists = true; + break; + } + } + + if (!materialExists) { + ConfigMaterialInfo newMaterial = new ConfigMaterialInfo(); + newMaterial.setId(IdUtil.simpleUUID()); + newMaterial.setCategoryId(categoryId); + newMaterial.setTypeId(typeId); + newMaterial.setMedicationId(medicationId); + newMaterial.setCategoryName(categoryName); + newMaterial.setTypeName(typeName); + newMaterial.setMedicationName(medicationName); + newMaterial.setMaterialName(materialName); + newMaterial.setPinyin(PinyinUtils.getFirstLetter(materialName)); + newMaterial.setMaterialNo(materialNo); + newMaterial.setSpecificationModel(specificationModel); + newMaterial.setBrandType(brandType); + newMaterial.setManufacturer(manufacturer); + newMaterial.setIzEnabled("Y"); + newMaterial.setDelFlag("0"); + newMaterial.setCreateTime(new Date()); + newMaterialList.add(newMaterial); + } + } + + rowNum++; + } + + // 批量保存一级分类(完全复制importType的逻辑) + if (!newCategoryMap.isEmpty()) { + List categoryList = new ArrayList<>(newCategoryMap.values()); + categoryService.saveBatch(categoryList); + for (ConfigMaterialCategory category : categoryList) { + existingCategoryMap.put(category.getCategoryName(), category.getId()); + tempCategoryIdMap.put(category.getCategoryName(), category.getId()); + } + } + + // 批量保存二级分类(完全复制importType的逻辑) + if (!newTypeMap.isEmpty()) { + List typeList = new ArrayList<>(newTypeMap.values()); + for (ConfigMaterialType type : typeList) { + String oldCategoryId = type.getCategoryId(); + if (tempCategoryIdMap.containsValue(oldCategoryId)) { + for (Map.Entry entry : tempCategoryIdMap.entrySet()) { + if (entry.getValue().equals(oldCategoryId)) { + type.setCategoryId(entry.getValue()); + break; + } + } + } + } + typeService.saveBatch(typeList); + for (ConfigMaterialType type : typeList) { + String categoryName = null; + for (Map.Entry entry : tempCategoryIdMap.entrySet()) { + if (entry.getValue().equals(type.getCategoryId())) { + categoryName = entry.getKey(); + break; + } + } + if (categoryName != null) { + String typeKey = categoryName + "|" + type.getTypeName(); + existingTypeMap.put(typeKey, type.getId()); + } + } + } + + // 批量保存三级分类(完全复制importType的逻辑) + if (!newMedicationMap.isEmpty()) { + List medicationList = new ArrayList<>(newMedicationMap.values()); + for (ConfigMaterialMedication medication : medicationList) { + String oldCategoryId = medication.getCategoryId(); + if (tempCategoryIdMap.containsValue(oldCategoryId)) { + for (Map.Entry entry : tempCategoryIdMap.entrySet()) { + if (entry.getValue().equals(oldCategoryId)) { + medication.setCategoryId(entry.getValue()); + break; + } + } + } + String oldTypeId = medication.getTypeId(); + for (ConfigMaterialType type : newTypeMap.values()) { + if (type.getId().equals(oldTypeId)) { + medication.setTypeId(type.getId()); + break; + } + } + } + medicationService.saveBatch(medicationList); + } + + // 批量保存物料信息 + int savedMaterialCount = 0; + if (!newMaterialList.isEmpty()) { + // 更新物料中的分类ID为真实ID + for (ConfigMaterialInfo material : newMaterialList) { + // 更新categoryId + String oldCategoryId = material.getCategoryId(); + if (oldCategoryId != null && tempCategoryIdMap.containsValue(oldCategoryId)) { + for (Map.Entry entry : tempCategoryIdMap.entrySet()) { + if (entry.getValue().equals(oldCategoryId)) { + material.setCategoryId(entry.getValue()); + break; + } + } + } + // 更新typeId + String oldTypeId = material.getTypeId(); + if (oldTypeId != null) { + for (ConfigMaterialType type : newTypeMap.values()) { + if (type.getId().equals(oldTypeId)) { + material.setTypeId(type.getId()); + break; + } + } + // 如果在新类型中没找到,尝试在现有类型中查找 + if (material.getTypeId() == null) { + for (Map.Entry entry : existingTypeMap.entrySet()) { + if (entry.getValue().equals(oldTypeId)) { + material.setTypeId(entry.getValue()); + break; + } + } + } + } + // 更新medicationId + String oldMedicationId = material.getMedicationId(); + if (oldMedicationId != null) { + for (ConfigMaterialMedication medication : newMedicationMap.values()) { + if (medication.getId().equals(oldMedicationId)) { + material.setMedicationId(medication.getId()); + break; + } + } + // 如果在新三级分类中没找到,尝试在现有三级分类中查找 + if (material.getMedicationId() == null) { + for (Map.Entry entry : existingMedicationMap.entrySet()) { + if (entry.getValue().equals(oldMedicationId)) { + material.setMedicationId(entry.getValue()); + break; + } + } + } + } + } + saveBatch(newMaterialList); + savedMaterialCount = newMaterialList.size(); + } + + String resultMsg = String.format("文件导入成功!新增一级分类:%d个,新增二级分类:%d个,新增三级分类:%d个,新增物料:%d个", + newCategoryMap.size(), newTypeMap.size(), newMedicationMap.size(), savedMaterialCount); + return Result.ok(resultMsg); + + } catch (Exception e) { + String msg = e.getMessage(); + log.error(msg, e); + if (msg != null && msg.indexOf("Duplicate entry") >= 0) { + return Result.error("文件导入失败:有重复数据!"); + } else { + return Result.error("文件导入失败:" + e.getMessage()); + } + } finally { + try { + file.getInputStream().close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + return Result.error("文件导入失败!"); + } + + /** + * 校验所有数据,包括分类和物料信息 + */ + private String validateAllData(String categoryName, String typeName, String medicationName, + String materialName, String materialNo, String specificationModel, int rowNum) { + boolean hasCategory = categoryName != null && !categoryName.trim().isEmpty(); + boolean hasType = typeName != null && !typeName.trim().isEmpty(); + boolean hasMedication = medicationName != null && !medicationName.trim().isEmpty(); + boolean hasMaterialName = materialName != null && !materialName.trim().isEmpty(); + boolean hasMaterialNo = materialNo != null && !materialNo.trim().isEmpty(); + boolean hasSpecificationModel = specificationModel != null && !specificationModel.trim().isEmpty(); + + // 必须有一级分类 + if (!hasCategory) { + return String.format("第%d行:缺少一级分类", rowNum); + } + + // 必须有二级分类 + if (!hasType) { + return String.format("第%d行:缺少二级分类", rowNum); + } + + // 必须有三级分类 + if (!hasMedication) { + return String.format("第%d行:缺少三级分类", rowNum); + } + + // 物料名称必须有值 + if (!hasMaterialName) { + return String.format("第%d行:缺少物料名称", rowNum); + } + + // 物料编码必须有值 + if (!hasMaterialNo) { + return String.format("第%d行:缺少物料编码", rowNum); + } + + // 规格型号必须有值 + if (!hasSpecificationModel) { + return String.format("第%d行:缺少规格型号", rowNum); + } + + return null; + } + + + /** + * 一级没有的话直接新增 + * 二级需要看 一级+二级组合是否存在 才新增 + * 三级需要看 一级+二级+三级组合是否存在 才新增 + * + * @param request + * @return + */ + @Override + public Result importType(HttpServletRequest request) { + // 查询现有的所有分类组合数据 + List currErTypes = baseMapper.selectAllErType(); + List currSanTypes = baseMapper.selectAllSanType(); + + // 查询现有的所有分类 + List yiHasList = categoryService.list(); + + // 构建缓存Map + Map existingCategoryMap = new HashMap<>(); + int maxCategorySort = 0; + for (ConfigMaterialCategory category : yiHasList) { + if (category.getCategoryName() != null) { + existingCategoryMap.put(category.getCategoryName(), category.getId()); + } + if (category.getSort() != null && category.getSort() > maxCategorySort) { + maxCategorySort = category.getSort(); + } + } + + // 二级分类:一级分类名称|二级分类名称 -> ID + Map existingTypeMap = new HashMap<>(); + for (ConfigMaterialInfo info : currErTypes) { + String categoryName = info.getCategoryName() != null ? info.getCategoryName() : ""; + if (info.getTypeName() != null && info.getTypeId() != null) { + String typeKey = categoryName + "|" + info.getTypeName(); + existingTypeMap.put(typeKey, info.getTypeId()); + } + } + + // 三级分类:一级分类名称|二级分类名称|三级分类名称 -> ID + Map existingMedicationMap = new HashMap<>(); + for (ConfigMaterialInfo info : currSanTypes) { + String categoryName = info.getCategoryName() != null ? info.getCategoryName() : ""; + String typeName = info.getTypeName() != null ? info.getTypeName() : ""; + if (info.getMedicationName() != null && info.getMedicationId() != null) { + String medicationKey = categoryName + "|" + typeName + "|" + info.getMedicationName(); + existingMedicationMap.put(medicationKey, info.getMedicationId()); + } + } + + MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request; + Map fileMap = multipartRequest.getFileMap(); + + for (Map.Entry entity : fileMap.entrySet()) { + MultipartFile file = entity.getValue(); + if (file == null) { + break; + } + + ImportParams params = new ImportParams(); + params.setTitleRows(2); + params.setHeadRows(1); + params.setNeedSave(true); + + try { + List list = ExcelImportUtil.importExcel( + file.getInputStream(), ConfigMaterialTypeImportEntity.class, params); + + // 校验数据 + List errorMessages = new ArrayList<>(); + int rowNum = 4; + for (ConfigMaterialTypeImportEntity importEntity : list) { + String categoryName = importEntity.getCategoryId(); + String typeName = importEntity.getTypeId(); + String medicationName = importEntity.getMedicationId(); + + String errorMsg = validateCategoryLevel(categoryName, typeName, medicationName, rowNum); + if (errorMsg != null) { + errorMessages.add(errorMsg); + } + rowNum++; + } + + if (!errorMessages.isEmpty()) { + return Result.error("文件导入失败,请检查以下数据:\n" + String.join("\n", errorMessages)); + } + + // 收集需要新增的数据 + Map newCategoryMap = new LinkedHashMap<>(); + Map newTypeMap = new LinkedHashMap<>(); + Map newMedicationMap = new LinkedHashMap<>(); + + // 临时存储新增的一级分类ID + Map tempCategoryIdMap = new HashMap<>(); + + rowNum = 3; + for (ConfigMaterialTypeImportEntity importEntity : list) { + String categoryName = importEntity.getCategoryId(); + String typeName = importEntity.getTypeId(); + String medicationName = importEntity.getMedicationId(); + + String categoryId = null; + String typeId = null; + + // 处理空值 + String safeCategoryName = categoryName != null ? categoryName : ""; + String safeTypeName = typeName != null ? typeName : ""; + + // 1. 处理一级分类 + if (categoryName != null && !categoryName.trim().isEmpty()) { + if (existingCategoryMap.containsKey(categoryName)) { + categoryId = existingCategoryMap.get(categoryName); + } else if (tempCategoryIdMap.containsKey(categoryName)) { + categoryId = tempCategoryIdMap.get(categoryName); + } else { + ConfigMaterialCategory newCategory = new ConfigMaterialCategory(); + newCategory.setId(IdUtil.simpleUUID()); + newCategory.setCategoryName(categoryName); + newCategory.setIzEnabled("Y"); + newCategory.setCreateTime(new Date()); + newCategory.setSort(++maxCategorySort); + newCategoryMap.put(categoryName, newCategory); + categoryId = newCategory.getId(); + tempCategoryIdMap.put(categoryName, categoryId); + } + } + + // 2. 处理二级分类(按一级分类名称+二级分类名称组合判断) + if (typeName != null && !typeName.trim().isEmpty() && categoryId != null) { + String typeKey = safeCategoryName + "|" + safeTypeName; + if (existingTypeMap.containsKey(typeKey)) { + typeId = existingTypeMap.get(typeKey); + } else { + // 检查是否已经在本次新增中 + boolean found = false; + for (ConfigMaterialType newType : newTypeMap.values()) { + // 获取新类型的分类名称 + String newTypeCategoryName = ""; + for (Map.Entry entry : tempCategoryIdMap.entrySet()) { + if (entry.getValue().equals(newType.getCategoryId())) { + newTypeCategoryName = entry.getKey(); + break; + } + } + String newTypeKey = newTypeCategoryName + "|" + newType.getTypeName(); + if (newTypeKey.equals(typeKey)) { + typeId = newType.getId(); + found = true; + break; + } + } + if (!found) { + ConfigMaterialType newType = new ConfigMaterialType(); + newType.setId(IdUtil.simpleUUID()); + newType.setCategoryId(categoryId); + newType.setTypeName(typeName); + newType.setIzEnabled("Y"); + newType.setCreateTime(new Date()); + newTypeMap.put(typeKey, newType); + typeId = newType.getId(); + } + } + } + + // 3. 处理三级分类(按一级分类名称+二级分类名称+三级分类名称组合判断) + if (medicationName != null && !medicationName.trim().isEmpty() && categoryId != null && typeId != null) { + String medicationKey = safeCategoryName + "|" + safeTypeName + "|" + medicationName; + if (!existingMedicationMap.containsKey(medicationKey)) { + // 检查是否已经在本次新增中 + boolean found = false; + for (ConfigMaterialMedication newMedication : newMedicationMap.values()) { + // 获取新三级分类的分类名称和类型名称 + String newMedicationCategoryName = ""; + String newMedicationTypeName = ""; + + for (Map.Entry entry : tempCategoryIdMap.entrySet()) { + if (entry.getValue().equals(newMedication.getCategoryId())) { + newMedicationCategoryName = entry.getKey(); + break; + } + } + + for (ConfigMaterialType newType : newTypeMap.values()) { + if (newType.getId().equals(newMedication.getTypeId())) { + newMedicationTypeName = newType.getTypeName(); + break; + } + } + + String newKey = newMedicationCategoryName + "|" + newMedicationTypeName + "|" + newMedication.getMedicationName(); + if (newKey.equals(medicationKey)) { + found = true; + break; + } + } + if (!found) { + ConfigMaterialMedication newMedication = new ConfigMaterialMedication(); + newMedication.setId(IdUtil.simpleUUID()); + newMedication.setCategoryId(categoryId); + newMedication.setTypeId(typeId); + newMedication.setMedicationName(medicationName); + newMedication.setIzEnabled("Y"); + newMedication.setCreateTime(new Date()); + newMedicationMap.put(medicationKey, newMedication); + } + } + } + + rowNum++; + } + + // 批量保存一级分类 + if (!newCategoryMap.isEmpty()) { + List categoryList = new ArrayList<>(newCategoryMap.values()); + categoryService.saveBatch(categoryList); + for (ConfigMaterialCategory category : categoryList) { + existingCategoryMap.put(category.getCategoryName(), category.getId()); + tempCategoryIdMap.put(category.getCategoryName(), category.getId()); + } + } + + // 批量保存二级分类 + if (!newTypeMap.isEmpty()) { + List typeList = new ArrayList<>(newTypeMap.values()); + // 更新categoryId为真实ID + for (ConfigMaterialType type : typeList) { + String oldCategoryId = type.getCategoryId(); + if (tempCategoryIdMap.containsValue(oldCategoryId)) { + for (Map.Entry entry : tempCategoryIdMap.entrySet()) { + if (entry.getValue().equals(oldCategoryId)) { + type.setCategoryId(entry.getValue()); + break; + } + } + } + } + typeService.saveBatch(typeList); + // 更新缓存 + for (ConfigMaterialType type : typeList) { + String categoryName = null; + for (Map.Entry entry : tempCategoryIdMap.entrySet()) { + if (entry.getValue().equals(type.getCategoryId())) { + categoryName = entry.getKey(); + break; + } + } + if (categoryName != null) { + String typeKey = categoryName + "|" + type.getTypeName(); + existingTypeMap.put(typeKey, type.getId()); + } + } + } + + // 批量保存三级分类 + if (!newMedicationMap.isEmpty()) { + List medicationList = new ArrayList<>(newMedicationMap.values()); + // 更新categoryId和typeId为真实ID + for (ConfigMaterialMedication medication : medicationList) { + // 更新categoryId + String oldCategoryId = medication.getCategoryId(); + if (tempCategoryIdMap.containsValue(oldCategoryId)) { + for (Map.Entry entry : tempCategoryIdMap.entrySet()) { + if (entry.getValue().equals(oldCategoryId)) { + medication.setCategoryId(entry.getValue()); + break; + } + } + } + // 更新typeId + String oldTypeId = medication.getTypeId(); + for (ConfigMaterialType type : newTypeMap.values()) { + if (type.getId().equals(oldTypeId)) { + medication.setTypeId(type.getId()); + break; + } + } + } + medicationService.saveBatch(medicationList); + } + + String resultMsg = String.format("文件导入成功!新增一级分类:%d个,新增二级分类:%d个,新增三级分类:%d个", + newCategoryMap.size(), newTypeMap.size(), newMedicationMap.size()); + return Result.ok(resultMsg); + + } catch (Exception e) { + String msg = e.getMessage(); + log.error(msg, e); + if (msg != null && msg.indexOf("Duplicate entry") >= 0) { + return Result.error("文件导入失败:有重复数据!"); + } else { + return Result.error("文件导入失败:" + e.getMessage()); + } + } finally { + try { + file.getInputStream().close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + return Result.error("文件导入失败!"); + } + + @Override + public ModelAndView exportTypeExcel() { + String title = "物料分类导入模板"; + LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal(); + List exportList = List.of(); + + // Step.3 AutoPoi 导出Excel + ModelAndView mv = new ModelAndView(new JeecgEntityExcelView()); + //此处设置的filename无效 ,前端会重更新设置一下 + mv.addObject(NormalExcelConstants.FILE_NAME, title); + mv.addObject(NormalExcelConstants.CLASS, ConfigMaterialTypeImportEntity.class); + //update-begin--Author:liusq Date:20210126 for:图片导出报错,ImageBasePath未设置-------------------- + ExportParams exportParams = new ExportParams(title, "下载人:" + sysUser.getRealname(), title); + exportParams.setImageBasePath(jeecgBaseConfig.getPath().getUpload()); + //update-end--Author:liusq Date:20210126 for:图片导出报错,ImageBasePath未设置---------------------- + mv.addObject(NormalExcelConstants.PARAMS, exportParams); + mv.addObject(NormalExcelConstants.DATA_LIST, exportList); + return mv; + } + + @Override + public ModelAndView exportMateriallInfoExcel() { + String title = "物料信息导入模板"; + LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal(); + List exportList = List.of(); + + // Step.3 AutoPoi 导出Excel + ModelAndView mv = new ModelAndView(new JeecgEntityExcelView()); + //此处设置的filename无效 ,前端会重更新设置一下 + mv.addObject(NormalExcelConstants.FILE_NAME, title); + mv.addObject(NormalExcelConstants.CLASS, ConfigMaterialInfoImportEntity.class); + //update-begin--Author:liusq Date:20210126 for:图片导出报错,ImageBasePath未设置-------------------- + ExportParams exportParams = new ExportParams(title, "下载人:" + sysUser.getRealname(), title); + exportParams.setImageBasePath(jeecgBaseConfig.getPath().getUpload()); + //update-end--Author:liusq Date:20210126 for:图片导出报错,ImageBasePath未设置---------------------- + mv.addObject(NormalExcelConstants.PARAMS, exportParams); + mv.addObject(NormalExcelConstants.DATA_LIST, exportList); + return mv; + } + + /** + * 校验分类层级关系,返回错误信息,如果没有错误返回null + */ + private String validateCategoryLevel(String categoryName, String typeName, String medicationName, int rowNum) { + boolean hasCategory = categoryName != null && !categoryName.trim().isEmpty(); + boolean hasType = typeName != null && !typeName.trim().isEmpty(); + boolean hasMedication = medicationName != null && !medicationName.trim().isEmpty(); + + // 必须有一级分类 + if (!hasCategory) { + return String.format("第%d行:缺少一级分类", rowNum); + } + + // 有三级分类但缺少二级分类 + if (hasMedication && !hasType) { + return String.format("第%d行:缺少二级分类", rowNum); + } + + return null; + } }