EmailServiceImpl.java
5.58 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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
package com.cnlive.shenhe.service.serviceImpl;
import com.alibaba.fastjson.JSON;
import com.cnlive.shenhe.dto.EmailDTO;
import com.cnlive.shenhe.entity.ShyEmail;
import com.cnlive.shenhe.mapper.ShyEmailMapper;
import com.cnlive.shenhe.service.EmailService;
import com.cnlive.shenhe.utils.CommonUtils;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
* @Auther: 周伟鹏
* @Date: 2018/11/29 14:23
* @Description:
*/
@Service
public class EmailServiceImpl implements EmailService {
private static Logger logger = LoggerFactory.getLogger(EmailServiceImpl.class);
@Autowired
ShyEmailMapper shyEmailMapper;
/**
* 获取 分页 条件查询的结果集
*
* @param emailDTO
* @return
*/
@Override
public PageInfo<ShyEmail> getPage(EmailDTO emailDTO) {
logger.info("接受参数列表为:{}", JSON.toJSONString(emailDTO));
Example example = new Example(ShyEmail.class);
Example.Criteria criteria = example.createCriteria();
if (CommonUtils.isNotEmpty(emailDTO.getOrderByClause())) {
example.setOrderByClause(emailDTO.getOrderByClause());
} else {
example.setOrderByClause("created_at desc");
}
if (CommonUtils.isNotEmpty(emailDTO.getRemark())) {
criteria.andLike("remark", "%" + emailDTO.getRemark() + "%");
}
if (CommonUtils.isNotEmpty(emailDTO.getEmail())) {
criteria.andLike("email", "%" + emailDTO.getEmail() + "%");
}
criteria.andEqualTo("is_delete", false);
PageHelper.startPage(emailDTO.getPage(), emailDTO.getPageSize(), true);
List<ShyEmail> shyEmailList = shyEmailMapper.selectByExample(example);
PageInfo<ShyEmail> pageInfo = new PageInfo<ShyEmail>(shyEmailList);
return pageInfo;
}
/**
* 根据主键id查询对象
*
* @param id
* @return
*/
@Override
public ShyEmail get(Integer id) {
return shyEmailMapper.selectByPrimaryKey(id);
}
/**
* 根据条件查询对象
*
* @param shyEmail
* @return
*/
@Override
public ShyEmail select(ShyEmail shyEmail) {
return shyEmailMapper.selectOne(shyEmail);
}
/**
* 修改状态
*
* @param id
* @param isEnable
* @param userId
* @return
*/
@Override
public Integer updateState(Integer id, Boolean isEnable, String userId) {
ShyEmail shyEmail = get(id);
shyEmail.setIs_enable(isEnable);
shyEmail.setUpdater(userId);
shyEmail.setUpdated_at(CommonUtils.getCurrentTime());
return shyEmailMapper.updateByPrimaryKeySelective(shyEmail);
}
/**
* 删除
*
* @param id
* @param userId
* @return
*/
@Override
public Integer deleted(Integer id, String userId) {
ShyEmail shyEmail = get(id);
shyEmail.setUpdater(userId);
shyEmail.setIs_delete(true);
shyEmail.setUpdated_at(CommonUtils.getCurrentTime());
return shyEmailMapper.updateByPrimaryKeySelective(shyEmail);
}
/**
* 修改
*
* @param id
* @param email
* @param remark
* @param write
* @param updater
* @return
*/
@Override
public boolean update(Integer id, String email, String remark, String write, String updater) {
ShyEmail shyEmail = new ShyEmail();
if (CommonUtils.isNotNull(id)) {
shyEmail.setId(id);
shyEmail = shyEmailMapper.selectOne(shyEmail);
if (shyEmail != null) {
shyEmail.setEmail(email);
shyEmail.setRemark(remark);
shyEmail.setNotice_type(write);
shyEmail.setUpdater(updater);
shyEmail.setUpdated_at(CommonUtils.getCurrentTime());
int re = shyEmailMapper.updateByPrimaryKeySelective(shyEmail);
return re == 1;
}
} else {
shyEmail.setEmail(email);
shyEmail.setIs_delete(false);
shyEmail.setIs_enable(true);
shyEmail.setNotice_type(write);
shyEmail.setRemark(remark);
shyEmail.setUpdater(updater);
shyEmail.setCreated_at(CommonUtils.getCurrentTime());
shyEmail.setUpdated_at(CommonUtils.getCurrentTime());
int re = shyEmailMapper.insertSelective(shyEmail);
return re == 1;
}
return true;
}
/**
* 通过邮件发送类型,获取需要发送邮件的list
*
* @param emailSendType
* @return
*/
@Override
public List<ShyEmail> getEmailSendList(Integer emailSendType) {
ShyEmail shyEmail = new ShyEmail();
shyEmail.setIs_delete(false);
shyEmail.setIs_enable(true);
List<ShyEmail> shyEmailList = shyEmailMapper.select(shyEmail);
List<ShyEmail> emailList = new ArrayList<ShyEmail>();
for (ShyEmail shyEmail2 : shyEmailList) {
if (CommonUtils.isNotEmpty(shyEmail2.getNotice_type())) {
String[] business = shyEmail2.getNotice_type().split(",");
List<String> asList = Arrays.asList(business);
if (asList.contains(emailSendType + "")) {
emailList.add(shyEmail2);
}
}
}
return emailList;
}
}