package com.doumee.biz.system.impl;
|
|
import com.doumee.biz.system.OperationConfigBiz;
|
import com.doumee.biz.system.SystemDictDataBiz;
|
import com.doumee.core.constants.Constants;
|
import com.doumee.core.constants.ResponseStatus;
|
import com.doumee.core.exception.BusinessException;
|
import com.doumee.dao.dto.OperationConfigDTO;
|
import com.doumee.dao.system.model.SystemDictData;
|
import org.apache.commons.lang3.StringUtils;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
|
/**
|
* 运营配置业务实现
|
* @author rk
|
* @date 2026/04/13
|
*/
|
@Service
|
public class OperationConfigBizImpl implements OperationConfigBiz {
|
|
@Autowired
|
private SystemDictDataBiz systemDictDataBiz;
|
|
@Override
|
public OperationConfigDTO getConfig() {
|
OperationConfigDTO dto = new OperationConfigDTO();
|
dto.setDriverDailyCancelLimit(getValue(Constants.OP_DRIVER_DAILY_CANCEL_LIMIT));
|
dto.setUnpickedDiscount(getValue(Constants.OP_UNPICKED_DISCOUNT));
|
dto.setSettlementDate(getValue(Constants.OP_SETTLEMENT_DATE));
|
dto.setUrgentCoefficient(getValue(Constants.OP_URGENT_COEFFICIENT));
|
dto.setAutoCancelTime(getValue(Constants.OP_AUTO_CANCEL_TIME));
|
dto.setInsuranceRate(getValue(Constants.OP_INSURANCE_RATE));
|
dto.setOrderAcceptLimit(getValue(Constants.OP_ORDER_ACCEPT_LIMIT));
|
dto.setAutoConfirmReceipt(getValue(Constants.OP_AUTO_CONFIRM_RECEIPT));
|
return dto;
|
}
|
|
@Override
|
@Transactional(rollbackFor = {Exception.class, BusinessException.class})
|
public void saveConfig(OperationConfigDTO dto) {
|
validate(dto);
|
saveOrUpdate(Constants.OP_DRIVER_DAILY_CANCEL_LIMIT, "司机每日取消次数", dto.getDriverDailyCancelLimit());
|
saveOrUpdate(Constants.OP_UNPICKED_DISCOUNT, "未取件折扣", dto.getUnpickedDiscount());
|
saveOrUpdate(Constants.OP_SETTLEMENT_DATE, "订单结算日期", dto.getSettlementDate());
|
saveOrUpdate(Constants.OP_URGENT_COEFFICIENT, "加急系数", dto.getUrgentCoefficient());
|
saveOrUpdate(Constants.OP_AUTO_CANCEL_TIME, "超时未支付自动取消时间", dto.getAutoCancelTime());
|
saveOrUpdate(Constants.OP_INSURANCE_RATE, "保费比率", dto.getInsuranceRate());
|
saveOrUpdate(Constants.OP_ORDER_ACCEPT_LIMIT, "接单数量", dto.getOrderAcceptLimit());
|
saveOrUpdate(Constants.OP_AUTO_CONFIRM_RECEIPT, "自动确认收货", dto.getAutoConfirmReceipt());
|
}
|
|
private String getValue(String label) {
|
SystemDictData data = systemDictDataBiz.queryByCode(Constants.OPERATION_CONFIG, label);
|
return data != null ? data.getCode() : null;
|
}
|
|
private void saveOrUpdate(String label, String name, String value) {
|
SystemDictData existing = systemDictDataBiz.queryByCode(Constants.OPERATION_CONFIG, label);
|
if (existing != null && existing.getId() != null) {
|
existing.setCode(value);
|
systemDictDataBiz.updateById(existing);
|
} else {
|
SystemDictData newData = new SystemDictData();
|
newData.setDictId(105);
|
newData.setLabel(label);
|
newData.setRemark(name);
|
newData.setCode(value);
|
newData.setDisabled(false);
|
newData.setDeleted(false);
|
systemDictDataBiz.create(newData);
|
}
|
}
|
|
private void validate(OperationConfigDTO dto) {
|
if (dto == null
|
|| StringUtils.isBlank(dto.getDriverDailyCancelLimit())
|
|| StringUtils.isBlank(dto.getUnpickedDiscount())
|
|| StringUtils.isBlank(dto.getSettlementDate())
|
|| StringUtils.isBlank(dto.getUrgentCoefficient())
|
|| StringUtils.isBlank(dto.getAutoCancelTime())
|
|| StringUtils.isBlank(dto.getInsuranceRate())
|
|| StringUtils.isBlank(dto.getOrderAcceptLimit())
|
|| StringUtils.isBlank(dto.getAutoConfirmReceipt())) {
|
throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "所有配置项均为必填");
|
}
|
}
|
}
|