ReleaseUserTask.java 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. package com.goafanti.common.task;
  2. import java.io.UnsupportedEncodingException;
  3. import java.util.ArrayList;
  4. import java.util.Date;
  5. import java.util.List;
  6. import java.util.UUID;
  7. import javax.annotation.Resource;
  8. import javax.mail.MessagingException;
  9. import org.springframework.beans.factory.annotation.Autowired;
  10. import org.springframework.scheduling.annotation.Scheduled;
  11. import org.springframework.stereotype.Component;
  12. import org.springframework.stereotype.Controller;
  13. import org.springframework.web.bind.annotation.RequestMapping;
  14. import org.springframework.web.bind.annotation.RequestMethod;
  15. import com.goafanti.common.bo.EmailBo;
  16. import com.goafanti.common.bo.userDaysBo;
  17. import com.goafanti.common.constant.AFTConstants;
  18. import com.goafanti.common.dao.NoticeMapper;
  19. import com.goafanti.common.enums.NoticeStatus;
  20. import com.goafanti.common.model.Notice;
  21. import com.goafanti.common.model.User;
  22. import com.goafanti.common.utils.LoggerUtils;
  23. import com.goafanti.common.utils.SendEmailUtil;
  24. import com.goafanti.common.utils.StringUtils;
  25. import com.goafanti.customer.bo.LockingReleaseBo;
  26. import com.goafanti.customer.service.CustomerService;
  27. import com.goafanti.user.service.UserService;
  28. @Component
  29. @Controller
  30. public class ReleaseUserTask {
  31. @Resource
  32. private CustomerService customerServiceImpl;
  33. @Resource
  34. private UserService userServiceImpl;
  35. @Autowired
  36. private NoticeMapper noticeMapper;
  37. int pointsDataLimit=50;
  38. /**
  39. * 每天凌晨一点
  40. * @throws InterruptedException
  41. */
  42. // @Scheduled(cron = "0 55 15 * * ?")
  43. @Scheduled(cron = "0 0 1 * * ?")
  44. public void startTask() {
  45. try {
  46. pushUserDays();
  47. Thread.sleep(2000);
  48. updateUser();
  49. } catch (InterruptedException e) {
  50. e.printStackTrace();
  51. }
  52. }
  53. @RequestMapping(value = "/open/remindUser", method = RequestMethod.GET)
  54. private void pushUserDays() throws InterruptedException {
  55. LoggerUtils.debug(getClass(), "==============客户提醒开始============");
  56. List<User> userList = userServiceImpl.selectUserByRoleName("营销员","营销经理");
  57. List<userDaysBo> count = new ArrayList<>();
  58. List<userDaysBo> userTmpList = null;
  59. for(User u : userList){
  60. if(StringUtils.isNotBlank(u.getId())) {
  61. userTmpList = customerServiceImpl.selectUserDays(u.getId());
  62. }
  63. if(!userTmpList.isEmpty())count.addAll(userTmpList);
  64. }
  65. List<Notice> ln=new ArrayList<>();
  66. for (userDaysBo ub : count) {
  67. ln.add(new Notice(UUID.randomUUID().toString(),new Date(),0,
  68. ub.getAid(),NoticeStatus.CUSTOMER_PRIVATE_REMINDER.getCode(),"您的客户:"+ub.getName()+",剩余天数不足十五天,请及时跟进或者限时签单!"));
  69. }
  70. List<Notice> newList=new ArrayList<>();
  71. if (ln!=null&&ln.size()>0) {
  72. for(int i=0;i<ln.size();i++){
  73. newList.add(ln.get(i));
  74. if(pointsDataLimit == newList.size()||i == ln.size()-1){
  75. if(newList.size()>0) noticeMapper.insertBatch(newList);
  76. newList.clear();
  77. Thread.sleep(2000);
  78. }
  79. }
  80. }
  81. LoggerUtils.debug(getClass(), "==============客户提醒结束============");
  82. }
  83. /**
  84. *将客户和业务转为待释放
  85. */
  86. @RequestMapping(value = "/open/updateUser", method = RequestMethod.GET)
  87. public void updateUser(){
  88. LoggerUtils.debug(getClass(), "==============客户释放开始============");
  89. Date releaseTime = new Date();
  90. try {
  91. List<User> userList = userServiceImpl.selectUserByRoleName("营销员","营销经理");
  92. List<LockingReleaseBo> lockUserList = new ArrayList<LockingReleaseBo>();
  93. List<LockingReleaseBo> userTmpList = null;
  94. List<LockingReleaseBo> userTmpList2 = null;
  95. if (userList!=null&&!userList.isEmpty()) {
  96. for(User u : userList){
  97. if(StringUtils.isNotBlank(u.getId())) {
  98. //获取30天释放
  99. userTmpList = customerServiceImpl.selectWaitReleaseCustomer(u.getId(),0);
  100. //获取270天释放
  101. userTmpList2 = customerServiceImpl.selectWaitReleaseCustomer(u.getId(),1);
  102. customerServiceImpl.pushReleaseLog(userTmpList,0);
  103. customerServiceImpl.pushReleaseLog(userTmpList2,1);
  104. if(userTmpList!=null&&!userTmpList.isEmpty())lockUserList.addAll(userTmpList);
  105. if(userTmpList2!=null&&!userTmpList2.isEmpty())lockUserList.addAll(userTmpList2);
  106. }
  107. }
  108. }
  109. List<LockingReleaseBo> newList=new ArrayList<LockingReleaseBo>();
  110. if (lockUserList!=null&&lockUserList.size()>0) {
  111. for(int i=0;i<lockUserList.size();i++){
  112. newList.add(lockUserList.get(i));
  113. if(pointsDataLimit == newList.size()||i == lockUserList.size()-1){
  114. if(newList.size()>0) {
  115. customerServiceImpl.updatePendingReleaseLock(newList);
  116. }
  117. newList.clear();
  118. Thread.sleep(2000);
  119. }
  120. }
  121. }
  122. List<LockingReleaseBo> lockList=customerServiceImpl.selectPendinglockUserList();
  123. if (lockList.size()>0)customerServiceImpl.updateReleaseLock(releaseTime);
  124. } catch (Exception e) {
  125. Notice n =new Notice(UUID.randomUUID().toString(),new Date(),0,"1",NoticeStatus.TASK_PATENT_ERROR.getCode(),"==============客户释放失败================");
  126. noticeMapper.insert(n);
  127. EmailBo emailBo = new EmailBo( "释放客户失败", AFTConstants.ADMIN_EMAIL, "超管", "平台", "系统", "释放客户失败");
  128. try {
  129. SendEmailUtil.getInstance().send(emailBo);
  130. } catch (UnsupportedEncodingException | MessagingException e1) {
  131. e1.printStackTrace();
  132. }
  133. LoggerUtils.error(getClass(), "====================客户释放失败=================");
  134. LoggerUtils.error(getClass(), "客户释放失败", e);
  135. }
  136. LoggerUtils.debug(getClass(), "==============客户释放完成============");
  137. }
  138. }