|
@@ -12,6 +12,7 @@ import com.platform.common.constant.CommonConstants;
|
|
|
import com.platform.common.enums.DataFilterTypeEnum;
|
|
|
import com.platform.common.enums.ResultCode;
|
|
|
import com.platform.common.exception.BusinessException;
|
|
|
+import com.platform.common.exception.DeniedException;
|
|
|
import com.platform.common.model.UserInfo;
|
|
|
import com.platform.common.util.*;
|
|
|
import com.platform.dao.bean.MyVOPage;
|
|
@@ -661,7 +662,6 @@ public class SbInfoServiceImpl extends BaseServiceImpl<SbInfoMapper, SbInfo, SbI
|
|
|
|
|
|
@Override
|
|
|
public String updateImportUpdateForLongYan(MultipartFile file) {
|
|
|
- int addNum = 0;
|
|
|
List<FirmProducer> producerList = firmProducerMapper.selectAll(); // 生产厂商
|
|
|
List<SbPosition> positionList = sbPositionMapper.selectAll(); // 设备位置
|
|
|
List<SbType> typeList = sbTypeMapper.selectAll(); // 设备类型集合
|
|
@@ -724,6 +724,19 @@ public class SbInfoServiceImpl extends BaseServiceImpl<SbInfoMapper, SbInfo, SbI
|
|
|
throw new BusinessException("找不到使用人员,请先添加, 名称" + vo.getSaveUserName());
|
|
|
}
|
|
|
}
|
|
|
+ /*if(StringUtils.isNotBlank(vo.getParentSbName())){ // 父设备
|
|
|
+ SbInfo queryInfo = new SbInfo();
|
|
|
+ queryInfo.setName(vo.getParentSbName().trim());
|
|
|
+ List<SbInfo> sbList = mapper.select(queryInfo);
|
|
|
+ if(sbList != null){
|
|
|
+ if(sbList.size() > 1){
|
|
|
+ throw new DeniedException("父设备【"+vo.getParentSbName()+"】,系统找寻到多个设备【"+sbList.size()+"】个,请确认");
|
|
|
+ }
|
|
|
+ tempInfo.setParentId(sbList.get(0).getId());
|
|
|
+ }else{
|
|
|
+ throw new DeniedException("系统未找到设备【"+vo.getParentSbName()+"】,请确认");
|
|
|
+ }
|
|
|
+ }*/
|
|
|
// 如果计量设备
|
|
|
if(vo.getUseType() == SbUseType.BGCL.getValue()){
|
|
|
if(vo.getCheckDate() == null && vo.getNextCheckDate() == null){
|
|
@@ -2014,80 +2027,87 @@ public class SbInfoServiceImpl extends BaseServiceImpl<SbInfoMapper, SbInfo, SbI
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public String importListByAdd(MultipartFile file) {
|
|
|
- int addNum = 0;
|
|
|
- List<String> modelError = new ArrayList<String>();
|
|
|
+ List<FirmProducer> producerList = firmProducerMapper.selectAll(); // 生产厂商
|
|
|
+ List<SbPosition> positionList = sbPositionMapper.selectAll(); // 设备位置
|
|
|
+ List<SbType> typeList = sbTypeMapper.selectAll(); // 设备类型集合
|
|
|
+ List<SbInfo> addList = new ArrayList<>(); // 待导入集合
|
|
|
+ List<SysUser> users = sysUserMapper.selectAll(); // 用户集合
|
|
|
try {
|
|
|
- List<SbInfoVO> items = CustomExcelImportUtil.importSbInfoList(file.getInputStream());
|
|
|
- if (!CollectionUtils.isEmpty(items)) {
|
|
|
- List<SbInfoVO> addItems = new ArrayList<SbInfoVO>();
|
|
|
- List<SysUser> users = sysUserMapper.selectAll();
|
|
|
- List<FirmProducer> producerList = firmProducerMapper.selectAll();
|
|
|
- LocalDateTime now = LocalDateTime.now();
|
|
|
- for (SbInfoVO item : items) {
|
|
|
- item.setUseArea(useArea);
|
|
|
- item.setUseCompany(useCompany);
|
|
|
- item.setUseProject(useProject);
|
|
|
- item.setUseDept(useDept);
|
|
|
- item.setUseGroup(useGroup);
|
|
|
- item.setId(IdGeneratorUtils.getObjectId());
|
|
|
- boolean findSaveUser = false;
|
|
|
- for (SysUser user : users) {
|
|
|
- if (user.getRealName().equals(item.getSaveUserName())) {
|
|
|
- item.setSaveUser(user.getUserId());
|
|
|
- item.setUseUser(user.getUserId());
|
|
|
- findSaveUser = true;
|
|
|
- break;
|
|
|
+ List<ExportSbInfoVO> list = ExcelUtil.importExcel(file.getInputStream(), ExportSbInfoVO.class, 1);
|
|
|
+ if(CollectionUtil.isNotEmpty(list)){
|
|
|
+ for(ExportSbInfoVO vo : list){
|
|
|
+ SbInfo tempInfo = BeanConverterUtil.copyObjectProperties(vo,SbInfo.class);
|
|
|
+ if(StringUtils.isNotBlank(vo.getTypeName())){ // 设备类型匹配
|
|
|
+ boolean findSbType = false;
|
|
|
+ for (SbType sbType : typeList) {
|
|
|
+ if (sbType.getName().equalsIgnoreCase(vo.getTypeName().trim())) {
|
|
|
+ tempInfo.setTypeId(sbType.getId());
|
|
|
+ findSbType = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
- if (!findSaveUser) {
|
|
|
- throw new BusinessException("找不到使用人员,请先添加, 名称" + item.getSaveUser());
|
|
|
- }
|
|
|
-
|
|
|
- List<SbType> typeList = sbTypeMapper.selectAll();
|
|
|
- boolean find = false;
|
|
|
- for (SbType type : typeList) {
|
|
|
- if (type.getName().equals(item.getTypeName())) {
|
|
|
- item.setTypeId(type.getId());
|
|
|
- find = true;
|
|
|
- break;
|
|
|
+ if (!findSbType) {
|
|
|
+ throw new BusinessException("系统找不到该设备类型名称,请先添加设备类型, 设备类型名称" + vo.getTypeName());
|
|
|
}
|
|
|
}
|
|
|
- if (!find) {
|
|
|
- throw new BusinessException("找不到设备类型,请先添加:" + item.getTypeName());
|
|
|
+ if(StringUtils.isNotBlank(vo.getPositionName())){ // 设备位置匹配
|
|
|
+ boolean findPosition = false;
|
|
|
+ for (SbPosition position : positionList) {
|
|
|
+ if (position.getName().equalsIgnoreCase(vo.getPositionName().trim())) {
|
|
|
+ tempInfo.setPositionId(position.getId());
|
|
|
+ findPosition = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!findPosition) {
|
|
|
+ throw new BusinessException("系统找不到车间名称,请先添加车间, 车间名称" + vo.getPositionName());
|
|
|
+ }
|
|
|
}
|
|
|
-
|
|
|
- List<SbPosition> positionList = sbPositionMapper.selectAll();
|
|
|
- boolean findPosition = false;
|
|
|
- for (SbPosition position : positionList) {
|
|
|
- if (position.getName().equals(item.getPositionName())) {
|
|
|
- item.setPositionId(position.getId());
|
|
|
- findPosition = true;
|
|
|
- break;
|
|
|
+ if(StringUtils.isNotBlank(vo.getProducerName())){ // 生产商匹配
|
|
|
+ boolean findProducer = false;
|
|
|
+ for (FirmProducer producer : producerList) {
|
|
|
+ if (producer.getName().equalsIgnoreCase(vo.getProducerName().trim())) {
|
|
|
+ tempInfo.setProducerId(producer.getId());
|
|
|
+ findProducer = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!findProducer) {
|
|
|
+ throw new BusinessException("找不到生产商,请先添加:" + vo.getProducerName());
|
|
|
}
|
|
|
}
|
|
|
- if (!findPosition) {
|
|
|
- throw new BusinessException("找不到设备位置,请先添加,位置名称是:" + item.getPositionName());
|
|
|
+ if(StringUtils.isNotBlank(vo.getSaveUserName())){ // 使用人员
|
|
|
+ boolean findSaveUser = false;
|
|
|
+ for (SysUser user : users) {
|
|
|
+ if (user.getRealName().equalsIgnoreCase(vo.getSaveUserName().trim())) {
|
|
|
+ tempInfo.setSaveUser(user.getUserId());
|
|
|
+ findSaveUser = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!findSaveUser) {
|
|
|
+ throw new BusinessException("找不到使用人员,请先添加, 名称" + vo.getSaveUserName());
|
|
|
+ }
|
|
|
}
|
|
|
-
|
|
|
- boolean findProdcuer = false;
|
|
|
- for (FirmProducer producer : producerList) {
|
|
|
- if (producer.getName().equals(item.getProducerId())) {
|
|
|
- item.setProducerId(producer.getId());
|
|
|
- findProdcuer = true;
|
|
|
- break;
|
|
|
+ // 如果计量设备
|
|
|
+ if(vo.getUseType() == SbUseType.BGCL.getValue()){
|
|
|
+ if(vo.getCheckDate() == null && vo.getNextCheckDate() == null){
|
|
|
+ throw new BusinessException("上次和下次检定日期,不能全部为空");
|
|
|
+ }
|
|
|
+ if(vo.getCheckPeriod() == null){
|
|
|
+ throw new BusinessException("检定周期不能为空");
|
|
|
}
|
|
|
}
|
|
|
- /*if (!findProdcuer) {
|
|
|
- throw new BusinessException("找不到生产商,请先添加:" + item.getProducerId());
|
|
|
- }*/
|
|
|
- addItems.add(item);
|
|
|
- }
|
|
|
- if (!CollectionUtils.isEmpty(addItems)) {
|
|
|
- List<SbInfo> itemsAdd = BeanConverterUtil.copyListProperties(addItems, SbInfo.class);
|
|
|
- mapper.insertListforComplex(itemsAdd);
|
|
|
+ tempInfo.setId(IdGeneratorUtils.getObjectId());
|
|
|
+ tempInfo.setCreatedUserName(SecurityUtils.getUserInfo().getUsername());
|
|
|
+ tempInfo.setCreatedUserId(SecurityUtils.getUserInfo().getUserId());
|
|
|
+ tempInfo.setCreatedTime(LocalDateTime.now());
|
|
|
+ addList.add(tempInfo);
|
|
|
}
|
|
|
}
|
|
|
- return "总计新增导入:" + (items.size());
|
|
|
+ // 导入数据
|
|
|
+ mapper.insertListforComplex(addList);
|
|
|
+ return "总计导入:" + (addList.size());
|
|
|
} catch (Exception e) {
|
|
|
throw new BusinessException(e.getMessage());
|
|
|
}
|