|
|
@ -7,6 +7,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
|
|
|
import com.win.framework.common.exception.util.ServiceExceptionUtil; |
|
|
|
import com.win.framework.common.pojo.CustomConditions; |
|
|
|
import com.win.framework.common.pojo.PageResult; |
|
|
|
import com.win.module.eam.controller.item.vo.ItemBaseVO; |
|
|
|
import com.win.module.eam.controller.itemaccounts.vo.*; |
|
|
|
import com.win.module.eam.controller.transaction.vo.TransactionCreateReqVO; |
|
|
|
import com.win.module.eam.convert.itemaccounts.ItemAccountsConvert; |
|
|
@ -28,6 +29,7 @@ import com.win.module.eam.enums.transaction.TransactionEnum; |
|
|
|
import com.win.module.eam.service.transaction.TransactionService; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
import org.springframework.transaction.interceptor.TransactionAspectSupport; |
|
|
|
import org.springframework.validation.annotation.Validated; |
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
@ -41,7 +43,6 @@ import java.util.Map; |
|
|
|
import static com.win.framework.common.exception.util.ServiceExceptionUtil.exception; |
|
|
|
import static com.win.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; |
|
|
|
import static com.win.module.eam.enums.ErrorCodeConstants.*; |
|
|
|
import static com.win.module.eam.enums.ErrorCodeConstants.CLASSTYPR_NO_NOMAL; |
|
|
|
|
|
|
|
/** |
|
|
|
* 备件台账 Service 实现类 |
|
|
@ -340,27 +341,86 @@ public class ItemAccountsServiceImpl implements ItemAccountsService { |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public List<ItemAccountsExcelVO> importItemAccountsList(List<ItemAccountsExcelVO> datas, Integer mode, boolean updatePart) { |
|
|
|
@Transactional |
|
|
|
public List<ItemAccountsImportExcelVO> importItemAccountsList(List<ItemAccountsImportExcelVO> datas, Integer mode, boolean updatePart) { |
|
|
|
//备件编号+库位编码+类型唯一
|
|
|
|
if (CollUtil.isEmpty(datas)) { |
|
|
|
//throw exception(ITEM_ACCOUNTS_IMPORT_LIST_IS_EMPTY);
|
|
|
|
} |
|
|
|
|
|
|
|
List<ItemAccountsExcelVO> errorList = new ArrayList<>(); |
|
|
|
// datas.forEach(item -> {
|
|
|
|
// if(errorList == null){
|
|
|
|
// // 判断如果不存在,在进行插入
|
|
|
|
// ItemAccountsDO obj = itemAccountsMapper.selectByCode(item.getCode());
|
|
|
|
// if (obj == null&& mode != 3) {
|
|
|
|
// itemAccountsMapper.insert(ItemAccountsConvert.INSTANCE.convert(item));
|
|
|
|
// }
|
|
|
|
// else if (obj != null && mode != 2) {// 如果存在,判断是否允许更新
|
|
|
|
// ItemAccountsDO itemAccountsDO = ItemAccountsConvert.INSTANCE.convert(item);
|
|
|
|
// itemAccountsDO.setId(obj.getId());
|
|
|
|
// itemAccountsMapper.updateById(obj);
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// });
|
|
|
|
throw exception(ITEM_NEW_TURN_IN_IMPORT_LIST_IS_EMPTY);//导入数据不能为空
|
|
|
|
} |
|
|
|
|
|
|
|
List<ItemAccountsImportExcelVO> errorList = new ArrayList<>(); |
|
|
|
datas.forEach(item -> { |
|
|
|
//判断该备件是否在备件基础数据中无则报错
|
|
|
|
validate(item.getItemNumber(),item.getLocationNumber());//校验库位是否被使用
|
|
|
|
QueryWrapper<ItemDO> queryWrapper = new QueryWrapper<>(); |
|
|
|
queryWrapper.eq("number",item.getItemNumber()); |
|
|
|
queryWrapper.eq("available","TRUE"); |
|
|
|
List<ItemDO> itemDOS = itemMapper.selectList(queryWrapper); |
|
|
|
if(itemDOS.isEmpty()){ |
|
|
|
ItemAccountsErrorVO convert = ItemAccountsConvert.INSTANCE.convert(item); |
|
|
|
convert.setImportStatus("失败"); |
|
|
|
convert.setImportRemark("该备件在基础数据中不存在"); |
|
|
|
errorList.add(convert); |
|
|
|
return; |
|
|
|
} |
|
|
|
//判断该库位是否在备件基础数据中无则报错
|
|
|
|
LocationDO locationDO = locationMapper.getByNumber(item.getLocationNumber()); |
|
|
|
if(locationDO==null){ |
|
|
|
ItemAccountsErrorVO convert = ItemAccountsConvert.INSTANCE.convert(item); |
|
|
|
convert.setImportStatus("失败"); |
|
|
|
convert.setImportRemark("该库位在基础数据中不存在"); |
|
|
|
errorList.add(convert); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
try { |
|
|
|
validate(item.getItemNumber(),item.getLocationNumber());//校验库位是否被使用
|
|
|
|
} catch (Exception e) { |
|
|
|
ItemAccountsErrorVO convert = ItemAccountsConvert.INSTANCE.convert(item); |
|
|
|
convert.setImportStatus("失败"); |
|
|
|
convert.setImportRemark("该库位已存在其他类型数据"); |
|
|
|
errorList.add(convert); |
|
|
|
return; |
|
|
|
} |
|
|
|
try { |
|
|
|
validate(item.getItemNumber(),item.getLocationNumber());//校验库位是否被使用
|
|
|
|
} catch (Exception e) { |
|
|
|
ItemAccountsErrorVO convert = ItemAccountsConvert.INSTANCE.convert(item); |
|
|
|
convert.setImportStatus("失败"); |
|
|
|
convert.setImportRemark("该库位已存在其他类型数据"); |
|
|
|
errorList.add(convert); |
|
|
|
return; |
|
|
|
} |
|
|
|
try { |
|
|
|
if(item.getItemNumber()==null|| item.getItemNumber().trim().isEmpty() || item.getLocationNumber()==null|| item.getLocationNumber().trim().isEmpty() || item.getType()==null|| item.getType().trim().isEmpty()){//备件号为空
|
|
|
|
ItemAccountsErrorVO convert = ItemAccountsConvert.INSTANCE.convert(item); |
|
|
|
convert.setImportStatus("失败"); |
|
|
|
convert.setImportRemark("数据为空"); |
|
|
|
errorList.add(convert); |
|
|
|
} |
|
|
|
ItemAccountsDO itemAccountsDO = validateItemAndTypeAndLocation(item.getItemNumber(), item.getType(), item.getLocationNumber());//查询重复数据
|
|
|
|
if(mode != 2){// 如果存在,判断是否允许更新
|
|
|
|
ItemAccountsDO itemAccountsDO1 = ItemAccountsConvert.INSTANCE.convert1(item); |
|
|
|
itemAccountsDO1.setId(itemAccountsDO.getId()); |
|
|
|
itemAccountsMapper.updateById(itemAccountsDO1); |
|
|
|
} |
|
|
|
if(itemAccountsDO==null&&mode != 3){//数据库中不存在值且不是覆盖走新增
|
|
|
|
//根据库位查询库区
|
|
|
|
ItemAccountsDO itemAccountsDO1 = ItemAccountsConvert.INSTANCE.convert1(item); |
|
|
|
itemAccountsDO1.setAreaNumber(locationDO.getAreaNumber()); |
|
|
|
itemAccountsMapper.insert(itemAccountsDO1); |
|
|
|
} |
|
|
|
} catch (Exception e) { |
|
|
|
ItemAccountsErrorVO convert = ItemAccountsConvert.INSTANCE.convert(item); |
|
|
|
convert.setImportStatus("失败"); |
|
|
|
convert.setImportRemark("数据错误"); |
|
|
|
errorList.add(convert); |
|
|
|
} |
|
|
|
}); |
|
|
|
//错误不为空并非部分更新,手工回滚
|
|
|
|
if(!errorList.isEmpty() && !updatePart) { |
|
|
|
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); |
|
|
|
} |
|
|
|
return errorList; |
|
|
|
} |
|
|
|
|
|
|
|