zelong.shao

kafka|反向匹配通知邮件

...@@ -2,6 +2,7 @@ package com.fedex.connect.kafka.repository.base; ...@@ -2,6 +2,7 @@ package com.fedex.connect.kafka.repository.base;
2 2
3 import com.fedex.connect.common.dao.biz.CeInfoMapper; 3 import com.fedex.connect.common.dao.biz.CeInfoMapper;
4 import com.fedex.connect.common.dao.biz.ConsignmentMapper; 4 import com.fedex.connect.common.dao.biz.ConsignmentMapper;
5 +import com.fedex.connect.common.dao.biz.EmailMapper;
5 import com.fedex.connect.common.dao.sys.KafkaStorageHistoryMapper; 6 import com.fedex.connect.common.dao.sys.KafkaStorageHistoryMapper;
6 import com.fedex.connect.common.dao.sys.KafkaTemporaryStorageMapper; 7 import com.fedex.connect.common.dao.sys.KafkaTemporaryStorageMapper;
7 import com.fedex.connect.kafka.repository.dao.CeInfoMapperExt; 8 import com.fedex.connect.kafka.repository.dao.CeInfoMapperExt;
...@@ -24,4 +25,6 @@ public class BaseRepository { ...@@ -24,4 +25,6 @@ public class BaseRepository {
24 protected KafkaTemporaryStorageMapperExt kafkaTemporaryStorageMapperExt; 25 protected KafkaTemporaryStorageMapperExt kafkaTemporaryStorageMapperExt;
25 @Autowired 26 @Autowired
26 protected UserMapperExt userMapperExt; 27 protected UserMapperExt userMapperExt;
28 + @Autowired
29 + protected EmailMapper emailMapper;
27 } 30 }
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -20,4 +20,9 @@ public interface UserMapperExt { ...@@ -20,4 +20,9 @@ public interface UserMapperExt {
20 "SELECT * FROM T_SYS_USER WHERE USER_UUID = #{uuid} AND ROWNUM <= 1" + 20 "SELECT * FROM T_SYS_USER WHERE USER_UUID = #{uuid} AND ROWNUM <= 1" +
21 "</script>") 21 "</script>")
22 User findUserByUUid(@Param("uuid") String uuid); 22 User findUserByUUid(@Param("uuid") String uuid);
23 +
24 + @Select( "<script>" +
25 + "SELECT * FROM T_SYS_USER WHERE ID = #{id}" +
26 + "</script>")
27 + User selectUserById(@Param("id") Long id);
23 } 28 }
...\ No newline at end of file ...\ No newline at end of file
......
1 +package com.fedex.connect.kafka.repository.repo;
2 +
3 +import com.fedex.connect.common.model.biz.Email;
4 +
5 +public interface IEmailRepository {
6 + void save(Email entity);
7 +}
...@@ -4,4 +4,5 @@ import com.fedex.connect.common.model.sys.User; ...@@ -4,4 +4,5 @@ import com.fedex.connect.common.model.sys.User;
4 4
5 public interface IUserRepository { 5 public interface IUserRepository {
6 User findUserByUUid(String uuid); 6 User findUserByUUid(String uuid);
7 + User selectUserById(Long id);
7 } 8 }
......
1 +package com.fedex.connect.kafka.repository.repo.impl;
2 +
3 +import com.fedex.connect.common.model.biz.Email;
4 +import com.fedex.connect.kafka.repository.base.BaseRepository;
5 +import com.fedex.connect.kafka.repository.repo.IEmailRepository;
6 +import org.springframework.stereotype.Repository;
7 +
8 +@Repository
9 +public class EmailRepositoryImpl extends BaseRepository implements IEmailRepository {
10 + public void save(Email entity){
11 + if(entity != null) {
12 + if (entity.getId() == null || entity.getId() <= 0) {
13 + emailMapper.insertSelective(entity);
14 + } else if (entity.getId() != null && entity.getId() > 0){
15 + emailMapper.updateByPrimaryKeySelective(entity);
16 + }
17 + }
18 + }
19 +}
...@@ -23,4 +23,9 @@ public class UserRepositoryImpl extends BaseRepository implements IUserRepositor ...@@ -23,4 +23,9 @@ public class UserRepositoryImpl extends BaseRepository implements IUserRepositor
23 public User findUserByUUid(String uuid) { 23 public User findUserByUUid(String uuid) {
24 return userMapperExt.findUserByUUid(uuid); 24 return userMapperExt.findUserByUUid(uuid);
25 } 25 }
26 +
27 + @Override
28 + public User selectUserById(Long id){
29 + return userMapperExt.selectUserById(id);
30 + }
26 } 31 }
......
...@@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSONObject; ...@@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSONObject;
4 import com.fedex.connect.common.dependencies.util.Utils; 4 import com.fedex.connect.common.dependencies.util.Utils;
5 import com.fedex.connect.common.model.biz.CeInfo; 5 import com.fedex.connect.common.model.biz.CeInfo;
6 import com.fedex.connect.common.model.biz.Consignment; 6 import com.fedex.connect.common.model.biz.Consignment;
7 +import com.fedex.connect.common.model.biz.Email;
7 import com.fedex.connect.common.model.sys.KafkaTemporaryStorage; 8 import com.fedex.connect.common.model.sys.KafkaTemporaryStorage;
8 import com.fedex.connect.kafka.data.dto.DmProcessResults; 9 import com.fedex.connect.kafka.data.dto.DmProcessResults;
9 import com.fedex.connect.kafka.data.dto.dm.dm501.Dm501Consignments; 10 import com.fedex.connect.kafka.data.dto.dm.dm501.Dm501Consignments;
...@@ -14,7 +15,6 @@ import com.fedex.connect.kafka.util.Dm501Util; ...@@ -14,7 +15,6 @@ import com.fedex.connect.kafka.util.Dm501Util;
14 import lombok.extern.slf4j.Slf4j; 15 import lombok.extern.slf4j.Slf4j;
15 import org.springframework.beans.factory.annotation.Autowired; 16 import org.springframework.beans.factory.annotation.Autowired;
16 import org.springframework.stereotype.Service; 17 import org.springframework.stereotype.Service;
17 -import org.springframework.transaction.annotation.Transactional;
18 18
19 import java.util.List; 19 import java.util.List;
20 import java.util.Objects; 20 import java.util.Objects;
...@@ -55,11 +55,12 @@ public class Dm501ServiceImpl extends BaseService implements IDm501Service { ...@@ -55,11 +55,12 @@ public class Dm501ServiceImpl extends BaseService implements IDm501Service {
55 if (Objects.isNull(bizCeInfo)) { 55 if (Objects.isNull(bizCeInfo)) {
56 CeInfo ceInfo = dm501Util.generateCeInfo(consignment501,kafKaTemporaryStorage.getSendTime()); 56 CeInfo ceInfo = dm501Util.generateCeInfo(consignment501,kafKaTemporaryStorage.getSendTime());
57 //ce数据解析正常,进行后续操作 57 //ce数据解析正常,进行后续操作
58 - Consignment consignment = dm501Util.generateConsignment(ceInfo); 58 + Email email = new Email();
59 + Consignment consignment = dm501Util.generateConsignment(ceInfo,email);
59 /** 60 /**
60 * 保存ce信息、以及运单表信息 61 * 保存ce信息、以及运单表信息
61 */ 62 */
62 - dm501Util.saveCeInfoAndConsignment(ceInfo,consignment); 63 + dm501Util.saveCeInfoAndConsignment(ceInfo,consignment,email);
63 } 64 }
64 }catch(Exception ex){ 65 }catch(Exception ex){
65 log.error("DM501消息处理异常:{}", ex.getMessage(),ex); 66 log.error("DM501消息处理异常:{}", ex.getMessage(),ex);
......
1 package com.fedex.connect.kafka.util; 1 package com.fedex.connect.kafka.util;
2 2
3 import com.fedex.connect.common.dependencies.cache.CacheSystem; 3 import com.fedex.connect.common.dependencies.cache.CacheSystem;
4 +import com.fedex.connect.common.dependencies.enums.biz.EmailStatusEnum;
5 +import com.fedex.connect.common.dependencies.enums.biz.EmailTypeEnum;
4 import com.fedex.connect.common.dependencies.util.AssignmentFieldUtils; 6 import com.fedex.connect.common.dependencies.util.AssignmentFieldUtils;
5 import com.fedex.connect.common.dependencies.util.DateUtil; 7 import com.fedex.connect.common.dependencies.util.DateUtil;
6 import com.fedex.connect.common.model.bi.DictionaryEntries; 8 import com.fedex.connect.common.model.bi.DictionaryEntries;
7 import com.fedex.connect.common.model.biz.CeInfo; 9 import com.fedex.connect.common.model.biz.CeInfo;
8 import com.fedex.connect.common.model.biz.Consignment; 10 import com.fedex.connect.common.model.biz.Consignment;
11 +import com.fedex.connect.common.model.biz.Email;
9 import com.fedex.connect.common.model.sys.User; 12 import com.fedex.connect.common.model.sys.User;
10 import com.fedex.connect.kafka.constants.Constant; 13 import com.fedex.connect.kafka.constants.Constant;
11 import com.fedex.connect.kafka.data.dto.dm.dm501.Dm501ConAddresses; 14 import com.fedex.connect.kafka.data.dto.dm.dm501.Dm501ConAddresses;
12 import com.fedex.connect.kafka.data.dto.dm.dm501.Dm501Consignments; 15 import com.fedex.connect.kafka.data.dto.dm.dm501.Dm501Consignments;
13 import com.fedex.connect.kafka.repository.repo.ICeInfoRepository; 16 import com.fedex.connect.kafka.repository.repo.ICeInfoRepository;
14 import com.fedex.connect.kafka.repository.repo.IConsignmentRepository; 17 import com.fedex.connect.kafka.repository.repo.IConsignmentRepository;
18 +import com.fedex.connect.kafka.repository.repo.IEmailRepository;
15 import com.fedex.connect.kafka.repository.repo.IUserRepository; 19 import com.fedex.connect.kafka.repository.repo.IUserRepository;
16 import org.apache.commons.lang3.StringUtils; 20 import org.apache.commons.lang3.StringUtils;
17 import org.springframework.beans.BeanUtils; 21 import org.springframework.beans.BeanUtils;
...@@ -23,6 +27,7 @@ import java.math.BigDecimal; ...@@ -23,6 +27,7 @@ import java.math.BigDecimal;
23 import java.util.Date; 27 import java.util.Date;
24 import java.util.List; 28 import java.util.List;
25 import java.util.Objects; 29 import java.util.Objects;
30 +import java.util.Optional;
26 31
27 @Component 32 @Component
28 public class Dm501Util { 33 public class Dm501Util {
...@@ -35,6 +40,8 @@ public class Dm501Util { ...@@ -35,6 +40,8 @@ public class Dm501Util {
35 ICeInfoRepository ceInfoRepository; 40 ICeInfoRepository ceInfoRepository;
36 @Autowired 41 @Autowired
37 IUserRepository userRepository; 42 IUserRepository userRepository;
43 + @Autowired
44 + IEmailRepository emailRepository;
38 45
39 /** 46 /**
40 * @Author mt 47 * @Author mt
...@@ -197,7 +204,7 @@ public class Dm501Util { ...@@ -197,7 +204,7 @@ public class Dm501Util {
197 * @param ceInfo 204 * @param ceInfo
198 * @return com.fedex.connect.common.model.biz.Consignment 205 * @return com.fedex.connect.common.model.biz.Consignment
199 */ 206 */
200 - public Consignment generateConsignment(CeInfo ceInfo) throws Exception{ 207 + public Consignment generateConsignment(CeInfo ceInfo,Email email) throws Exception{
201 Consignment rsConsignment; 208 Consignment rsConsignment;
202 /** 209 /**
203 * 根据运单号查找30天之内运单 210 * 根据运单号查找30天之内运单
...@@ -206,10 +213,6 @@ public class Dm501Util { ...@@ -206,10 +213,6 @@ public class Dm501Util {
206 if(Objects.isNull(consignment)){ 213 if(Objects.isNull(consignment)){
207 Consignment resultConsignment = new Consignment(); 214 Consignment resultConsignment = new Consignment();
208 BeanUtils.copyProperties(ceInfo,resultConsignment); 215 BeanUtils.copyProperties(ceInfo,resultConsignment);
209 - //运单状态赋值为"待上传"
210 -// DictionaryEntries consignmentDicEntries = cacheSystem.getDicConsignmentStatus(ConsignmentStatusEnum.CONSIGNMENT_STATUS_01.getCode());
211 -// resultConsignment.setStatusCode(consignmentDicEntries.getCode());
212 -// resultConsignment.setStatusName(consignmentDicEntries.getEnglishName());
213 /** 216 /**
214 * 初始化运单表原产国、目的国 217 * 初始化运单表原产国、目的国
215 */ 218 */
...@@ -228,6 +231,10 @@ public class Dm501Util { ...@@ -228,6 +231,10 @@ public class Dm501Util {
228 AssignmentFieldUtils.assignmentTableBaseField(resultConsignment); 231 AssignmentFieldUtils.assignmentTableBaseField(resultConsignment);
229 rsConsignment = resultConsignment; 232 rsConsignment = resultConsignment;
230 }else{ 233 }else{
234 + /**
235 + * 初始化提醒邮件
236 + */
237 + this.initNotificationEmail(email,consignment,ceInfo);
231 //ceInfo转换为consignment忽略字段 238 //ceInfo转换为consignment忽略字段
232 String[] ignoreProperties = Constant.CE_CONSIGNMENT_COPY_IGNORE_PROP_KEYS.IGNORE_PROPERTIES; 239 String[] ignoreProperties = Constant.CE_CONSIGNMENT_COPY_IGNORE_PROP_KEYS.IGNORE_PROPERTIES;
233 //字段拷贝 240 //字段拷贝
...@@ -241,6 +248,31 @@ public class Dm501Util { ...@@ -241,6 +248,31 @@ public class Dm501Util {
241 return rsConsignment; 248 return rsConsignment;
242 } 249 }
243 250
251 + private void initNotificationEmail(Email email,Consignment consignment,CeInfo ceInfo) throws Exception{
252 + /**
253 + * 初始化提醒发件人邮件
254 + */
255 + User userOld = userRepository.selectUserById(consignment.getSubmitterId());
256 + if (StringUtils.isEmpty(consignment.getUserUuid()) && !userOld.getUserUuid().equals(ceInfo.getUserUuid())){
257 + /**
258 + * 初始化Email对象
259 + */
260 + email.setBizId(consignment.getId());
261 + email.setBizCode(consignment.getConsignmentCode());
262 + String emailAddress = Optional.ofNullable(ceInfo.getUserUuid())
263 + .map(userRepository::findUserByUUid)
264 + .map(user -> StringUtils.defaultIfEmpty(user.getEmail(), ceInfo.getShipperEmail()))
265 + .orElse(consignment.getShipperEmail());
266 + email.setToAddress(emailAddress);
267 + email.setSubject("");
268 + email.setTypeName(EmailTypeEnum.NOTIFICATION_SENDER.getMsg());
269 + email.setTypeCode(EmailTypeEnum.NOTIFICATION_SENDER.getCode());
270 + email.setStatusName(EmailStatusEnum.PENDING.getMsg());
271 + email.setStatusCode(EmailStatusEnum.PENDING.getCode());
272 + AssignmentFieldUtils.assignmentTableBaseField(email);
273 + }
274 + }
275 +
244 /** 276 /**
245 * @Author mt 277 * @Author mt
246 * @Description 初始化运单表原产国、目的国 278 * @Description 初始化运单表原产国、目的国
...@@ -297,10 +329,16 @@ public class Dm501Util { ...@@ -297,10 +329,16 @@ public class Dm501Util {
297 * @return void 329 * @return void
298 */ 330 */
299 @Transactional(rollbackFor = Exception.class) 331 @Transactional(rollbackFor = Exception.class)
300 - public void saveCeInfoAndConsignment(CeInfo ceInfo, Consignment consignment){ 332 + public void saveCeInfoAndConsignment(CeInfo ceInfo, Consignment consignment,Email email){
301 ceInfoRepository.save(ceInfo); 333 ceInfoRepository.save(ceInfo);
302 //绑定ceInfo表Id 334 //绑定ceInfo表Id
303 consignment.setCeInfoId(ceInfo.getId()); 335 consignment.setCeInfoId(ceInfo.getId());
304 consignmentRepository.save(consignment); 336 consignmentRepository.save(consignment);
337 + /**
338 + * 保存入库
339 + */
340 + if (email != null){
341 + emailRepository.save(email);
342 + }
305 } 343 }
306 } 344 }
......