Browse Source

承运商

master
廉洪喜 2 years ago
parent
commit
e0193267cb
  1. 22
      win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/controller/owner/OwnerController.java
  2. 82
      win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/controller/owner/vo/OwnerImportErrorVO.java
  3. 4
      win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/convert/owner/OwnerConvert.java
  4. 2
      win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/service/bom/BomServiceImpl.java
  5. 2
      win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/service/owner/OwnerService.java
  6. 78
      win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/service/owner/OwnerServiceImpl.java

22
win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/controller/owner/OwnerController.java

@ -8,13 +8,8 @@ import com.win.framework.excel.core.util.ExcelUtils;
import com.win.framework.operatelog.core.annotations.OperateLog; import com.win.framework.operatelog.core.annotations.OperateLog;
import com.win.module.system.api.user.AdminUserApi; import com.win.module.system.api.user.AdminUserApi;
import com.win.module.system.api.user.dto.AdminUserRespDTO; import com.win.module.system.api.user.dto.AdminUserRespDTO;
import com.win.module.wms.controller.itembasic.vo.ItembasicExcelVO;
import com.win.module.wms.controller.owner.vo.*; import com.win.module.wms.controller.owner.vo.*;
import com.win.module.wms.controller.recordsetting.vo.RecordsettingRespVO;
import com.win.module.wms.convert.itembasic.ItembasicConvert;
import com.win.module.wms.convert.owner.OwnerConvert; import com.win.module.wms.convert.owner.OwnerConvert;
import com.win.module.wms.convert.recordsetting.RecordsettingConvert;
import com.win.module.wms.dal.dataobject.itembasic.ItembasicDO;
import com.win.module.wms.dal.dataobject.owner.OwnerDO; import com.win.module.wms.dal.dataobject.owner.OwnerDO;
import com.win.module.wms.enums.DictTypeConstants; import com.win.module.wms.enums.DictTypeConstants;
import com.win.module.wms.service.owner.OwnerService; import com.win.module.wms.service.owner.OwnerService;
@ -111,6 +106,8 @@ public class OwnerController {
} }
return success(result); return success(result);
} }
@GetMapping("/export-excel") @GetMapping("/export-excel")
@Operation(summary = "导出货主 Excel") @Operation(summary = "导出货主 Excel")
@PreAuthorize("@ss.hasPermission('wms:owner:export')") @PreAuthorize("@ss.hasPermission('wms:owner:export')")
@ -122,6 +119,7 @@ public class OwnerController {
List<OwnerExcelVO> resultList = this.getExcelVo(list, mapDropDown); List<OwnerExcelVO> resultList = this.getExcelVo(list, mapDropDown);
ExcelUtils.write(response, "货主.xlsx", "数据", OwnerExcelVO.class, resultList, mapDropDown); ExcelUtils.write(response, "货主.xlsx", "数据", OwnerExcelVO.class, resultList, mapDropDown);
} }
@PostMapping("/export-excel-senior") @PostMapping("/export-excel-senior")
@Operation(summary = "导出货主 Excel") @Operation(summary = "导出货主 Excel")
@PreAuthorize("@ss.hasPermission('wms:owner:export')") @PreAuthorize("@ss.hasPermission('wms:owner:export')")
@ -149,6 +147,7 @@ public class OwnerController {
return resultList; return resultList;
} }
@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 {
@ -165,6 +164,7 @@ public class OwnerController {
ExcelUtils.write(response, "货主导入模板.xls", "货主列表", OwnerImportExcelVO.class, list,mapDropDown); ExcelUtils.write(response, "货主导入模板.xls", "货主列表", OwnerImportExcelVO.class, list,mapDropDown);
} }
@PostMapping("/import") @PostMapping("/import")
@Operation(summary = "导入货主") @Operation(summary = "导入货主")
@Parameters({ @Parameters({
@ -173,17 +173,19 @@ public class OwnerController {
@Parameter(name = "updatePart", description = "部分更新,默认为 true", example = "true") @Parameter(name = "updatePart", description = "部分更新,默认为 true", example = "true")
}) })
@PreAuthorize("@ss.hasPermission('wms:owner:import')") @PreAuthorize("@ss.hasPermission('wms:owner:import')")
public void importExcel(HttpServletResponse response, public CommonResult<Map<String, Object>> importExcel(HttpServletResponse response,
@RequestParam("file") MultipartFile file, @RequestParam("file") MultipartFile file,
@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<OwnerImportExcelVO> list = ExcelUtils.read(file, OwnerImportExcelVO.class); List<OwnerImportExcelVO> list = ExcelUtils.read(file, OwnerImportExcelVO.class);
List<OwnerImportExcelVO> errorList = ownerService.importOwnerList(list, mode, updatePart); List<OwnerImportErrorVO> errorList = ownerService.importOwnerList(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());
if(!errorList.isEmpty()) { if(!errorList.isEmpty()) {
String url = ExcelUtils.writeLocalFile("库位导入错误数据" + LocalDateTime.now().toEpochSecond(ZoneOffset.of("+8")) + ".xls", "错误列表", errorList); String url = ExcelUtils.writeLocalFile("库位导入错误数据" + LocalDateTime.now().toEpochSecond(ZoneOffset.of("+8")) + ".xls", "错误列表", errorList);
returnMap.put("errorFile", url); returnMap.put("errorFile", url);
} }
return success(returnMap);
} }
} }

82
win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/controller/owner/vo/OwnerImportErrorVO.java

@ -0,0 +1,82 @@
package com.win.module.wms.controller.owner.vo;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.write.style.ColumnWidth;
import com.win.framework.excel.core.annotations.DictFormat;
import com.win.framework.excel.core.convert.DictConvert;
import com.win.module.wms.enums.DictTypeConstants;
import lombok.Builder;
import lombok.Data;
import lombok.ToString;
import java.math.BigDecimal;
import java.time.LocalDateTime;
@Data
@Builder
@ToString(callSuper = true)
public class OwnerImportErrorVO {
@ExcelProperty("代码")
private String code;
@ExcelProperty("名称")
private String name;
@ExcelProperty("简称")
private String shortName;
@ExcelProperty("地址")
private String address;
@ExcelProperty("国家")
private String country;
@ExcelProperty("城市")
private String city;
@ExcelProperty("电话")
private String phone;
@ExcelProperty("传真")
private String fax;
@ExcelProperty("邮编")
private String postId;
@ExcelProperty("联系人")
private String contacts;
@ExcelProperty("银行")
private String bank;
@ExcelProperty(value = "币种", converter = DictConvert.class)
@DictFormat(DictTypeConstants.CURRENCY)
private String currency;
@ExcelProperty("税率")
private BigDecimal taxRate;
@ExcelProperty(value = "类型", converter = DictConvert.class)
@DictFormat(DictTypeConstants.OWNER_TYPE)
private String type;
@ExcelProperty(value = "是否可用", converter = DictConvert.class)
@DictFormat(DictTypeConstants.TRUE_FALSE)
private String available;
@ExcelProperty(value = "生效时间")
@ColumnWidth(value = 16)
private LocalDateTime activeTime;
@ExcelProperty(value = "失效时间")
@ColumnWidth(value = 16)
private LocalDateTime expireTime;
@ExcelProperty(value = "备注")
private String remark;
@ExcelProperty(value = "导入状态", index = 0)
private String importStatus;
@ExcelProperty(value = "导入说明", index = 1)
private String importRemark;
}

4
win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/convert/owner/OwnerConvert.java

@ -1,6 +1,8 @@
package com.win.module.wms.convert.owner; package com.win.module.wms.convert.owner;
import com.win.framework.common.pojo.PageResult; import com.win.framework.common.pojo.PageResult;
import com.win.module.wms.controller.bom.vo.BomImportErrorVO;
import com.win.module.wms.controller.bom.vo.BomImportExcelVo;
import com.win.module.wms.controller.owner.vo.*; import com.win.module.wms.controller.owner.vo.*;
import com.win.module.wms.dal.dataobject.owner.OwnerDO; import com.win.module.wms.dal.dataobject.owner.OwnerDO;
import org.mapstruct.Mapper; import org.mapstruct.Mapper;
@ -31,4 +33,6 @@ public interface OwnerConvert {
List<OwnerExcelVO> convertList02(List<OwnerDO> list); List<OwnerExcelVO> convertList02(List<OwnerDO> list);
OwnerDO convert(OwnerImportExcelVO owner); OwnerDO convert(OwnerImportExcelVO owner);
OwnerImportErrorVO convert2(OwnerDO bean);
} }

2
win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/service/bom/BomServiceImpl.java

@ -266,4 +266,6 @@ public class BomServiceImpl implements BomService {
} }
} }

2
win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/service/owner/OwnerService.java

@ -78,5 +78,5 @@ public interface OwnerService {
*/ */
List<OwnerDO> getOwnerList(OwnerExportReqVO exportReqVO); List<OwnerDO> getOwnerList(OwnerExportReqVO exportReqVO);
List<OwnerImportExcelVO> importOwnerList(List<OwnerImportExcelVO> owners, Integer mode, Boolean updatePart); List<OwnerImportErrorVO> importOwnerList(List<OwnerImportExcelVO> owners, Integer mode, Boolean updatePart);
} }

78
win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/service/owner/OwnerServiceImpl.java

@ -7,10 +7,13 @@ import com.win.framework.common.exception.ServiceException;
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.framework.datapermission.core.util.DataPermissionUtils; import com.win.framework.datapermission.core.util.DataPermissionUtils;
import com.win.module.wms.controller.bom.vo.BomImportErrorVO;
import com.win.module.wms.controller.owner.vo.*; import com.win.module.wms.controller.owner.vo.*;
import com.win.module.wms.convert.accountcalendar.AccountcalendarConvert; import com.win.module.wms.convert.accountcalendar.AccountcalendarConvert;
import com.win.module.wms.convert.bom.BomConvert;
import com.win.module.wms.convert.owner.OwnerConvert; import com.win.module.wms.convert.owner.OwnerConvert;
import com.win.module.wms.dal.dataobject.accountcalendar.AccountcalendarDO; import com.win.module.wms.dal.dataobject.accountcalendar.AccountcalendarDO;
import com.win.module.wms.dal.dataobject.bom.BomDO;
import com.win.module.wms.dal.dataobject.itembasic.ItembasicDO; import com.win.module.wms.dal.dataobject.itembasic.ItembasicDO;
import com.win.module.wms.dal.dataobject.owner.OwnerDO; import com.win.module.wms.dal.dataobject.owner.OwnerDO;
import com.win.module.wms.dal.mysql.owner.OwnerMapper; import com.win.module.wms.dal.mysql.owner.OwnerMapper;
@ -88,60 +91,61 @@ public class OwnerServiceImpl implements OwnerService {
public PageResult<OwnerDO> getOwnerSenior(CustomConditions conditions) { public PageResult<OwnerDO> getOwnerSenior(CustomConditions conditions) {
return ownerMapper.selectSenior(conditions); return ownerMapper.selectSenior(conditions);
} }
public String validateOwnerImport(OwnerDO owner){
StringBuilder message = new StringBuilder();
try {
validateOwnerExists(null);
} catch (ServiceException ex) {
message.append(ex.getMessage()).append(",");
}
try {
validateCodeExists(null,owner.getCode());
} catch (ServiceException ex) {
message.append(ex.getMessage()).append(",");
}
try {
validateShortNameExists(owner.getShortName());
} catch (ServiceException ex) {
message.append(ex.getMessage()).append(",");
}
try {
validateAvailableExists(owner.getAvailable());
} catch (ServiceException ex) {
message.append(ex.getMessage()).append(",");
}
return message.toString();
}
@Override @Override
public List<OwnerImportExcelVO> importOwnerList(List<OwnerImportExcelVO> owners, Integer mode, Boolean updatePart) { public List<OwnerImportErrorVO> importOwnerList(List<OwnerImportExcelVO> owners, Integer mode, Boolean updatePart) {
if (CollUtil.isEmpty(owners)) { if (CollUtil.isEmpty(owners)) {
throw exception(OWNER_IMPORT_LIST_IS_EMPTY); throw exception(OWNER_IMPORT_LIST_IS_EMPTY);
} }
List<OwnerImportExcelVO> errorList = new ArrayList<>(); List<OwnerImportErrorVO> errorList = new ArrayList<>();
owners.forEach(owner -> { owners.forEach(owner -> {
String massage = ""; OwnerDO ownerDO = OwnerConvert.INSTANCE.convert(owner);
// 校验,判断是否有不符合的原因 String massage =this.validateOwnerImport(ownerDO);
if(mode != null){ boolean flag = true;
try { if(!massage.isEmpty()){
validateOwnerExists(null); OwnerImportErrorVO importErrorVO = OwnerConvert.INSTANCE.convert2(ownerDO);
} catch (ServiceException ex) { importErrorVO.setImportStatus("失败");
massage += ex.getMessage() + ","; importErrorVO.setImportRemark(massage.substring(0, massage.length() - 1));
} errorList.add(importErrorVO);
try { flag = false;
validateCodeExists(null,owner.getCode());
} catch (ServiceException ex) {
massage += ex.getMessage() + ",";
}
try {
validateShortNameExists(owner.getShortName());
} catch (ServiceException ex) {
massage += ex.getMessage() + ",";
}
try {
validateAvailableExists(owner.getAvailable());
} catch (ServiceException ex) {
massage += ex.getMessage() + ",";
}
} }
if(StrUtil.isNotEmpty(massage)){ if(flag){
massage.substring(0,massage.length()-1); OwnerDO existOwner = ownerMapper.selectByCode(ownerDO.getCode());
errorList.add(owner);
}
if(errorList == null){
// 判断如果不存在,在进行插入
OwnerDO existOwner = new OwnerDO();
if (existOwner == null&& mode != 3) { if (existOwner == null&& mode != 3) {
ownerMapper.insert(OwnerConvert.INSTANCE.convert(owner)); ownerMapper.insert(OwnerConvert.INSTANCE.convert(owner));
} }
else if (existOwner != null && mode != 2) {// 如果存在,判断是否允许更新 else if (existOwner != null && mode != 2) {// 如果存在,判断是否允许更新
OwnerDO ownerDO = OwnerConvert.INSTANCE.convert(owner);
ownerDO.setId(existOwner.getId()); ownerDO.setId(existOwner.getId());
ownerMapper.updateById(ownerDO); ownerMapper.updateById(ownerDO);
} }
} }
}); });
//错误不为空并非部分更新,手工回滚
if(!errorList.isEmpty() && !updatePart) {
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
}
return errorList; return errorList;
} }
private void validateLocationForCreateOrUpdate(Long id, String code,String shortName,String available) { private void validateLocationForCreateOrUpdate(Long id, String code,String shortName,String available) {
// 关闭数据权限,避免因为没有数据权限,查询不到数据,进而导致唯一校验不正确 // 关闭数据权限,避免因为没有数据权限,查询不到数据,进而导致唯一校验不正确
DataPermissionUtils.executeIgnore(() -> { DataPermissionUtils.executeIgnore(() -> {

Loading…
Cancel
Save