diff --git a/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/controller/currencyexchange/CurrencyexchangeController.java b/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/controller/currencyexchange/CurrencyexchangeController.java index bba5ed96..4612ddf5 100644 --- a/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/controller/currencyexchange/CurrencyexchangeController.java +++ b/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/controller/currencyexchange/CurrencyexchangeController.java @@ -8,14 +8,9 @@ import com.win.framework.excel.core.util.ExcelUtils; import com.win.framework.operatelog.core.annotations.OperateLog; import com.win.module.system.api.user.AdminUserApi; import com.win.module.system.api.user.dto.AdminUserRespDTO; -import com.win.module.wms.controller.accountcalendar.vo.AccountcalendarRespVO; import com.win.module.wms.controller.currencyexchange.vo.*; -import com.win.module.wms.controller.itembasic.vo.ItembasicExcelVO; -import com.win.module.wms.convert.accountcalendar.AccountcalendarConvert; import com.win.module.wms.convert.currencyexchange.CurrencyexchangeConvert; -import com.win.module.wms.convert.itembasic.ItembasicConvert; import com.win.module.wms.dal.dataobject.currencyexchange.CurrencyexchangeDO; -import com.win.module.wms.dal.dataobject.itembasic.ItembasicDO; import com.win.module.wms.enums.DictTypeConstants; import com.win.module.wms.service.currencyexchange.CurrencyexchangeService; import io.swagger.v3.oas.annotations.Operation; @@ -167,16 +162,19 @@ public class CurrencyexchangeController { @Parameter(name = "updatePart", description = "部分更新,默认为 true", example = "true") }) @PreAuthorize("@ss.hasPermission('wms:configurationsetting:import')") - public void importExcel(HttpServletResponse response, - @RequestParam("file") MultipartFile file, - @RequestParam(value = "mode") Integer mode, - @RequestParam(value = "updatePart", required = false, defaultValue = "false") Boolean updatePart) throws Exception { + public CommonResult> importExcel(HttpServletResponse response, + @RequestParam("file") MultipartFile file, + @RequestParam(value = "mode") Integer mode, + @RequestParam(value = "updatePart", required = false, defaultValue = "false") Boolean updatePart) throws Exception { List list = ExcelUtils.read(file, CurrencyexchangeImportExcelVo.class); - List errorList = currencyexchangeService.importCurrencyexchangeList(list, mode, updatePart); + List errorList = currencyexchangeService.importCurrencyexchangeList(list, mode, updatePart); Map returnMap = new HashMap<>(); returnMap.put("errorCount", errorList.size()); if(!errorList.isEmpty()) { String url = ExcelUtils.writeLocalFile("货币转换导入错误数据" + LocalDateTime.now().toEpochSecond(ZoneOffset.of("+8")) + ".xls", "错误列表", errorList); returnMap.put("errorFile", url); - }} + } + return success(returnMap); + } + } diff --git a/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/controller/currencyexchange/vo/CurrencyexchangeImportErrorVO.java b/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/controller/currencyexchange/vo/CurrencyexchangeImportErrorVO.java new file mode 100644 index 00000000..be852200 --- /dev/null +++ b/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/controller/currencyexchange/vo/CurrencyexchangeImportErrorVO.java @@ -0,0 +1,54 @@ +package com.win.module.wms.controller.currencyexchange.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 CurrencyexchangeImportErrorVO { + @ExcelProperty("货币") + private String currency; + + @ExcelProperty("基础货币") + private String basiccurrency; + + @ExcelProperty("比率") + private BigDecimal rate; + + @ExcelProperty(value = "是否可用", converter = DictConvert.class) + @DictFormat("true_false") // TODO 代码优化:建议设置到对应的 XXXDictTypeConstants 枚举类中 + private String available; + + @ExcelProperty("生效时间") + @ColumnWidth(value = 16) + private LocalDateTime activeTime; + + @ExcelProperty("失效时间") + @ColumnWidth(value = 16) + private LocalDateTime expireTime; + + @ExcelProperty("备注") + private String remark; + + @ExcelProperty("创建时间") + @ColumnWidth(value = 16) + private LocalDateTime createTime; + + @ExcelProperty("创建者ID") + private String creator; + + @ExcelProperty(value = "导入状态", index = 0) + private String importStatus; + + @ExcelProperty(value = "导入说明", index = 1) + private String importRemark; +} diff --git a/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/convert/currencyexchange/CurrencyexchangeConvert.java b/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/convert/currencyexchange/CurrencyexchangeConvert.java index c93b9fc3..dc26b698 100644 --- a/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/convert/currencyexchange/CurrencyexchangeConvert.java +++ b/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/convert/currencyexchange/CurrencyexchangeConvert.java @@ -1,6 +1,8 @@ package com.win.module.wms.convert.currencyexchange; 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.currencyexchange.vo.*; import com.win.module.wms.dal.dataobject.currencyexchange.CurrencyexchangeDO; import org.mapstruct.Mapper; @@ -32,4 +34,7 @@ public interface CurrencyexchangeConvert { CurrencyexchangeDO convert(CurrencyexchangeImportExcelVo currencyexchange); + + CurrencyexchangeImportErrorVO convert2(CurrencyexchangeDO bean); + } diff --git a/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/service/accountcalendar/AccountcalendarServiceImpl.java b/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/service/accountcalendar/AccountcalendarServiceImpl.java index e2e23e4e..69b918ad 100644 --- a/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/service/accountcalendar/AccountcalendarServiceImpl.java +++ b/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/service/accountcalendar/AccountcalendarServiceImpl.java @@ -2,6 +2,7 @@ package com.win.module.wms.service.accountcalendar; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.StrUtil; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.google.common.annotations.VisibleForTesting; import com.win.framework.common.exception.ServiceException; import com.win.framework.common.pojo.CustomConditions; @@ -108,6 +109,22 @@ public class AccountcalendarServiceImpl implements AccountcalendarService { return message.toString(); } + + public AccountcalendarDO existAccountcalendar(AccountcalendarDO accountcalendarDO){ + QueryWrapper queryWrapper = new QueryWrapper(); + queryWrapper.eq("year",accountcalendarDO.getYear()); + queryWrapper.eq("month",accountcalendarDO.getMonth()); + queryWrapper.eq("descriiption",accountcalendarDO.getDescriiption()); + queryWrapper.eq("begin_time",accountcalendarDO.getBeginTime()); + queryWrapper.eq("end_time",accountcalendarDO.getEndTime()); + queryWrapper.eq("converttotime",accountcalendarDO.getConverttotime()); + queryWrapper.eq("available",accountcalendarDO.getAvailable()); + queryWrapper.eq("active_time",accountcalendarDO.getActiveTime()); + queryWrapper.eq("expire_time",accountcalendarDO.getExpireTime()); + AccountcalendarDO AccountcalendarDO = accountcalendarMapper.selectOne(queryWrapper); + return AccountcalendarDO; + } + public List importAccountcalendarList(List importAccountcalendars, Integer mode, boolean updatePart) { if (CollUtil.isEmpty(importAccountcalendars)) { throw exception(ACCOUNTCALENDAR_IMPORT_LIST_IS_EMPTY); @@ -125,12 +142,13 @@ public class AccountcalendarServiceImpl implements AccountcalendarService { flag = false; } if(flag){ + AccountcalendarDO existAccountcalendarDO = existAccountcalendar(accountcalendarDO); - - if ( mode != 3) { + if (existAccountcalendarDO==null && mode != 3) { accountcalendarMapper.insert(AccountcalendarConvert.INSTANCE.convert(importAccountcalendar)); } - else if ( mode != 2) { + else if (existAccountcalendarDO!=null&& mode != 2) { + accountcalendarDO.setId(existAccountcalendarDO.getId()); // 如果存在,判断是否允许更新 accountcalendarMapper.updateById(accountcalendarDO); } diff --git a/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/service/currencyexchange/CurrencyexchangeService.java b/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/service/currencyexchange/CurrencyexchangeService.java index ec51e093..d81beb89 100644 --- a/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/service/currencyexchange/CurrencyexchangeService.java +++ b/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/service/currencyexchange/CurrencyexchangeService.java @@ -77,7 +77,7 @@ public interface CurrencyexchangeService { */ List getCurrencyexchangeList(CurrencyexchangeExportReqVO exportReqVO); - List importCurrencyexchangeList(List currencyexchanges, Integer mode, Boolean updatePart); + List importCurrencyexchangeList(List currencyexchanges, Integer mode, Boolean updatePart); /** * BQ----CE diff --git a/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/service/currencyexchange/CurrencyexchangeServiceImpl.java b/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/service/currencyexchange/CurrencyexchangeServiceImpl.java index ab961db1..b78365f5 100644 --- a/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/service/currencyexchange/CurrencyexchangeServiceImpl.java +++ b/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/service/currencyexchange/CurrencyexchangeServiceImpl.java @@ -10,7 +10,9 @@ import com.win.framework.common.pojo.CustomConditions; import com.win.framework.common.pojo.PageResult; import com.win.framework.datapermission.core.util.DataPermissionUtils; import com.win.module.wms.controller.currencyexchange.vo.*; +import com.win.module.wms.convert.bom.BomConvert; import com.win.module.wms.convert.currencyexchange.CurrencyexchangeConvert; +import com.win.module.wms.dal.dataobject.bom.BomDO; import com.win.module.wms.dal.dataobject.currencyexchange.CurrencyexchangeDO; import com.win.module.wms.dal.mysql.currencyexchange.CurrencyexchangeMapper; import org.springframework.stereotype.Service; @@ -97,57 +99,80 @@ public class CurrencyexchangeServiceImpl implements CurrencyexchangeService { return currencyexchangeMapper.selectList(exportReqVO); } + + public String validateCurrencyexchangeImport(CurrencyexchangeDO currencyExchange ){ + StringBuilder message = new StringBuilder(); + try { + validateConfigurationSettingExists(null); + } catch (ServiceException ex) { + message.append(ex.getMessage()).append(","); + } + try { + validateCurrencyExists(currencyExchange.getCurrency()); + } catch (ServiceException ex) { + message.append(ex.getMessage()).append(","); + } + try { + validateBasiccurrencyExists(currencyExchange.getBasiccurrency()); + } catch (ServiceException ex) { + message.append(ex.getMessage()).append(","); + } + try { + validateAvailableExists(currencyExchange.getAvailable()); + } catch (ServiceException ex) { + message.append(ex.getMessage()).append(","); + } + return message.toString(); + } + + + public CurrencyexchangeDO existCurrencyExchange(CurrencyexchangeDO currencyexchangeDO){ + QueryWrapper queryWrapper = new QueryWrapper(); + queryWrapper.eq("currency",currencyexchangeDO.getCurrency()); + queryWrapper.eq("basiccurrency",currencyexchangeDO.getBasiccurrency()); + queryWrapper.eq("rate",currencyexchangeDO.getRate()); + queryWrapper.eq("available",currencyexchangeDO.getAvailable()); + queryWrapper.eq("active_time",currencyexchangeDO.getActiveTime()); + queryWrapper.eq("expire_time",currencyexchangeDO.getExpireTime()); + CurrencyexchangeDO CurrencyexchangeDO = currencyexchangeMapper.selectOne(queryWrapper); + return CurrencyexchangeDO; + } + + + + + + @Override - public List importCurrencyexchangeList(List currencyexchanges, Integer mode, Boolean updatePart) { + public List importCurrencyexchangeList(List currencyexchanges, Integer mode, Boolean updatePart) { if (CollUtil.isEmpty(currencyexchanges)) { throw exception(CURRENCYEXCHANGE_IMPORT_LIST_IS_EMPTY); } - List errorList = new ArrayList<>(); - currencyexchanges.forEach(currencyexchange -> { - String massage = ""; + List errorList = new ArrayList<>(); + currencyexchanges.forEach(currencyExchange -> { + CurrencyexchangeDO currencyexchangeDO = CurrencyexchangeConvert.INSTANCE.convert(currencyExchange); + String message = this.validateCurrencyexchangeImport(currencyexchangeDO); + boolean flag = true; // 校验,判断是否有不符合的原因 - if(mode != null){ - try { - validateConfigurationSettingExists(null); - } catch (ServiceException ex) { - massage += ex.getMessage() + ","; - } - try { - validateCurrencyExists(currencyexchange.getCurrency()); - } catch (ServiceException ex) { - massage += ex.getMessage() + ","; - } - try { - validateBasiccurrencyExists(currencyexchange.getBasiccurrency()); - } catch (ServiceException ex) { - massage += ex.getMessage() + ","; - } - try { - validateAvailableExists(currencyexchange.getAvailable()); - } catch (ServiceException ex) { - massage += ex.getMessage() + ","; - }if(StrUtil.isNotEmpty(massage)){ - massage.substring(0,massage.length()-1); - errorList.add(currencyexchange); - } - if(errorList == null){ - // 判断如果不存在,在进行插入 - CurrencyexchangeDO existConfigurationSetting = null; - if (existConfigurationSetting == null&& mode != 3) { - currencyexchangeMapper.insert(CurrencyexchangeConvert.INSTANCE.convert(currencyexchange)); - } - else if (existConfigurationSetting != null && mode != 2) {// 如果存在,判断是否允许更新 - CurrencyexchangeDO currencyexchangeDO = CurrencyexchangeConvert.INSTANCE.convert(currencyexchange); - currencyexchangeDO.setId(existConfigurationSetting.getId()); - currencyexchangeMapper.updateById(currencyexchangeDO); - } - } - } + if(!message.isEmpty()){ + CurrencyexchangeImportErrorVO importErrorVO = CurrencyexchangeConvert.INSTANCE.convert2(currencyexchangeDO); + importErrorVO.setImportStatus("失败"); + importErrorVO.setImportRemark(message.substring(0, message.length() - 1)); + errorList.add(importErrorVO); + flag = false; + } + if(flag){ + CurrencyexchangeDO existAccountcalendar = existCurrencyExchange(currencyexchangeDO); + if (existAccountcalendar==null&& mode != 3) { + currencyexchangeMapper.insert(CurrencyexchangeConvert.INSTANCE.convert(currencyExchange)); + } + else if (existAccountcalendar!=null&& mode != 2) { + currencyexchangeDO.setId(existAccountcalendar.getId()); + currencyexchangeMapper.updateById(currencyexchangeDO); + } + } }); - //错误不为空并非部分更新,手工回滚 - if(!errorList.isEmpty() && !updatePart) { - TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); - } + return errorList; }