diff --git a/ruoyi-admin/src/main/java/com/ruoyi/system/domain/BaseExchangeRate.java b/ruoyi-admin/src/main/java/com/ruoyi/system/domain/BaseExchangeRate.java index adbaff08..b1005151 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/system/domain/BaseExchangeRate.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/system/domain/BaseExchangeRate.java @@ -3,6 +3,7 @@ package com.ruoyi.system.domain; import java.math.BigDecimal; import java.util.Date; import com.fasterxml.jackson.annotation.JsonFormat; +import com.ruoyi.common.annotation.FieldCompare; import org.apache.commons.lang3.builder.ToStringBuilder; import org.apache.commons.lang3.builder.ToStringStyle; import com.ruoyi.common.annotation.Excel; @@ -22,15 +23,18 @@ public class BaseExchangeRate extends BaseEntity private Long exchangeRateId; /** 汇率 */ + @FieldCompare(chineseName = "汇率") @Excel(name = "汇率") private BigDecimal exchangeRate; /** 开始时间 */ + @FieldCompare(chineseName = "开始时间") @JsonFormat(pattern = "yyyy-MM-dd") @Excel(name = "开始时间", width = 30, dateFormat = "yyyy-MM-dd") private Date startTime; /** 结束时间 */ + @FieldCompare(chineseName = "结束时间") @JsonFormat(pattern = "yyyy-MM-dd") @Excel(name = "结束时间", width = 30, dateFormat = "yyyy-MM-dd") private Date endTime; diff --git a/ruoyi-admin/src/main/java/com/ruoyi/system/service/impl/BaseExchangeRateServiceImpl.java b/ruoyi-admin/src/main/java/com/ruoyi/system/service/impl/BaseExchangeRateServiceImpl.java index 7dd0dacd..9a5561f6 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/system/service/impl/BaseExchangeRateServiceImpl.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/system/service/impl/BaseExchangeRateServiceImpl.java @@ -3,16 +3,22 @@ package com.ruoyi.system.service.impl; import java.util.Date; import java.util.List; +import com.ruoyi.common.constant.BusinessKeysConstants; +import com.ruoyi.common.core.domain.entity.SysFieldDifferent; import com.ruoyi.common.exception.BusinessException; import com.ruoyi.common.utils.DateUtils; +import com.ruoyi.common.utils.FieldCompareUtil; import com.ruoyi.common.utils.ShiroUtils; +import com.ruoyi.system.domain.SysDiffLog; import com.ruoyi.system.service.ISysDiffLogService; +import lombok.SneakyThrows; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.ruoyi.system.mapper.BaseExchangeRateMapper; import com.ruoyi.system.domain.BaseExchangeRate; import com.ruoyi.system.service.IBaseExchangeRateService; import com.ruoyi.common.core.text.Convert; +import org.springframework.transaction.annotation.Transactional; import org.springframework.util.CollectionUtils; /** @@ -27,6 +33,8 @@ public class BaseExchangeRateServiceImpl implements IBaseExchangeRateService @Autowired private BaseExchangeRateMapper baseExchangeRateMapper; + @Autowired + private ISysDiffLogService diffLogService; /** * 查询基础资料汇率管理 @@ -58,6 +66,7 @@ public class BaseExchangeRateServiceImpl implements IBaseExchangeRateService * @param baseExchangeRate 基础资料汇率管理 * @return 结果 */ + @Transactional(rollbackFor = Exception.class) @Override public int insertBaseExchangeRate(BaseExchangeRate baseExchangeRate) { @@ -75,7 +84,18 @@ public class BaseExchangeRateServiceImpl implements IBaseExchangeRateService if (!CollectionUtils.isEmpty(exchangeRates)){ throw new BusinessException("新增汇率失败!该时间段内已存在汇率数据!"); } - return baseExchangeRateMapper.insertBaseExchangeRate(baseExchangeRate); + + int result = baseExchangeRateMapper.insertBaseExchangeRate(baseExchangeRate); + + Long exchangeRateId = baseExchangeRate.getExchangeRateId(); + SysDiffLog sysDiffLog = new SysDiffLog(); + sysDiffLog.setBusinessId(exchangeRateId); + sysDiffLog.setBusinessKey(BusinessKeysConstants.SYS_EXCHANGE_RATE); + int insertSysDiffLog = diffLogService.insertSysDiffLog(sysDiffLog); + if (insertSysDiffLog <= 0){ + throw new BusinessException("新增汇率数据修改记录失败"); + } + return result; } /** @@ -84,12 +104,35 @@ public class BaseExchangeRateServiceImpl implements IBaseExchangeRateService * @param baseExchangeRate 基础资料汇率管理 * @return 结果 */ + @SneakyThrows + @Transactional(rollbackFor = Exception.class) @Override public int updateBaseExchangeRate(BaseExchangeRate baseExchangeRate) { String loginName = ShiroUtils.getLoginName(); baseExchangeRate.setUpdateBy(loginName); baseExchangeRate.setUpdateTime(DateUtils.getNowDate()); + Date startTime = baseExchangeRate.getStartTime(); + Date endTime = baseExchangeRate.getEndTime(); + + if (startTime.after(endTime)){ + throw new BusinessException("新增汇率失败!开始时间不能大于结束时间!"); + } + + List exchangeRates = baseExchangeRateMapper.selectExchangeRateByTimeRange(baseExchangeRate); + if (!CollectionUtils.isEmpty(exchangeRates)){ + throw new BusinessException("新增汇率失败!该时间段内已存在汇率数据!"); + } + Long exchangeRateId = baseExchangeRate.getExchangeRateId(); + BaseExchangeRate oldExchangeRate = baseExchangeRateMapper.selectBaseExchangeRateById(exchangeRateId); + List compare = FieldCompareUtil.compare(BaseExchangeRate.class, baseExchangeRate, oldExchangeRate); + if (!CollectionUtils.isEmpty(compare)){ + int updateSysDiffLog = diffLogService.updateSysDiffLogByBusiness(exchangeRateId,BusinessKeysConstants.SYS_EXCHANGE_RATE,compare); + if (updateSysDiffLog <= 0){ + throw new BusinessException("修改汇率数据修改记录失败"); + } + } + return baseExchangeRateMapper.updateBaseExchangeRate(baseExchangeRate); } diff --git a/ruoyi-admin/src/main/resources/mapper/system/BaseExchangeRateMapper.xml b/ruoyi-admin/src/main/resources/mapper/system/BaseExchangeRateMapper.xml index 2147e1cf..54234d0a 100644 --- a/ruoyi-admin/src/main/resources/mapper/system/BaseExchangeRateMapper.xml +++ b/ruoyi-admin/src/main/resources/mapper/system/BaseExchangeRateMapper.xml @@ -22,9 +22,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" diff --git a/ruoyi-admin/src/main/resources/templates/system/exchangeRate/add.html b/ruoyi-admin/src/main/resources/templates/system/exchangeRate/add.html index 7aae6e7f..06c7d6b6 100644 --- a/ruoyi-admin/src/main/resources/templates/system/exchangeRate/add.html +++ b/ruoyi-admin/src/main/resources/templates/system/exchangeRate/add.html @@ -28,7 +28,7 @@
- +
@@ -43,7 +43,14 @@