无关风月
2026-02-25 80f6c17c34dae2c5f9f861e274f4e8d5e2394d5c
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
package com.xiaopeng.operation.service.impl;
 
 
import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xiaopeng.operation.dto.XpAgreementDTO;
import com.xiaopeng.operation.mapper.XpAgreementMapper;
import com.xiaopeng.api.model.operation.XpAgreement;
import com.xiaopeng.operation.service.XpAgreementService;
import com.xiaopeng.operation.vo.XpAgreementVo;
import org.springframework.stereotype.Service;
 
import java.util.*;
 
/**
 * <p>
 * 协议设置 服务实现类
 * </p>
 *
 * @author liu
 * @since 2026-02-03
 */
@Service
public class XpAgreementServiceImpl extends ServiceImpl<XpAgreementMapper, XpAgreement> implements XpAgreementService {
 
    @Override
    public XpAgreementVo getContentByType(Integer type) {
        XpAgreement xpAgreement = this.getOne(new LambdaQueryWrapper<XpAgreement>().eq(XpAgreement::getContentType,type));
        if (xpAgreement != null) {
            XpAgreementVo xpAgreementVo = new XpAgreementVo();
            xpAgreementVo.setId(xpAgreement.getId());
            xpAgreementVo.setContent(xpAgreement.getContent());
            xpAgreementVo.setType(xpAgreement.getContentType());
            xpAgreementVo.setVersion(xpAgreement.getVersion());
            return xpAgreementVo;
        }
        return null;
    }
 
    @Override
    public List<XpAgreementVo> getContentByTypeAll() {
        List<XpAgreement> list = this.list(new LambdaQueryWrapper<XpAgreement>().in(XpAgreement::getContentType, Arrays.asList(1,2,3,4)));
        List<XpAgreementVo> xpAgreementVos = new ArrayList<>();
        for (XpAgreement xpAgreement : list) {
            XpAgreementVo xpAgreementVo = new XpAgreementVo();
            xpAgreementVo.setId(xpAgreement.getId());
            xpAgreementVo.setContent(xpAgreement.getContent());
            xpAgreementVo.setType(xpAgreement.getContentType());
            xpAgreementVo.setVersion(xpAgreement.getVersion());
            xpAgreementVos.add(xpAgreementVo);
        }
        return xpAgreementVos;
    }
 
    /**
     * 根据类型获取配置
     * @param type
     * @return
     */
    @Override
    public XpAgreement getAgreementContent(Integer type) {
        return this.lambdaQuery().eq(XpAgreement::getContentType, type).last("limit 1").one();
    }
 
    @Override
    public void saveAgreement(XpAgreementDTO dto) {
        //根据类型查询协议
        Optional<XpAgreement> opt = this.lambdaQuery().eq(XpAgreement::getContentType, dto.getContentType()).last("limit 1").oneOpt();
 
        //如果存在则更新,不存在则新增
        if (opt.isPresent()) {
            XpAgreement xpAgreement = opt.get();
            xpAgreement.setContent(dto.getContent());
            updateById(xpAgreement);
        } else {
            XpAgreement xpAgreement = BeanUtil.copyProperties(dto, XpAgreement.class);
            this.save(xpAgreement);
        }
    }
}