|
|
@@ -2,14 +2,21 @@ package cn.iocoder.yudao.module.iscs.service.materials;
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
import cn.hutool.core.lang.Assert;
|
|
|
+import cn.iocoder.yudao.framework.common.exception.ServiceException;
|
|
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
|
|
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
|
|
import cn.iocoder.yudao.module.iscs.controller.admin.materials.vo.*;
|
|
|
import cn.iocoder.yudao.module.iscs.dal.dataobject.exceptionmisplace.ExceptionMisplaceDO;
|
|
|
import cn.iocoder.yudao.module.iscs.dal.dataobject.materials.MaterialsDO;
|
|
|
+import cn.iocoder.yudao.module.iscs.dal.dataobject.materialscabinet.MaterialsCabinetDO;
|
|
|
+import cn.iocoder.yudao.module.iscs.dal.dataobject.materialsproperty.MaterialsPropertyDO;
|
|
|
+import cn.iocoder.yudao.module.iscs.dal.dataobject.materialspropertyvalue.MaterialsPropertyValueDO;
|
|
|
import cn.iocoder.yudao.module.iscs.dal.dataobject.materialstype.MaterialsTypeDO;
|
|
|
import cn.iocoder.yudao.module.iscs.dal.mysql.materials.MaterialsMapper;
|
|
|
import cn.iocoder.yudao.module.iscs.service.exceptionmisplace.ExceptionMisplaceService;
|
|
|
+import cn.iocoder.yudao.module.iscs.service.materialscabinet.MaterialsCabinetService;
|
|
|
+import cn.iocoder.yudao.module.iscs.service.materialsproperty.MaterialsPropertyService;
|
|
|
+import cn.iocoder.yudao.module.iscs.service.materialspropertyvalue.MaterialsPropertyValueService;
|
|
|
import cn.iocoder.yudao.module.iscs.service.materialstype.MaterialsTypeService;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
@@ -44,6 +51,14 @@ public class MaterialsServiceImpl extends ServiceImpl<MaterialsMapper, Materials
|
|
|
private MaterialsTypeService materialsTypeService;
|
|
|
@Autowired
|
|
|
private ExceptionMisplaceService exceptionMisplaceService;
|
|
|
+ @Lazy
|
|
|
+ @Autowired
|
|
|
+ private MaterialsCabinetService materialsCabinetService;
|
|
|
+ @Autowired
|
|
|
+ private MaterialsPropertyValueService materialsPropertyValueService;
|
|
|
+ @Autowired
|
|
|
+ private MaterialsPropertyService materialsPropertyService;
|
|
|
+
|
|
|
|
|
|
@Override
|
|
|
public Long createMaterials(MaterialsSaveReqVO createReqVO) {
|
|
|
@@ -186,4 +201,105 @@ public class MaterialsServiceImpl extends ServiceImpl<MaterialsMapper, Materials
|
|
|
return materialsPageVOS;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public String importMaterials(List<ImportMaterialsVO> itemList) throws JsonProcessingException {
|
|
|
+ Assert.notNull(itemList, "导入物资数据不能为空!");
|
|
|
+ int successNum = 0;
|
|
|
+ int failureNum = 0;
|
|
|
+ StringBuilder successMsg = new StringBuilder();
|
|
|
+ StringBuilder failureMsg = new StringBuilder();
|
|
|
+ for (ImportMaterialsVO materials : itemList) {
|
|
|
+ // 0.检测第一行示例数据有没有被删除
|
|
|
+ if ("测试白大褂(测试示例行可删除)".equals(materials.getMaterialsTypeName()) || "测试实验室(测试示例行可删除)".equals(materials.getSupplier())) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ // 1.定义一个boolean,记录当前这条数据有没有问题
|
|
|
+ boolean result = true;
|
|
|
+ // 1.1定义一个物资类型id
|
|
|
+ Long materialsTypeId = null;
|
|
|
+
|
|
|
+ // 2.-----------------检查物资名称不能为空-------------------------------
|
|
|
+ if (StringUtils.isBlank(materials.getMaterialsName())) {
|
|
|
+ result = false;
|
|
|
+ failureMsg.append("<br/>" + failureNum + "、物资名称 :" + materials.getMaterialsName() + " 不能为空");
|
|
|
+ }
|
|
|
+ // 3.-----------------检查物资类型不能为空-------------------------------
|
|
|
+ if (StringUtils.isNotBlank(materials.getMaterialsTypeName())) {
|
|
|
+ // 3.1检查物资类型是否在我们的系统中
|
|
|
+ List<MaterialsTypeDO> materialsTypelist = materialsTypeService.list(Wrappers.<MaterialsTypeDO>lambdaQuery()
|
|
|
+ .eq(MaterialsTypeDO::getMaterialsTypeName, materials.getMaterialsTypeName()));
|
|
|
+ if (materialsTypelist.isEmpty()) {
|
|
|
+ result = false;
|
|
|
+ failureMsg.append("<br/>" + failureNum + "、物资分类 :" + materials.getMaterialsTypeName() + " 系统中无该物资类型");
|
|
|
+ } else {
|
|
|
+ materialsTypeId = materialsTypelist.get(0).getId();
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ result = false;
|
|
|
+ failureMsg.append("<br/>" + failureNum + "、物资分类 :" + materials.getMaterialsName() + " 的物资分类不能为空");
|
|
|
+ }
|
|
|
+ // 4.---------------------检查rfid是否填写------------------------------
|
|
|
+ if (StringUtils.isNotBlank(materials.getMaterialsRfid())) {
|
|
|
+ // 4.1检查rfid是否被使用
|
|
|
+ List<MaterialsDO> materialslist = list(Wrappers.<MaterialsDO>lambdaQuery()
|
|
|
+ .eq(MaterialsDO::getMaterialsRfid, materials.getMaterialsRfid()));
|
|
|
+ if (!materialslist.isEmpty()) {
|
|
|
+ result = false;
|
|
|
+ failureMsg.append("<br/>" + failureNum + "、物资RFID :" + materials.getMaterialsRfid() + " 已被使用");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ result = false;
|
|
|
+ failureMsg.append("<br/>" + failureNum + "、物资RFID :" + materials.getMaterialsName() + " 的RFID不能为空");
|
|
|
+ }
|
|
|
+ // 5.---------------------检查物资柜信息------------------------------
|
|
|
+ if (StringUtils.isNotBlank(materials.getCabinetName())) {
|
|
|
+ List<MaterialsCabinetDO> cabinets = materialsCabinetService.list(Wrappers.<MaterialsCabinetDO>lambdaQuery()
|
|
|
+ .eq(MaterialsCabinetDO::getCabinetName, materials.getCabinetName()));
|
|
|
+ if (!cabinets.isEmpty()) {
|
|
|
+ materials.setMaterialsCabinetId(cabinets.get(0).getId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 6.---------------------检查物资规格------------------------------
|
|
|
+ if (StringUtils.isNotBlank(materials.getValueName())) {
|
|
|
+ List<MaterialsPropertyValueDO> propertyValueList = materialsPropertyValueService.list(Wrappers.<MaterialsPropertyValueDO>lambdaQuery()
|
|
|
+ .eq(MaterialsPropertyValueDO::getValueName, materials.getValueName()));
|
|
|
+ if (!propertyValueList.isEmpty()) {
|
|
|
+ MaterialsPropertyDO property = materialsPropertyService.getById(propertyValueList.get(0).getPropertyId());
|
|
|
+ PropertyVO propertyVO = new PropertyVO();
|
|
|
+ propertyVO.setPropertyId(String.valueOf(property.getId()));
|
|
|
+ propertyVO.setPropertyName(property.getPropertyName());
|
|
|
+ propertyVO.setRecordId(String.valueOf(propertyValueList.get(0).getId()));
|
|
|
+ propertyVO.setValueName(propertyValueList.get(0).getValueName());
|
|
|
+ // 使用 ObjectMapper 将对象转换为 JSON 字符串
|
|
|
+ ObjectMapper objectMapper = new ObjectMapper();
|
|
|
+ String jsonString = objectMapper.writeValueAsString(propertyVO);
|
|
|
+ materials.setProperties("[" + jsonString + "]");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 开始做最后的插入操作
|
|
|
+ if (result) {
|
|
|
+ successNum++;
|
|
|
+ MaterialsDO bean = BeanUtils.toBean(materials, MaterialsDO.class);
|
|
|
+ bean.setMaterialsTypeId(materialsTypeId);
|
|
|
+ createMaterials(BeanUtils.toBean(bean, MaterialsSaveReqVO.class));
|
|
|
+ } else {
|
|
|
+ failureNum++;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ // 总结
|
|
|
+ if (failureNum > 0) {
|
|
|
+ failureMsg.insert(0, "导入失败!共 " + failureNum + " 条数据格式不正确,错误如下:");
|
|
|
+ throw new ServiceException(failureMsg.toString());
|
|
|
+ } else {
|
|
|
+ if (successNum > 0) {
|
|
|
+ successMsg.insert(0, "恭喜您,数据已全部导入成功!共 " + successNum + " 条");
|
|
|
+ } else {
|
|
|
+ successMsg.insert(0, "导入失败!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return successMsg.toString();
|
|
|
+ }
|
|
|
+
|
|
|
}
|