Browse Source

货币转换

master
廉洪喜 2 years ago
parent
commit
97952f02c8
  1. 14
      win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/controller/currencyexchange/CurrencyexchangeController.java
  2. 54
      win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/controller/currencyexchange/vo/CurrencyexchangeImportErrorVO.java
  3. 5
      win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/convert/currencyexchange/CurrencyexchangeConvert.java
  4. 24
      win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/service/accountcalendar/AccountcalendarServiceImpl.java
  5. 2
      win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/service/currencyexchange/CurrencyexchangeService.java
  6. 95
      win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/service/currencyexchange/CurrencyexchangeServiceImpl.java

14
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.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.accountcalendar.vo.AccountcalendarRespVO;
import com.win.module.wms.controller.currencyexchange.vo.*; 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.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.currencyexchange.CurrencyexchangeDO;
import com.win.module.wms.dal.dataobject.itembasic.ItembasicDO;
import com.win.module.wms.enums.DictTypeConstants; import com.win.module.wms.enums.DictTypeConstants;
import com.win.module.wms.service.currencyexchange.CurrencyexchangeService; import com.win.module.wms.service.currencyexchange.CurrencyexchangeService;
import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Operation;
@ -167,16 +162,19 @@ public class CurrencyexchangeController {
@Parameter(name = "updatePart", description = "部分更新,默认为 true", example = "true") @Parameter(name = "updatePart", description = "部分更新,默认为 true", example = "true")
}) })
@PreAuthorize("@ss.hasPermission('wms:configurationsetting:import')") @PreAuthorize("@ss.hasPermission('wms:configurationsetting: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<CurrencyexchangeImportExcelVo> list = ExcelUtils.read(file, CurrencyexchangeImportExcelVo.class); List<CurrencyexchangeImportExcelVo> list = ExcelUtils.read(file, CurrencyexchangeImportExcelVo.class);
List<CurrencyexchangeImportExcelVo> errorList = currencyexchangeService.importCurrencyexchangeList(list, mode, updatePart); List<CurrencyexchangeImportErrorVO> errorList = currencyexchangeService.importCurrencyexchangeList(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);
}
} }

54
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;
}

5
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; package com.win.module.wms.convert.currencyexchange;
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.currencyexchange.vo.*; import com.win.module.wms.controller.currencyexchange.vo.*;
import com.win.module.wms.dal.dataobject.currencyexchange.CurrencyexchangeDO; import com.win.module.wms.dal.dataobject.currencyexchange.CurrencyexchangeDO;
import org.mapstruct.Mapper; import org.mapstruct.Mapper;
@ -32,4 +34,7 @@ public interface CurrencyexchangeConvert {
CurrencyexchangeDO convert(CurrencyexchangeImportExcelVo currencyexchange); CurrencyexchangeDO convert(CurrencyexchangeImportExcelVo currencyexchange);
CurrencyexchangeImportErrorVO convert2(CurrencyexchangeDO bean);
} }

24
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.collection.CollUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.google.common.annotations.VisibleForTesting; import com.google.common.annotations.VisibleForTesting;
import com.win.framework.common.exception.ServiceException; import com.win.framework.common.exception.ServiceException;
import com.win.framework.common.pojo.CustomConditions; import com.win.framework.common.pojo.CustomConditions;
@ -108,6 +109,22 @@ public class AccountcalendarServiceImpl implements AccountcalendarService {
return message.toString(); return message.toString();
} }
public AccountcalendarDO existAccountcalendar(AccountcalendarDO accountcalendarDO){
QueryWrapper<AccountcalendarDO> 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<AccountcalendarImportErrorVO> importAccountcalendarList(List<AccountcalendarImportExcelVo> importAccountcalendars, Integer mode, boolean updatePart) { public List<AccountcalendarImportErrorVO> importAccountcalendarList(List<AccountcalendarImportExcelVo> importAccountcalendars, Integer mode, boolean updatePart) {
if (CollUtil.isEmpty(importAccountcalendars)) { if (CollUtil.isEmpty(importAccountcalendars)) {
throw exception(ACCOUNTCALENDAR_IMPORT_LIST_IS_EMPTY); throw exception(ACCOUNTCALENDAR_IMPORT_LIST_IS_EMPTY);
@ -125,12 +142,13 @@ public class AccountcalendarServiceImpl implements AccountcalendarService {
flag = false; flag = false;
} }
if(flag){ if(flag){
AccountcalendarDO existAccountcalendarDO = existAccountcalendar(accountcalendarDO);
if (existAccountcalendarDO==null && mode != 3) {
if ( mode != 3) {
accountcalendarMapper.insert(AccountcalendarConvert.INSTANCE.convert(importAccountcalendar)); accountcalendarMapper.insert(AccountcalendarConvert.INSTANCE.convert(importAccountcalendar));
} }
else if ( mode != 2) { else if (existAccountcalendarDO!=null&& mode != 2) {
accountcalendarDO.setId(existAccountcalendarDO.getId());
// 如果存在,判断是否允许更新 // 如果存在,判断是否允许更新
accountcalendarMapper.updateById(accountcalendarDO); accountcalendarMapper.updateById(accountcalendarDO);
} }

2
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<CurrencyexchangeDO> getCurrencyexchangeList(CurrencyexchangeExportReqVO exportReqVO); List<CurrencyexchangeDO> getCurrencyexchangeList(CurrencyexchangeExportReqVO exportReqVO);
List<CurrencyexchangeImportExcelVo> importCurrencyexchangeList(List<CurrencyexchangeImportExcelVo> currencyexchanges, Integer mode, Boolean updatePart); List<CurrencyexchangeImportErrorVO> importCurrencyexchangeList(List<CurrencyexchangeImportExcelVo> currencyexchanges, Integer mode, Boolean updatePart);
/** /**
* BQ----CE * BQ----CE

95
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.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.currencyexchange.vo.*; 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.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.dataobject.currencyexchange.CurrencyexchangeDO;
import com.win.module.wms.dal.mysql.currencyexchange.CurrencyexchangeMapper; import com.win.module.wms.dal.mysql.currencyexchange.CurrencyexchangeMapper;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -97,57 +99,80 @@ public class CurrencyexchangeServiceImpl implements CurrencyexchangeService {
return currencyexchangeMapper.selectList(exportReqVO); return currencyexchangeMapper.selectList(exportReqVO);
} }
@Override
public List<CurrencyexchangeImportExcelVo> importCurrencyexchangeList(List<CurrencyexchangeImportExcelVo> currencyexchanges, Integer mode, Boolean updatePart) { public String validateCurrencyexchangeImport(CurrencyexchangeDO currencyExchange ){
if (CollUtil.isEmpty(currencyexchanges)) { StringBuilder message = new StringBuilder();
throw exception(CURRENCYEXCHANGE_IMPORT_LIST_IS_EMPTY);
}
List<CurrencyexchangeImportExcelVo> errorList = new ArrayList<>();
currencyexchanges.forEach(currencyexchange -> {
String massage = "";
// 校验,判断是否有不符合的原因
if(mode != null){
try { try {
validateConfigurationSettingExists(null); validateConfigurationSettingExists(null);
} catch (ServiceException ex) { } catch (ServiceException ex) {
massage += ex.getMessage() + ","; message.append(ex.getMessage()).append(",");
} }
try { try {
validateCurrencyExists(currencyexchange.getCurrency()); validateCurrencyExists(currencyExchange.getCurrency());
} catch (ServiceException ex) { } catch (ServiceException ex) {
massage += ex.getMessage() + ","; message.append(ex.getMessage()).append(",");
} }
try { try {
validateBasiccurrencyExists(currencyexchange.getBasiccurrency()); validateBasiccurrencyExists(currencyExchange.getBasiccurrency());
} catch (ServiceException ex) { } catch (ServiceException ex) {
massage += ex.getMessage() + ","; message.append(ex.getMessage()).append(",");
} }
try { try {
validateAvailableExists(currencyexchange.getAvailable()); validateAvailableExists(currencyExchange.getAvailable());
} catch (ServiceException ex) { } catch (ServiceException ex) {
massage += ex.getMessage() + ","; message.append(ex.getMessage()).append(",");
}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);
} }
return message.toString();
} }
public CurrencyexchangeDO existCurrencyExchange(CurrencyexchangeDO currencyexchangeDO){
QueryWrapper<CurrencyexchangeDO> 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;
} }
});
//错误不为空并非部分更新,手工回滚
if(!errorList.isEmpty() && !updatePart) {
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
@Override
public List<CurrencyexchangeImportErrorVO> importCurrencyexchangeList(List<CurrencyexchangeImportExcelVo> currencyexchanges, Integer mode, Boolean updatePart) {
if (CollUtil.isEmpty(currencyexchanges)) {
throw exception(CURRENCYEXCHANGE_IMPORT_LIST_IS_EMPTY);
} }
List<CurrencyexchangeImportErrorVO> errorList = new ArrayList<>();
currencyexchanges.forEach(currencyExchange -> {
CurrencyexchangeDO currencyexchangeDO = CurrencyexchangeConvert.INSTANCE.convert(currencyExchange);
String message = this.validateCurrencyexchangeImport(currencyexchangeDO);
boolean flag = true;
// 校验,判断是否有不符合的原因
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);
}
}
});
return errorList; return errorList;
} }

Loading…
Cancel
Save