rk
昨天 fcd0f63ea0a86d5756cf3950f08144e1552a3d4e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
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(), "所有配置项均为必填");
        }
    }
}