Browse Source

备件台账导入

master
songguoqiang 6 months ago
parent
commit
58a6b91218
  1. 11
      win-module-eam/win-module-eam-biz/src/main/java/com/win/module/eam/controller/itemaccounts/ItemAccountsController.java
  2. 17
      win-module-eam/win-module-eam-biz/src/main/java/com/win/module/eam/controller/itemaccounts/vo/ItemAccountsErrorVO.java
  3. 10
      win-module-eam/win-module-eam-biz/src/main/java/com/win/module/eam/controller/itemaccounts/vo/ItemAccountsExcelVO.java
  4. 42
      win-module-eam/win-module-eam-biz/src/main/java/com/win/module/eam/controller/itemaccounts/vo/ItemAccountsImportExcelVO.java
  5. 7
      win-module-eam/win-module-eam-biz/src/main/java/com/win/module/eam/convert/itemaccounts/ItemAccountsConvert.java
  6. 11
      win-module-eam/win-module-eam-biz/src/main/java/com/win/module/eam/dal/mysql/location/LocationMapper.java
  7. 2
      win-module-eam/win-module-eam-biz/src/main/java/com/win/module/eam/service/itemaccounts/ItemAccountsService.java
  8. 96
      win-module-eam/win-module-eam-biz/src/main/java/com/win/module/eam/service/itemaccounts/ItemAccountsServiceImpl.java

11
win-module-eam/win-module-eam-biz/src/main/java/com/win/module/eam/controller/itemaccounts/ItemAccountsController.java

@ -159,9 +159,12 @@ public class ItemAccountsController {
@GetMapping("/get-import-template") @GetMapping("/get-import-template")
@Operation(summary = "获得导入备件台账模板") @Operation(summary = "获得导入备件台账模板")
public void importTemplate(HttpServletResponse response) throws IOException { public void importTemplate(HttpServletResponse response) throws IOException {
List<ItemAccountsExcelVO> list = Arrays.asList(); List<ItemAccountsImportExcelVO> list = Arrays.asList();
Map<Integer, String[]> mapDropDown = new HashMap<>();
String[] strings = DictFrameworkUtils.dictTypeDictDataValue(DictTypeConstants.ITEM_ACCOUNT_LOCATION_TYPE);
mapDropDown.put(3, strings);
// 输出 // 输出
ExcelUtils.write(response, "备件台账基本信息导入模板.xls", "备件台账基本信息列表", ItemAccountsExcelVO.class, list); ExcelUtils.write(response, "备件台账基本信息导入模板.xls", "备件台账基本信息列表", ItemAccountsImportExcelVO.class, list,mapDropDown);
} }
@PostMapping("/import") @PostMapping("/import")
@ -177,8 +180,8 @@ public class ItemAccountsController {
@RequestParam(value = "mode") Integer mode, @RequestParam(value = "mode") Integer mode,
@RequestParam(value = "updatePart", required = false, defaultValue = "false") Boolean updatePart) throws Exception { @RequestParam(value = "updatePart", required = false, defaultValue = "false") Boolean updatePart) throws Exception {
List<ItemAccountsExcelVO> list = ExcelUtils.read(file, ItemAccountsExcelVO.class); List<ItemAccountsImportExcelVO> list = ExcelUtils.read(file, ItemAccountsImportExcelVO.class);
List<ItemAccountsExcelVO> errorList = itemAccountsService.importItemAccountsList(list, mode, updatePart); List<ItemAccountsImportExcelVO> errorList = itemAccountsService.importItemAccountsList(list, mode, updatePart);
Map<String, Object> returnMap = new HashMap<>(); Map<String, Object> returnMap = new HashMap<>();
returnMap.put("errorCount", errorList.size()); returnMap.put("errorCount", errorList.size());

17
win-module-eam/win-module-eam-biz/src/main/java/com/win/module/eam/controller/itemaccounts/vo/ItemAccountsErrorVO.java

@ -0,0 +1,17 @@
package com.win.module.eam.controller.itemaccounts.vo;
import com.alibaba.excel.annotation.ExcelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class ItemAccountsErrorVO extends ItemAccountsImportExcelVO {
@ExcelProperty(value = "导入状态", index = 0)
private String importStatus;
@ExcelProperty(value = "导入说明", index = 1)
private String importRemark;
}

10
win-module-eam/win-module-eam-biz/src/main/java/com/win/module/eam/controller/itemaccounts/vo/ItemAccountsExcelVO.java

@ -2,6 +2,8 @@ package com.win.module.eam.controller.itemaccounts.vo;
import com.alibaba.excel.annotation.ExcelIgnore; import com.alibaba.excel.annotation.ExcelIgnore;
import com.alibaba.excel.annotation.ExcelProperty; import com.alibaba.excel.annotation.ExcelProperty;
import com.win.framework.excel.core.annotations.DictFormat;
import com.win.framework.excel.core.convert.DictConvert;
import lombok.Data; import lombok.Data;
import java.math.BigDecimal; import java.math.BigDecimal;
@ -18,10 +20,10 @@ public class ItemAccountsExcelVO {
@ExcelProperty("备件编号") @ExcelProperty("备件编号")
private String itemNumber; private String itemNumber;
@ExcelProperty("备件编号") @ExcelProperty("备件名称")
private String itemName; private String itemName;
@ExcelProperty("库区名称") @ExcelProperty("库区编号")
private String areaNumber; private String areaNumber;
@ExcelProperty("库区名称") @ExcelProperty("库区名称")
@ -35,8 +37,8 @@ public class ItemAccountsExcelVO {
@ExcelProperty("库存数量") @ExcelProperty("库存数量")
private BigDecimal qty; private BigDecimal qty;
@DictFormat("item_account_location_type") // TODO 代码优化:建议设置到对应的 XXXDictTypeConstants 枚举类中
@ExcelProperty("库存类型") @ExcelProperty(value = "库存类型", converter = DictConvert.class)
private String type; private String type;
@ExcelProperty("创建时间") @ExcelProperty("创建时间")

42
win-module-eam/win-module-eam-biz/src/main/java/com/win/module/eam/controller/itemaccounts/vo/ItemAccountsImportExcelVO.java

@ -0,0 +1,42 @@
package com.win.module.eam.controller.itemaccounts.vo;
import com.alibaba.excel.annotation.ExcelIgnore;
import com.alibaba.excel.annotation.ExcelProperty;
import com.win.framework.excel.core.annotations.DictFormat;
import com.win.framework.excel.core.annotations.ExcelValid;
import com.win.framework.excel.core.convert.DictConvert;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import java.math.BigDecimal;
import java.time.LocalDateTime;
/**
* 备件台账 导出模版和导入数据
*
* @author 超级管理员
*/
@AllArgsConstructor
@NoArgsConstructor
@Accessors(chain = false) // 设置 chain = false,避免用户导入有问题
@Data
public class ItemAccountsImportExcelVO {
@ExcelProperty("备件编号")
private String itemNumber;
@ExcelProperty("库位编号")
private String locationNumber;
@ExcelProperty("库存数量")
private BigDecimal qty;
@ExcelProperty(value = "库存类型", converter = DictConvert.class)
@DictFormat("item_account_location_type") // TODO 代码优化:建议设置到对应的 XXXDictTypeConstants 枚举类中
private String type;
}

7
win-module-eam/win-module-eam-biz/src/main/java/com/win/module/eam/convert/itemaccounts/ItemAccountsConvert.java

@ -4,10 +4,7 @@ import java.util.*;
import com.win.framework.common.pojo.PageResult; import com.win.framework.common.pojo.PageResult;
import com.win.module.eam.controller.itemaccounts.vo.ItemAccountsCreateReqVO; import com.win.module.eam.controller.itemaccounts.vo.*;
import com.win.module.eam.controller.itemaccounts.vo.ItemAccountsExcelVO;
import com.win.module.eam.controller.itemaccounts.vo.ItemAccountsRespVO;
import com.win.module.eam.controller.itemaccounts.vo.ItemAccountsUpdateReqVO;
import org.mapstruct.Mapper; import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers; import org.mapstruct.factory.Mappers;
import com.win.module.eam.dal.dataobject.itemaccounts.ItemAccountsDO; import com.win.module.eam.dal.dataobject.itemaccounts.ItemAccountsDO;
@ -23,6 +20,8 @@ public interface ItemAccountsConvert {
ItemAccountsConvert INSTANCE = Mappers.getMapper(ItemAccountsConvert.class); ItemAccountsConvert INSTANCE = Mappers.getMapper(ItemAccountsConvert.class);
ItemAccountsDO convert(ItemAccountsCreateReqVO bean); ItemAccountsDO convert(ItemAccountsCreateReqVO bean);
ItemAccountsErrorVO convert(ItemAccountsImportExcelVO bean);
ItemAccountsDO convert1(ItemAccountsImportExcelVO bean);
ItemAccountsDO convert(ItemAccountsUpdateReqVO bean); ItemAccountsDO convert(ItemAccountsUpdateReqVO bean);

11
win-module-eam/win-module-eam-biz/src/main/java/com/win/module/eam/dal/mysql/location/LocationMapper.java

@ -52,6 +52,17 @@ public interface LocationMapper extends BaseMapperX<LocationDO> {
.orderByDesc(LocationDO::getId)); .orderByDesc(LocationDO::getId));
} }
/**
* 根据库位编码查询信息
* @param number
* @return
*/
default LocationDO getByNumber(@Param("number") String number){
return selectOne(new LambdaQueryWrapperX<LocationDO>()
.eqIfPresent(LocationDO::getNumber, number)
.eqIfPresent(LocationDO::getAvailable, "TRUE"));
};
/** /**
* 扫库位码获取库位信息以及关联备件信息 * 扫库位码获取库位信息以及关联备件信息
* @param number * @param number

2
win-module-eam/win-module-eam-biz/src/main/java/com/win/module/eam/service/itemaccounts/ItemAccountsService.java

@ -108,7 +108,7 @@ public interface ItemAccountsService {
* @param updatePart 是否支持更新 * @param updatePart 是否支持更新
* @return 导入结果 * @return 导入结果
*/ */
public List<ItemAccountsExcelVO> importItemAccountsList(List<ItemAccountsExcelVO> datas, Integer mode, boolean updatePart); public List<ItemAccountsImportExcelVO> importItemAccountsList(List<ItemAccountsImportExcelVO> datas, Integer mode, boolean updatePart);
/** /**
* 获得备件台账分页 * 获得备件台账分页

96
win-module-eam/win-module-eam-biz/src/main/java/com/win/module/eam/service/itemaccounts/ItemAccountsServiceImpl.java

@ -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.exception.util.ServiceExceptionUtil;
import com.win.framework.common.pojo.CustomConditions; import com.win.framework.common.pojo.CustomConditions;
import com.win.framework.common.pojo.PageResult; 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.itemaccounts.vo.*;
import com.win.module.eam.controller.transaction.vo.TransactionCreateReqVO; import com.win.module.eam.controller.transaction.vo.TransactionCreateReqVO;
import com.win.module.eam.convert.itemaccounts.ItemAccountsConvert; 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 com.win.module.eam.service.transaction.TransactionService;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource; 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.common.exception.util.ServiceExceptionUtil.exception;
import static com.win.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; 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.*;
import static com.win.module.eam.enums.ErrorCodeConstants.CLASSTYPR_NO_NOMAL;
/** /**
* 备件台账 Service 实现类 * 备件台账 Service 实现类
@ -340,27 +341,86 @@ public class ItemAccountsServiceImpl implements ItemAccountsService {
} }
@Override @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)) { if (CollUtil.isEmpty(datas)) {
//throw exception(ITEM_ACCOUNTS_IMPORT_LIST_IS_EMPTY); throw exception(ITEM_NEW_TURN_IN_IMPORT_LIST_IS_EMPTY);//导入数据不能为空
} }
List<ItemAccountsExcelVO> errorList = new ArrayList<>(); List<ItemAccountsImportExcelVO> errorList = new ArrayList<>();
// datas.forEach(item -> { datas.forEach(item -> {
// if(errorList == null){ //判断该备件是否在备件基础数据中无则报错
// // 判断如果不存在,在进行插入 validate(item.getItemNumber(),item.getLocationNumber());//校验库位是否被使用
// ItemAccountsDO obj = itemAccountsMapper.selectByCode(item.getCode()); QueryWrapper<ItemDO> queryWrapper = new QueryWrapper<>();
// if (obj == null&& mode != 3) { queryWrapper.eq("number",item.getItemNumber());
// itemAccountsMapper.insert(ItemAccountsConvert.INSTANCE.convert(item)); queryWrapper.eq("available","TRUE");
// } List<ItemDO> itemDOS = itemMapper.selectList(queryWrapper);
// else if (obj != null && mode != 2) {// 如果存在,判断是否允许更新 if(itemDOS.isEmpty()){
// ItemAccountsDO itemAccountsDO = ItemAccountsConvert.INSTANCE.convert(item); ItemAccountsErrorVO convert = ItemAccountsConvert.INSTANCE.convert(item);
// itemAccountsDO.setId(obj.getId()); convert.setImportStatus("失败");
// itemAccountsMapper.updateById(obj); 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; return errorList;
} }

Loading…
Cancel
Save