package com.doumee.biz.system.impl;
|
|
import com.doumee.biz.system.AgreementConfigBiz;
|
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.AgreementConfigDTO;
|
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 AgreementConfigBizImpl implements AgreementConfigBiz {
|
|
@Autowired
|
private SystemDictDataBiz systemDictDataBiz;
|
|
@Override
|
public AgreementConfigDTO getConfig() {
|
AgreementConfigDTO dto = new AgreementConfigDTO();
|
dto.setPrivacyAgreement(getValue(Constants.PRIVACY_AGREEMENT));
|
dto.setUserAgreement(getValue(Constants.USER_AGREEMENT));
|
dto.setAboutUs(getValue(Constants.ABOUT_US));
|
return dto;
|
}
|
|
@Override
|
@Transactional(rollbackFor = {Exception.class, BusinessException.class})
|
public void saveConfig(AgreementConfigDTO dto) {
|
validate(dto);
|
saveOrUpdate(Constants.PRIVACY_AGREEMENT, "隐私协议", dto.getPrivacyAgreement());
|
saveOrUpdate(Constants.USER_AGREEMENT, "用户协议", dto.getUserAgreement());
|
saveOrUpdate(Constants.ABOUT_US, "关于我们", dto.getAboutUs());
|
}
|
|
private String getValue(String label) {
|
SystemDictData data = systemDictDataBiz.queryByCode(Constants.SYSTEM, label);
|
return data != null ? data.getCode() : null;
|
}
|
|
private void saveOrUpdate(String label, String remark, String value) {
|
SystemDictData existing = systemDictDataBiz.queryByCode(Constants.SYSTEM, label);
|
if (existing != null && existing.getId() != null) {
|
existing.setCode(value);
|
systemDictDataBiz.updateById(existing);
|
} else {
|
SystemDictData newData = new SystemDictData();
|
newData.setDictId(100);
|
newData.setLabel(label);
|
newData.setRemark(remark);
|
newData.setCode(value);
|
newData.setDisabled(false);
|
newData.setDeleted(false);
|
systemDictDataBiz.create(newData);
|
}
|
}
|
|
private void validate(AgreementConfigDTO dto) {
|
if (dto == null
|
|| StringUtils.isBlank(dto.getPrivacyAgreement())
|
|| StringUtils.isBlank(dto.getUserAgreement())
|
|| StringUtils.isBlank(dto.getAboutUs())) {
|
throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "所有配置项均为必填");
|
}
|
}
|
}
|