CertDictServiceImpl.java
5.11 KB
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
package com.subsidy.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.subsidy.dto.cert.AddCertDTO;
import com.subsidy.dto.cert.GetAllCertsDTO;
import com.subsidy.dto.cert.GetOneCertDTO;
import com.subsidy.mapper.*;
import com.subsidy.model.*;
import com.subsidy.service.CertDictService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.subsidy.service.CertTypeDictService;
import com.subsidy.util.ConstantUtils;
import com.subsidy.vo.cert.GetAllCertsVO;
import com.subsidy.vo.cert.GetAllCertsWithoutTypeVO;
import com.subsidy.vo.cert.GetOneCertVO;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.List;
/**
* <p>
* 证书字典表 服务实现类
* </p>
*
* @author DengMin
* @since 2022-05-11
*/
@Service
public class CertDictServiceImpl extends ServiceImpl<CertDictMapper, CertDictDO> implements CertDictService {
@Autowired
private CertTypeMappingMapper certTypeMappingMapper;
@Autowired
private CertTypeDictMapper certTypeDictMapper;
@Autowired
private CertRequirementMapper certRequirementMapper;
@Autowired
private CertMemberMappingMapper certMemberMappingMapper;
@Transactional(rollbackFor = Exception.class)
public String addCert(AddCertDTO addCertDTO) {
CertDictDO certDictDO = new CertDictDO();
BeanUtils.copyProperties(addCertDTO, certDictDO);
this.baseMapper.insert(certDictDO);
List<Long> list = addCertDTO.getTypeIds();
for (Long lg : list) {
CertTypeMappingDO certTypeMappingDO = new CertTypeMappingDO();
certTypeMappingDO.setCertId(certDictDO.getId());
certTypeMappingDO.setTypeId(lg);
certTypeMappingMapper.insert(certTypeMappingDO);
}
return ConstantUtils.ADD_SUCCESS;
}
@Transactional(rollbackFor = Exception.class)
public String deleteCert(CertDictDO certDictDO) {
//删除证书
this.baseMapper.deleteById(certDictDO.getId());
//删除证书类目映射关系
certTypeMappingMapper.delete(new QueryWrapper<CertTypeMappingDO>()
.lambda()
.eq(CertTypeMappingDO::getCertId,certDictDO.getId()));
//删除证书相关条件
certRequirementMapper.delete(new QueryWrapper<CertRequirementDO>()
.lambda()
.eq(CertRequirementDO::getCertId,certDictDO.getId()));
return ConstantUtils.DELETE_SUCCESS;
}
public String updateCert(AddCertDTO addCertDTO) {
CertDictDO certDictDO = new CertDictDO();
BeanUtils.copyProperties(addCertDTO, certDictDO);
this.baseMapper.updateById(certDictDO);
if (addCertDTO.getTypeIds().size() > 0) {
certTypeMappingMapper.delete(new QueryWrapper<CertTypeMappingDO>()
.lambda()
.eq(CertTypeMappingDO::getCertId, addCertDTO.getId()));
List<Long> list = addCertDTO.getTypeIds();
for (Long lg : list) {
CertTypeMappingDO certTypeMappingDO = new CertTypeMappingDO();
certTypeMappingDO.setCertId(certDictDO.getId());
certTypeMappingDO.setTypeId(lg);
certTypeMappingMapper.insert(certTypeMappingDO);
}
}
return ConstantUtils.SET_SUCCESS;
}
public GetOneCertVO getOneCert(GetOneCertDTO getOneCertDTO) {
GetOneCertVO getOneCertVO = new GetOneCertVO();
CertDictDO certDictDO1 = this.baseMapper.selectById(getOneCertDTO.getId());
BeanUtils.copyProperties(certDictDO1, getOneCertVO);
//查看证书有哪些类型
List<CertTypeDictDO> certTypeDictDOS = certTypeDictMapper.getCertTypes(certDictDO1.getId());
getOneCertVO.setCertTypeDictDOS(certTypeDictDOS);
Integer count = certMemberMappingMapper.memberCertStatus(getOneCertDTO.getUserId(),certDictDO1.getId());
if (count > 0){
getOneCertVO.setStatus(true);
}else {
getOneCertVO.setStatus(false);
}
return getOneCertVO;
}
public IPage<GetAllCertsVO> getAllCerts(GetAllCertsDTO getAllCertsDTO) {
Page pager = new Page(getAllCertsDTO.getPageNum(), getAllCertsDTO.getPageSize());
IPage<GetAllCertsVO> getAllCertsVOIPage = this.baseMapper.getAllCerts(pager,getAllCertsDTO.getTypeId(),getAllCertsDTO.getCertName());
List<GetAllCertsVO> getAllCertsVOS = getAllCertsVOIPage.getRecords();
for (GetAllCertsVO gav : getAllCertsVOS){
List<CertTypeDictDO> certTypeDictDOS = certTypeDictMapper.getCertTypes(gav.getId());
gav.setCertTypeDictDOS(certTypeDictDOS);
}
return getAllCertsVOIPage;
}
public List<GetAllCertsWithoutTypeVO> getAllCertsWithoutType(){
return this.baseMapper.getAllCertsWithoutType();
}
}