1、调整币种汇率模块
2、新增保险记录模块 3、新增违章记录模块 4、新增换胎记录模块 5、新增事故记录模块 6、新增年检记录模块 7、新增里程记录模块 8、新增变更记录模块 9、新增油电记录模块 10、新增ETC记录模块 11、新增其他费用记录模块
This commit is contained in:
@@ -25,8 +25,9 @@
|
||||
*/
|
||||
package org.springblade.system.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
@@ -49,6 +50,7 @@ import org.springblade.system.pojo.entity.Currency;
|
||||
import org.springblade.system.pojo.vo.CurrencyVO;
|
||||
import org.springblade.system.service.ICurrencyService;
|
||||
import org.springblade.system.wrapper.CurrencyWrapper;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
@@ -57,12 +59,12 @@ import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 币种主数据 控制器
|
||||
* 币种汇率 控制器
|
||||
*
|
||||
* @author Chill
|
||||
*/
|
||||
@@ -71,7 +73,7 @@ import java.util.Map;
|
||||
@AllArgsConstructor
|
||||
@PreAuth(menu = "currency")
|
||||
@RequestMapping("/currency")
|
||||
@Tag(name = "币种主数据", description = "币种主数据")
|
||||
@Tag(name = "币种汇率", description = "币种汇率")
|
||||
public class CurrencyController extends BladeController {
|
||||
|
||||
private final ICurrencyService currencyService;
|
||||
@@ -98,11 +100,22 @@ public class CurrencyController extends BladeController {
|
||||
return R.data(pages);
|
||||
}
|
||||
|
||||
/**
|
||||
* 有效汇率查询
|
||||
*/
|
||||
@GetMapping("/rate")
|
||||
@ApiOperationSupport(order = 3)
|
||||
@Operation(summary = "有效汇率查询", description = "根据币种编码和业务日期查询有效汇率")
|
||||
public R<CurrencyVO> rate(@Parameter(description = "币种编码", required = true) @RequestParam String code,
|
||||
@Parameter(description = "业务日期") @DateTimeFormat(pattern = "yyyy-MM-dd") @RequestParam(required = false) LocalDate businessDate) {
|
||||
return R.data(currencyService.getEffectiveRate(code, businessDate));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增或修改
|
||||
*/
|
||||
@PostMapping("/submit")
|
||||
@ApiOperationSupport(order = 3)
|
||||
@ApiOperationSupport(order = 4)
|
||||
@Operation(summary = "新增或修改", description = "传入currency")
|
||||
public R submit(@Valid @RequestBody Currency currency) {
|
||||
return R.status(currencyService.submit(currency));
|
||||
@@ -112,7 +125,7 @@ public class CurrencyController extends BladeController {
|
||||
* 删除
|
||||
*/
|
||||
@PostMapping("/remove")
|
||||
@ApiOperationSupport(order = 4)
|
||||
@ApiOperationSupport(order = 5)
|
||||
@Operation(summary = "逻辑删除", description = "传入ids")
|
||||
public R remove(@Parameter(description = "主键集合", required = true) @RequestParam String ids) {
|
||||
return R.status(currencyService.deleteLogic(Func.toLongList(ids)));
|
||||
@@ -122,7 +135,7 @@ public class CurrencyController extends BladeController {
|
||||
* 启用或停用
|
||||
*/
|
||||
@PostMapping("/status")
|
||||
@ApiOperationSupport(order = 5)
|
||||
@ApiOperationSupport(order = 6)
|
||||
@Operation(summary = "启用或停用", description = "传入id和status")
|
||||
public R status(@Parameter(description = "主键", required = true) @RequestParam Long id,
|
||||
@Parameter(description = "状态", required = true) @RequestParam Integer status) {
|
||||
@@ -130,11 +143,11 @@ public class CurrencyController extends BladeController {
|
||||
}
|
||||
|
||||
/**
|
||||
* 导入币种主数据
|
||||
* 导入币种汇率
|
||||
*/
|
||||
@PostMapping("/import-currency")
|
||||
@ApiOperationSupport(order = 6)
|
||||
@Operation(summary = "导入币种主数据", description = "传入excel")
|
||||
@ApiOperationSupport(order = 7)
|
||||
@Operation(summary = "导入币种汇率", description = "传入excel")
|
||||
public R importCurrency(MultipartFile file) {
|
||||
CurrencyImporter currencyImporter = new CurrencyImporter(currencyService);
|
||||
ExcelUtil.save(file, currencyImporter, CurrencyExcel.class);
|
||||
@@ -142,30 +155,71 @@ public class CurrencyController extends BladeController {
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出币种主数据
|
||||
* 导出币种汇率
|
||||
*/
|
||||
@GetMapping("/export-currency")
|
||||
@ApiOperationSupport(order = 7)
|
||||
@Operation(summary = "导出币种主数据")
|
||||
public void exportCurrency(@Parameter(hidden = true) @RequestParam Map<String, Object> currency, HttpServletResponse response) {
|
||||
Object ids = currency.remove("ids");
|
||||
QueryWrapper<Currency> queryWrapper = Condition.getQueryWrapper(currency, Currency.class);
|
||||
if (Func.isNotEmpty(ids)) {
|
||||
queryWrapper.lambda().in(Currency::getId, Func.toLongList(ids.toString()));
|
||||
}
|
||||
List<CurrencyExcel> list = currencyService.exportCurrency(queryWrapper);
|
||||
ExcelUtil.export(response, "币种主数据" + DateUtil.time(), "币种主数据表", list, CurrencyExcel.class);
|
||||
@ApiOperationSupport(order = 8)
|
||||
@Operation(summary = "导出币种汇率")
|
||||
public void exportCurrency(CurrencyVO currency,
|
||||
@RequestParam(required = false) String ids,
|
||||
HttpServletResponse response) {
|
||||
List<CurrencyExcel> list = currencyService.exportCurrency(buildExportQuery(currency, ids));
|
||||
ExcelUtil.export(response, "币种汇率" + DateUtil.time(), "币种汇率表", list, CurrencyExcel.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出模板
|
||||
*/
|
||||
@GetMapping("/export-template")
|
||||
@ApiOperationSupport(order = 8)
|
||||
@ApiOperationSupport(order = 9)
|
||||
@Operation(summary = "导出模板")
|
||||
public void exportTemplate(HttpServletResponse response) {
|
||||
List<CurrencyExcel> list = new ArrayList<>();
|
||||
ExcelUtil.export(response, "币种主数据模板", "币种主数据表", list, CurrencyExcel.class);
|
||||
ExcelUtil.export(response, "币种汇率模板", "币种汇率表", list, CurrencyExcel.class);
|
||||
}
|
||||
|
||||
private LambdaQueryWrapper<Currency> buildExportQuery(CurrencyVO currency, String ids) {
|
||||
LambdaQueryWrapper<Currency> queryWrapper = Wrappers.<Currency>lambdaQuery()
|
||||
.eq(Currency::getIsDeleted, 0)
|
||||
.orderByAsc(Currency::getCode)
|
||||
.orderByDesc(Currency::getEffectiveDate);
|
||||
if (Func.isNotEmpty(ids)) {
|
||||
queryWrapper.in(Currency::getId, Func.toLongList(ids));
|
||||
}
|
||||
if (Func.isNotEmpty(currency.getCode())) {
|
||||
queryWrapper.like(Currency::getCode, currency.getCode());
|
||||
}
|
||||
if (Func.isNotEmpty(currency.getName())) {
|
||||
queryWrapper.like(Currency::getName, currency.getName());
|
||||
}
|
||||
if (Func.isNotEmpty(currency.getStatus())) {
|
||||
queryWrapper.eq(Currency::getStatus, currency.getStatus());
|
||||
}
|
||||
if (Func.isNotEmpty(currency.getExchangeRate())) {
|
||||
queryWrapper.eq(Currency::getExchangeRate, currency.getExchangeRate());
|
||||
}
|
||||
if (Func.isNotEmpty(currency.getDataSource())) {
|
||||
queryWrapper.eq(Currency::getDataSource, currency.getDataSource());
|
||||
}
|
||||
if (Func.isNotEmpty(currency.getEffectiveDateStart())) {
|
||||
queryWrapper.ge(Currency::getEffectiveDate, currency.getEffectiveDateStart());
|
||||
}
|
||||
if (Func.isNotEmpty(currency.getEffectiveDateEnd())) {
|
||||
queryWrapper.le(Currency::getEffectiveDate, currency.getEffectiveDateEnd());
|
||||
}
|
||||
if (Func.isNotEmpty(currency.getExpiryDateStart())) {
|
||||
queryWrapper.ge(Currency::getExpiryDate, currency.getExpiryDateStart());
|
||||
}
|
||||
if (Func.isNotEmpty(currency.getExpiryDateEnd())) {
|
||||
queryWrapper.le(Currency::getExpiryDate, currency.getExpiryDateEnd());
|
||||
}
|
||||
if (Func.isNotEmpty(currency.getUpdateTimeStart())) {
|
||||
queryWrapper.ge(Currency::getUpdateTime, currency.getUpdateTimeStart());
|
||||
}
|
||||
if (Func.isNotEmpty(currency.getUpdateTimeEnd())) {
|
||||
queryWrapper.le(Currency::getUpdateTime, currency.getUpdateTimeEnd());
|
||||
}
|
||||
return queryWrapper;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -35,9 +35,10 @@ import lombok.Data;
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDate;
|
||||
|
||||
/**
|
||||
* 币种主数据 Excel
|
||||
* 币种汇率 Excel
|
||||
*
|
||||
* @author Chill
|
||||
*/
|
||||
@@ -58,27 +59,21 @@ public class CurrencyExcel implements Serializable {
|
||||
@ExcelProperty("币种中文名称")
|
||||
private String name;
|
||||
|
||||
@ExcelProperty("币种英文名称")
|
||||
private String englishName;
|
||||
|
||||
@ExcelProperty("货币符号")
|
||||
private String symbol;
|
||||
|
||||
@ExcelProperty("小数位数")
|
||||
private Integer decimalPlaces;
|
||||
|
||||
@ExcelProperty("汇率")
|
||||
private BigDecimal exchangeRate;
|
||||
|
||||
@ExcelProperty("是否本位币")
|
||||
private String baseCurrencyName;
|
||||
|
||||
@ExcelProperty("数据来源")
|
||||
private String dataSource;
|
||||
@ExcelProperty("生效日期")
|
||||
private LocalDate effectiveDate;
|
||||
|
||||
@ExcelProperty("状态")
|
||||
private String statusName;
|
||||
|
||||
@ExcelProperty("来源")
|
||||
private String dataSource;
|
||||
|
||||
@ExcelProperty("失效日期")
|
||||
private LocalDate expiryDate;
|
||||
|
||||
@ExcelProperty("备注")
|
||||
private String remark;
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ import org.springblade.system.service.ICurrencyService;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 币种主数据导入类
|
||||
* 币种汇率导入类
|
||||
*
|
||||
* @author Chill
|
||||
*/
|
||||
|
||||
@@ -17,6 +17,8 @@
|
||||
<result column="symbol" property="symbol"/>
|
||||
<result column="decimal_places" property="decimalPlaces"/>
|
||||
<result column="exchange_rate" property="exchangeRate"/>
|
||||
<result column="effective_date" property="effectiveDate"/>
|
||||
<result column="expiry_date" property="expiryDate"/>
|
||||
<result column="is_base_currency" property="baseCurrency"/>
|
||||
<result column="data_source" property="dataSource"/>
|
||||
<result column="remark" property="remark"/>
|
||||
@@ -41,16 +43,34 @@
|
||||
<bind name="englishNameLike" value="'%' + currency.englishName + '%'"/>
|
||||
AND english_name LIKE #{englishNameLike}
|
||||
</if>
|
||||
<if test="currency.baseCurrency != null">
|
||||
AND is_base_currency = #{currency.baseCurrency}
|
||||
<if test="currency.status != null">
|
||||
AND status = #{currency.status}
|
||||
</if>
|
||||
<if test="currency.exchangeRate != null">
|
||||
AND exchange_rate = #{currency.exchangeRate}
|
||||
</if>
|
||||
<if test="currency.dataSource != null and currency.dataSource != ''">
|
||||
AND data_source = #{currency.dataSource}
|
||||
</if>
|
||||
<if test="currency.status != null">
|
||||
AND status = #{currency.status}
|
||||
<if test="currency.effectiveDateStart != null">
|
||||
AND effective_date >= #{currency.effectiveDateStart}
|
||||
</if>
|
||||
ORDER BY update_time DESC, create_time DESC
|
||||
<if test="currency.effectiveDateEnd != null">
|
||||
AND effective_date <= #{currency.effectiveDateEnd}
|
||||
</if>
|
||||
<if test="currency.expiryDateStart != null">
|
||||
AND expiry_date >= #{currency.expiryDateStart}
|
||||
</if>
|
||||
<if test="currency.expiryDateEnd != null">
|
||||
AND expiry_date <= #{currency.expiryDateEnd}
|
||||
</if>
|
||||
<if test="currency.updateTimeStart != null">
|
||||
AND update_time >= #{currency.updateTimeStart}
|
||||
</if>
|
||||
<if test="currency.updateTimeEnd != null">
|
||||
AND update_time <= #{currency.updateTimeEnd}
|
||||
</if>
|
||||
ORDER BY code ASC, effective_date DESC, create_time DESC
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
|
||||
@@ -32,10 +32,11 @@ import org.springblade.system.excel.CurrencyExcel;
|
||||
import org.springblade.system.pojo.entity.Currency;
|
||||
import org.springblade.system.pojo.vo.CurrencyVO;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 币种主数据 服务类
|
||||
* 币种汇率 服务类
|
||||
*
|
||||
* @author Chill
|
||||
*/
|
||||
@@ -51,9 +52,9 @@ public interface ICurrencyService extends BaseService<Currency> {
|
||||
IPage<CurrencyVO> selectCurrencyPage(IPage<CurrencyVO> page, CurrencyVO currency);
|
||||
|
||||
/**
|
||||
* 新增或修改币种
|
||||
* 新增或修改币种汇率
|
||||
*
|
||||
* @param currency 币种
|
||||
* @param currency 币种汇率
|
||||
* @return 是否成功
|
||||
*/
|
||||
boolean submit(Currency currency);
|
||||
@@ -68,18 +69,27 @@ public interface ICurrencyService extends BaseService<Currency> {
|
||||
boolean changeStatus(Long id, Integer status);
|
||||
|
||||
/**
|
||||
* 导入币种
|
||||
* 导入币种汇率
|
||||
*
|
||||
* @param data 导入数据
|
||||
*/
|
||||
void importCurrency(List<CurrencyExcel> data);
|
||||
|
||||
/**
|
||||
* 导出币种
|
||||
* 导出币种汇率
|
||||
*
|
||||
* @param queryWrapper 查询条件
|
||||
* @return 导出数据
|
||||
*/
|
||||
List<CurrencyExcel> exportCurrency(Wrapper<Currency> queryWrapper);
|
||||
|
||||
/**
|
||||
* 查询有效汇率
|
||||
*
|
||||
* @param code 币种编码
|
||||
* @param businessDate 业务日期
|
||||
* @return 有效汇率
|
||||
*/
|
||||
CurrencyVO getEffectiveRate(String code, LocalDate businessDate);
|
||||
|
||||
}
|
||||
|
||||
@@ -42,6 +42,7 @@ import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
@@ -49,7 +50,7 @@ import java.util.Objects;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* 币种主数据 服务实现类
|
||||
* 币种汇率 服务实现类
|
||||
*
|
||||
* @author Chill
|
||||
*/
|
||||
@@ -57,7 +58,7 @@ import java.util.regex.Pattern;
|
||||
public class CurrencyServiceImpl extends BaseServiceImpl<CurrencyMapper, Currency> implements ICurrencyService {
|
||||
|
||||
private static final String SOURCE_BATCH = "批量导入";
|
||||
private static final String SOURCE_MANUAL = "手工导入";
|
||||
private static final String SOURCE_MANUAL = "手工录入";
|
||||
private static final int STATUS_ENABLED = 1;
|
||||
private static final int STATUS_DISABLED = 2;
|
||||
private static final int YES = 1;
|
||||
@@ -65,6 +66,7 @@ public class CurrencyServiceImpl extends BaseServiceImpl<CurrencyMapper, Currenc
|
||||
private static final int REMARK_MAX_LENGTH = 200;
|
||||
private static final int MIN_DECIMAL_PLACES = 0;
|
||||
private static final int MAX_DECIMAL_PLACES = 8;
|
||||
private static final int EXCHANGE_RATE_SCALE = 6;
|
||||
private static final Pattern CURRENCY_CODE_PATTERN = Pattern.compile("^[A-Z]{3}$");
|
||||
|
||||
@Override
|
||||
@@ -75,9 +77,15 @@ public class CurrencyServiceImpl extends BaseServiceImpl<CurrencyMapper, Currenc
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean submit(Currency currency) {
|
||||
Currency oldCurrency = Func.isNotEmpty(currency.getId()) ? getById(currency.getId()) : null;
|
||||
prepare(currency, SOURCE_MANUAL);
|
||||
validate(currency);
|
||||
return saveOrUpdate(currency);
|
||||
boolean result = saveOrUpdate(currency);
|
||||
rebuildEnabledValidity(currency.getCode());
|
||||
if (oldCurrency != null && !Objects.equals(oldCurrency.getCode(), currency.getCode())) {
|
||||
rebuildEnabledValidity(oldCurrency.getCode());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -96,30 +104,36 @@ public class CurrencyServiceImpl extends BaseServiceImpl<CurrencyMapper, Currenc
|
||||
Currency update = new Currency();
|
||||
update.setId(id);
|
||||
update.setStatus(status);
|
||||
return updateById(update);
|
||||
boolean result = updateById(update);
|
||||
rebuildEnabledValidity(currency.getCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void importCurrency(List<CurrencyExcel> data) {
|
||||
if (Func.isEmpty(data)) {
|
||||
throw new ServiceException("导入数据不能为空");
|
||||
}
|
||||
List<String> errorList = new ArrayList<>();
|
||||
int successCount = 0;
|
||||
for (int index = 0; index < data.size(); index++) {
|
||||
CurrencyExcel excel = data.get(index);
|
||||
try {
|
||||
Currency currency = Objects.requireNonNull(BeanUtil.copyProperties(excel, Currency.class));
|
||||
currency.setBaseCurrency(parseBaseCurrency(excel.getBaseCurrencyName()));
|
||||
currency.setDataSource(SOURCE_BATCH);
|
||||
currency.setStatus(STATUS_ENABLED);
|
||||
prepare(currency, SOURCE_BATCH);
|
||||
validate(currency);
|
||||
save(currency);
|
||||
rebuildEnabledValidity(currency.getCode());
|
||||
successCount++;
|
||||
} catch (Exception exception) {
|
||||
String message = exception instanceof ServiceException ? exception.getMessage() : "导入失败";
|
||||
errorList.add("第" + (index + 2) + "行:" + message);
|
||||
}
|
||||
}
|
||||
if (Func.isNotEmpty(errorList)) {
|
||||
throw new ServiceException(String.join(";", errorList));
|
||||
throw new ServiceException("导入成功" + successCount + "条,失败" + errorList.size() + "条:" + String.join(";", errorList));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -128,12 +142,37 @@ public class CurrencyServiceImpl extends BaseServiceImpl<CurrencyMapper, Currenc
|
||||
List<Currency> currencyList = list(queryWrapper);
|
||||
return currencyList.stream().map(currency -> {
|
||||
CurrencyExcel excel = Objects.requireNonNull(BeanUtil.copyProperties(currency, CurrencyExcel.class));
|
||||
excel.setBaseCurrencyName(Objects.equals(currency.getBaseCurrency(), YES) ? "是" : "否");
|
||||
excel.setStatusName(Objects.equals(currency.getStatus(), STATUS_ENABLED) ? "启用" : "停用");
|
||||
return excel;
|
||||
}).toList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CurrencyVO getEffectiveRate(String code, LocalDate businessDate) {
|
||||
String currencyCode = trimToEmpty(code).toUpperCase(Locale.ROOT);
|
||||
if (!CURRENCY_CODE_PATTERN.matcher(currencyCode).matches()) {
|
||||
throw new ServiceException("币种代码为3位大写字母");
|
||||
}
|
||||
if (count(Wrappers.<Currency>lambdaQuery()
|
||||
.eq(Currency::getCode, currencyCode)
|
||||
.eq(Currency::getIsDeleted, 0)) <= 0L) {
|
||||
throw new ServiceException("币种不存在");
|
||||
}
|
||||
LocalDate queryDate = businessDate == null ? LocalDate.now() : businessDate;
|
||||
Currency currency = getOne(Wrappers.<Currency>lambdaQuery()
|
||||
.eq(Currency::getCode, currencyCode)
|
||||
.eq(Currency::getStatus, STATUS_ENABLED)
|
||||
.eq(Currency::getIsDeleted, 0)
|
||||
.le(Currency::getEffectiveDate, queryDate)
|
||||
.and(wrapper -> wrapper.isNull(Currency::getExpiryDate).or().gt(Currency::getExpiryDate, queryDate))
|
||||
.orderByDesc(Currency::getEffectiveDate)
|
||||
.last("limit 1"));
|
||||
if (currency == null) {
|
||||
throw new ServiceException("未找到有效汇率");
|
||||
}
|
||||
return Objects.requireNonNull(BeanUtil.copyProperties(currency, CurrencyVO.class));
|
||||
}
|
||||
|
||||
private void prepare(Currency currency, String defaultDataSource) {
|
||||
currency.setCode(trimToEmpty(currency.getCode()).toUpperCase(Locale.ROOT));
|
||||
currency.setName(trimToEmpty(currency.getName()));
|
||||
@@ -141,12 +180,10 @@ public class CurrencyServiceImpl extends BaseServiceImpl<CurrencyMapper, Currenc
|
||||
currency.setSymbol(trimToNull(currency.getSymbol()));
|
||||
currency.setRemark(trimToNull(currency.getRemark()));
|
||||
currency.setDataSource(Func.toStrWithEmpty(currency.getDataSource(), defaultDataSource));
|
||||
currency.setExpiryDate(null);
|
||||
if (Func.isEmpty(currency.getDecimalPlaces())) {
|
||||
currency.setDecimalPlaces(2);
|
||||
}
|
||||
if (Func.isEmpty(currency.getExchangeRate())) {
|
||||
currency.setExchangeRate(BigDecimal.ONE);
|
||||
}
|
||||
if (Func.isEmpty(currency.getBaseCurrency())) {
|
||||
currency.setBaseCurrency(NO);
|
||||
}
|
||||
@@ -163,63 +200,77 @@ public class CurrencyServiceImpl extends BaseServiceImpl<CurrencyMapper, Currenc
|
||||
throw new ServiceException("币种代码为3位大写字母");
|
||||
}
|
||||
if (Func.isEmpty(currency.getName())) {
|
||||
throw new ServiceException("币种中文名称不能为空");
|
||||
throw new ServiceException("币种名称不能为空");
|
||||
}
|
||||
if (currency.getDecimalPlaces() < MIN_DECIMAL_PLACES || currency.getDecimalPlaces() > MAX_DECIMAL_PLACES) {
|
||||
throw new ServiceException("小数位数范围为0到8");
|
||||
}
|
||||
if (Func.isEmpty(currency.getExchangeRate())) {
|
||||
throw new ServiceException("汇率不能为空");
|
||||
}
|
||||
if (currency.getExchangeRate().compareTo(BigDecimal.ZERO) <= 0) {
|
||||
throw new ServiceException("汇率必须大于0");
|
||||
}
|
||||
if (currency.getExchangeRate().stripTrailingZeros().scale() > EXCHANGE_RATE_SCALE) {
|
||||
throw new ServiceException("汇率最多保留6位小数");
|
||||
}
|
||||
if (Func.isEmpty(currency.getEffectiveDate())) {
|
||||
throw new ServiceException("生效日期不能为空");
|
||||
}
|
||||
if (!Objects.equals(currency.getBaseCurrency(), YES) && !Objects.equals(currency.getBaseCurrency(), NO)) {
|
||||
throw new ServiceException("是否本位币取值不正确");
|
||||
}
|
||||
if (Objects.equals(currency.getBaseCurrency(), YES) && currency.getExchangeRate().compareTo(BigDecimal.ONE) != 0) {
|
||||
throw new ServiceException("本位币汇率必须为1");
|
||||
}
|
||||
if (Func.isNotEmpty(currency.getRemark()) && currency.getRemark().length() > REMARK_MAX_LENGTH) {
|
||||
throw new ServiceException("备注不能超过200字");
|
||||
}
|
||||
validateUnique(currency, Currency::getCode, currency.getCode(), "该币种代码已存在");
|
||||
validateBaseCurrency(currency);
|
||||
validateCodeName(currency);
|
||||
validateUniqueEffectiveDate(currency);
|
||||
}
|
||||
|
||||
private void validateUnique(Currency currency, com.baomidou.mybatisplus.core.toolkit.support.SFunction<Currency, ?> column, String value, String message) {
|
||||
private void validateUniqueEffectiveDate(Currency currency) {
|
||||
LambdaQueryWrapper<Currency> queryWrapper = Wrappers.<Currency>lambdaQuery()
|
||||
.eq(column, value)
|
||||
.eq(Currency::getCode, currency.getCode())
|
||||
.eq(Currency::getEffectiveDate, currency.getEffectiveDate())
|
||||
.eq(Currency::getIsDeleted, 0);
|
||||
if (Func.isNotEmpty(currency.getId())) {
|
||||
queryWrapper.ne(Currency::getId, currency.getId());
|
||||
}
|
||||
if (count(queryWrapper) > 0L) {
|
||||
throw new ServiceException(message);
|
||||
throw new ServiceException("同币种同生效日期已存在");
|
||||
}
|
||||
}
|
||||
|
||||
private void validateBaseCurrency(Currency currency) {
|
||||
if (!Objects.equals(currency.getBaseCurrency(), YES)) {
|
||||
private void validateCodeName(Currency currency) {
|
||||
LambdaQueryWrapper<Currency> queryWrapper = Wrappers.<Currency>lambdaQuery()
|
||||
.eq(Currency::getCode, currency.getCode())
|
||||
.eq(Currency::getIsDeleted, 0);
|
||||
if (Func.isNotEmpty(currency.getId())) {
|
||||
queryWrapper.ne(Currency::getId, currency.getId());
|
||||
}
|
||||
Currency exists = getOne(queryWrapper.last("limit 1"));
|
||||
if (exists != null && !Objects.equals(exists.getName(), currency.getName())) {
|
||||
throw new ServiceException("同一币种编码的币种名称必须一致");
|
||||
}
|
||||
}
|
||||
|
||||
private void rebuildEnabledValidity(String code) {
|
||||
String currencyCode = trimToEmpty(code).toUpperCase(Locale.ROOT);
|
||||
if (Func.isEmpty(currencyCode)) {
|
||||
return;
|
||||
}
|
||||
LambdaQueryWrapper<Currency> queryWrapper = Wrappers.<Currency>lambdaQuery()
|
||||
.eq(Currency::getBaseCurrency, YES)
|
||||
.eq(Currency::getIsDeleted, 0);
|
||||
if (Func.isNotEmpty(currency.getId())) {
|
||||
queryWrapper.ne(Currency::getId, currency.getId());
|
||||
List<Currency> enabledRecords = list(Wrappers.<Currency>lambdaQuery()
|
||||
.eq(Currency::getCode, currencyCode)
|
||||
.eq(Currency::getStatus, STATUS_ENABLED)
|
||||
.eq(Currency::getIsDeleted, 0)
|
||||
.orderByAsc(Currency::getEffectiveDate)
|
||||
.orderByAsc(Currency::getCreateTime));
|
||||
for (int index = 0; index < enabledRecords.size(); index++) {
|
||||
Currency record = enabledRecords.get(index);
|
||||
Currency update = new Currency();
|
||||
update.setId(record.getId());
|
||||
update.setExpiryDate(index + 1 < enabledRecords.size() ? enabledRecords.get(index + 1).getEffectiveDate() : null);
|
||||
updateById(update);
|
||||
}
|
||||
if (count(queryWrapper) > 0L) {
|
||||
throw new ServiceException("本位币只能设置一个");
|
||||
}
|
||||
}
|
||||
|
||||
private Integer parseBaseCurrency(String value) {
|
||||
String trimValue = trimToEmpty(value);
|
||||
if (Func.isEmpty(trimValue) || "否".equals(trimValue) || "0".equals(trimValue)) {
|
||||
return NO;
|
||||
}
|
||||
if ("是".equals(trimValue) || "1".equals(trimValue)) {
|
||||
return YES;
|
||||
}
|
||||
throw new ServiceException("是否本位币只能填写是或否");
|
||||
}
|
||||
|
||||
private String trimToEmpty(String value) {
|
||||
|
||||
@@ -27,6 +27,7 @@ package org.springblade.system.wrapper;
|
||||
|
||||
import org.springblade.core.mp.support.BaseEntityWrapper;
|
||||
import org.springblade.core.tool.utils.BeanUtil;
|
||||
import org.springblade.system.cache.UserCache;
|
||||
import org.springblade.system.pojo.entity.AirportMaster;
|
||||
import org.springblade.system.pojo.vo.AirportMasterVO;
|
||||
|
||||
@@ -45,7 +46,9 @@ public class AirportMasterWrapper extends BaseEntityWrapper<AirportMaster, Airpo
|
||||
|
||||
@Override
|
||||
public AirportMasterVO entityVO(AirportMaster airportMaster) {
|
||||
return Objects.requireNonNull(BeanUtil.copyProperties(airportMaster, AirportMasterVO.class));
|
||||
AirportMasterVO airportMasterVO = Objects.requireNonNull(BeanUtil.copyProperties(airportMaster, AirportMasterVO.class));
|
||||
airportMasterVO.setUpdateUserName(UserCache.getUserRealName(airportMaster.getUpdateUser()));
|
||||
return airportMasterVO;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ package org.springblade.system.wrapper;
|
||||
|
||||
import org.springblade.core.mp.support.BaseEntityWrapper;
|
||||
import org.springblade.core.tool.utils.BeanUtil;
|
||||
import org.springblade.system.cache.UserCache;
|
||||
import org.springblade.system.pojo.entity.PortTerminal;
|
||||
import org.springblade.system.pojo.vo.PortTerminalVO;
|
||||
|
||||
@@ -45,7 +46,9 @@ public class PortTerminalWrapper extends BaseEntityWrapper<PortTerminal, PortTer
|
||||
|
||||
@Override
|
||||
public PortTerminalVO entityVO(PortTerminal portTerminal) {
|
||||
return Objects.requireNonNull(BeanUtil.copyProperties(portTerminal, PortTerminalVO.class));
|
||||
PortTerminalVO portTerminalVO = Objects.requireNonNull(BeanUtil.copyProperties(portTerminal, PortTerminalVO.class));
|
||||
portTerminalVO.setUpdateUserName(UserCache.getUserRealName(portTerminal.getUpdateUser()));
|
||||
return portTerminalVO;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ package org.springblade.system.wrapper;
|
||||
|
||||
import org.springblade.core.mp.support.BaseEntityWrapper;
|
||||
import org.springblade.core.tool.utils.BeanUtil;
|
||||
import org.springblade.system.cache.UserCache;
|
||||
import org.springblade.system.pojo.entity.RailwayStation;
|
||||
import org.springblade.system.pojo.vo.RailwayStationVO;
|
||||
|
||||
@@ -45,7 +46,9 @@ public class RailwayStationWrapper extends BaseEntityWrapper<RailwayStation, Rai
|
||||
|
||||
@Override
|
||||
public RailwayStationVO entityVO(RailwayStation railwayStation) {
|
||||
return Objects.requireNonNull(BeanUtil.copyProperties(railwayStation, RailwayStationVO.class));
|
||||
RailwayStationVO railwayStationVO = Objects.requireNonNull(BeanUtil.copyProperties(railwayStation, RailwayStationVO.class));
|
||||
railwayStationVO.setUpdateUserName(UserCache.getUserRealName(railwayStation.getUpdateUser()));
|
||||
return railwayStationVO;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user