EmailServiceImpl.java
4.47 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
package com.cnlive.shenhe.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.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 {
private static Logger logger = LoggerFactory.getLogger(EmailServiceImpl.class);
@Autowired
ShyEmailMapper shyEmailMapper;
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;
}
public ShyEmail get(Integer id) {
return shyEmailMapper.selectByPrimaryKey(id);
}
public ShyEmail select(ShyEmail shyEmail) {
return shyEmailMapper.selectOne(shyEmail);
}
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);
}
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);
}
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);
if (re != 1) {
return false;
}
}
} 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);
if (re != 1) {
return false;
}
}
return true;
}
/**
* 通过邮件发送类型,获取需要发送邮件的list
* @param emailSendType
* @return
*/
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;
}
}