| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278 |
- package com.goafanti.common.task;
- import java.io.UnsupportedEncodingException;
- import java.util.ArrayList;
- import java.util.Date;
- import java.util.List;
- import java.util.UUID;
- import javax.annotation.Resource;
- import javax.mail.MessagingException;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.beans.factory.annotation.Value;
- import org.springframework.scheduling.annotation.Scheduled;
- import org.springframework.stereotype.Component;
- import org.springframework.stereotype.Controller;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.RequestMethod;
- import org.springframework.web.bind.annotation.ResponseBody;
- import com.goafanti.common.bo.EmailBo;
- import com.goafanti.common.bo.userDaysBo;
- import com.goafanti.common.constant.AFTConstants;
- import com.goafanti.common.dao.NoticeMapper;
- import com.goafanti.common.enums.NoticeStatus;
- import com.goafanti.common.enums.NoticeTypes;
- import com.goafanti.common.model.Notice;
- import com.goafanti.common.model.User;
- import com.goafanti.common.utils.AsyncUtils;
- import com.goafanti.common.utils.LoggerUtils;
- import com.goafanti.common.utils.StringUtils;
- import com.goafanti.customer.bo.LockingReleaseBo;
- import com.goafanti.customer.service.CustomerService;
- import com.goafanti.user.service.UserService;
- @Component
- @Controller
- public class ReleaseUserTask {
- @Resource
- private CustomerService customerService;
- @Resource
- private UserService userService;
- @Autowired
- private NoticeMapper noticeMapper;
- @Autowired
- private AsyncUtils asyncUtils;
- @Value(value = "${dev.name}")
- private String devName=null;
-
- int pointsDataLimit = 50;
- /**
- * 每天凌晨一点
- *
- * @throws InterruptedException
- */
- // @Scheduled(cron = "0 55 15 * * ?")
- @Scheduled(cron = "0 0 1 * * ?")
- public void startTask() {
- try {
- pushUserDays();
- Thread.sleep(2000);
- updateUser();
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
- @ResponseBody
- @RequestMapping(value = "/open/remindUser", method = RequestMethod.GET)
- private void pushUserDays() throws InterruptedException {
- LoggerUtils.debug(getClass(), "==============客户提醒开始============");
- List<User> userList = userService.selectUserByRoleName("营销员", "营销经理");
- List<userDaysBo> userTmpList = null;
- List<Notice> ln = new ArrayList<>();
- for (User u : userList) {
- if (StringUtils.isNotBlank(u.getId())) {
- userTmpList = customerService.selectReleaseUserDays(u.getId());
- for (userDaysBo ub : userTmpList) {
- String str=null;
- if (ub.getChannel() == 0) {
- str = String.format("您的%s客户【%s】剩余天数不足十五天,请及时%s!",
- "私有", ub.getName(),ub.getType()==0?"跟进":"签单");
-
- }else {
- str = String.format("您的%s客户【%s】剩余天数不足十五天,请及时签单!", "渠道", ub.getName());
- }
- ln.add(new Notice(UUID.randomUUID().toString(), new Date(), 0, ub.getAid(),
- NoticeStatus.CUSTOMER_LOSE_REMINDER.getCode(), str,ub.getUid()));
- }
- }
- }
- //查询15天未跟进,私有跟释放前15天重复,去除
- List<userDaysBo> userChannelList = new ArrayList<userDaysBo>();
- for (User u : userList) {
- if (StringUtils.isNotBlank(u.getId())) {
-
- userChannelList = customerService.selectChannelNotFollow(u.getId());
- }
- for (userDaysBo ub : userChannelList) {
- String str=null;
- if (ub.getChannel() == 1) {
- str = String.format("您的%s客户【%s】已经十五天未跟进,请及时跟进或者限时签单!", "渠道", ub.getName());
- }
- ln.add(new Notice(UUID.randomUUID().toString(), new Date(), 0, ub.getAid(),
- NoticeStatus.CUSTOMER_PRIVATE_REMINDER.getCode(), str,ub.getUid()));
- }
- }
- addNoticeBatch(ln);
- LoggerUtils.debug(getClass(), "==============客户提醒结束============");
- }
- /**
- * 将客户和业务转为待释放
- */
- @RequestMapping(value = "/open/updateUser", method = RequestMethod.GET)
- public void updateUser() {
- LoggerUtils.debug(getClass(), "==============客户释放开始============");
- Date releaseTime = new Date();
- try {
- List<User> userList = userService.selectUserByRoleName("营销员", "营销经理");
- List<LockingReleaseBo> lockUserList = new ArrayList<LockingReleaseBo>();
- if (userList != null && !userList.isEmpty()) {
- for (User u : userList) {
- List<LockingReleaseBo> userTmpList = null;
- List<LockingReleaseBo> userTmpList2 = null;
- if (StringUtils.isNotBlank(u.getId())) {
- // 获取30天释放
- userTmpList = customerService.selectWaitReleaseCustomer(u.getId(), 0);
- // 获取270天释放
- if(!u.getId().equals("734092ad-6564-4021-b7ab-aab5af3a1537")){
- userTmpList2 = customerService.selectWaitReleaseCustomer(u.getId(), 1);
- customerService.pushReleaseLog(userTmpList2, 1);
- }
- addUserNotice(userTmpList,userTmpList2);
- //
- customerService.pushReleaseLog(userTmpList, 0);
- if (userTmpList != null && !userTmpList.isEmpty())
- lockUserList.addAll(userTmpList);
- if (userTmpList2 != null && !userTmpList2.isEmpty())
- lockUserList.addAll(userTmpList2);
- }
- }
- }
- List<LockingReleaseBo> newList = new ArrayList<LockingReleaseBo>();
- if (lockUserList != null && lockUserList.size() > 0) {
- for (int i = 0; i < lockUserList.size(); i++) {
- newList.add(lockUserList.get(i));
- if (pointsDataLimit == newList.size() || i == lockUserList.size() - 1) {
- if (newList.size() > 0) {
- customerService.updatePendingReleaseLock(newList);
- }
- newList.clear();
- Thread.sleep(2000);
- }
- }
- }
- // 获取超过90天客户,判断是否回收过,未回收则回收,已回收则释放为公共客户
- List<userDaysBo> userChannelList =null;
- List<userDaysBo> count =new ArrayList<userDaysBo>();
- if (userList != null && !userList.isEmpty()) {
- for (User u : userList) {
- userChannelList=customerService.selectChannelUserDays(u.getId());
- if (userChannelList!=null) {
- count.addAll(userChannelList);
- }
- }
- }
- List<userDaysBo> hsList=new ArrayList<>();
- List<userDaysBo> sfList=new ArrayList<>();
- if (count != null && count.size() > 0) {
- for (int i = 0; i < count.size(); i++) {
- //回收
- if (count.get(i).getRecovery()==0) {
- hsList.add(count.get(i));
- }else {
- sfList.add(count.get(i));
- }
- if (pointsDataLimit == (hsList.size()+sfList.size()) || i == count.size() - 1) {
- if(!hsList.isEmpty())userService.pushReleaseUserChannel(hsList,0);
- if(!sfList.isEmpty())userService.pushReleaseUserChannel(sfList,1);
- addChannelNotice(hsList,sfList);
- hsList.clear();
- sfList.clear();
- Thread.sleep(2000);
- }
- }
- }
- List<LockingReleaseBo> lockList = customerService.selectPendinglockUserList();
- if (lockList.size() > 0)
- customerService.updateReleaseLock(releaseTime);
- } catch (Exception e) {
- Notice n = new Notice(UUID.randomUUID().toString(), new Date(), 0, "1",
- NoticeStatus.TASK_PATENT_ERROR.getCode(), "==============客户释放失败================",null);
- addNotice(n);
- EmailBo emailBo = new EmailBo("释放客户失败", AFTConstants.ADMIN_EMAIL, "超管", "平台", "系统", devName+"释放客户失败");
- try {
- asyncUtils.send(emailBo);
- } catch (UnsupportedEncodingException | MessagingException e1) {
- e1.printStackTrace();
- }
- LoggerUtils.error(getClass(), "====================客户释放失败=================");
- LoggerUtils.error(getClass(), "客户释放失败", e);
- }
- LoggerUtils.debug(getClass(), "==============客户释放完成============");
- }
-
- public void addNotice(Notice n ) {
- n.setType(NoticeTypes.getType(n.getNoticeType()));
- noticeMapper.insertSelective(n);
- }
-
- public void addNoticeBatch(List<Notice> ln) {
- List<Notice> newList=new ArrayList<Notice>();
- if (ln != null && ln.size() > 0) {
- for (int i = 0; i < ln.size(); i++) {
- ln.get(i).setType(NoticeTypes.getType(ln.get(i).getNoticeType()));
- newList.add(ln.get(i));
- if (50 == newList.size() || i == ln.size() - 1) {
- if (newList.size() > 0) noticeMapper.insertBatch(newList);
- newList.clear();
- try {
- Thread.sleep(2000);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
- }
- }
- }
- private void addUserNotice(List<LockingReleaseBo> userTmpList, List<LockingReleaseBo> userTmpList2) {
- List<Notice> nl=new ArrayList<Notice>();
- if (!userTmpList.isEmpty()) {
- for (LockingReleaseBo u : userTmpList) {
- nl.add(new Notice(UUID.randomUUID().toString(), new Date(), 0, u.getAid(),
- NoticeStatus.CUSTOMER_LOSE30.getCode(),
- String.format("您的%s客户【%s】已经30天未跟进,已经自动释放!", "私有", u.getUserName()),
- u.getUid()));
- }
- }
- if (!userTmpList2.isEmpty()) {
- for (LockingReleaseBo u : userTmpList2) {
- nl.add(new Notice(UUID.randomUUID().toString(), new Date(), 0, u.getAid(),
- NoticeStatus.CUSTOMER_LOSE270.getCode(),
- String.format("您的%s客户【%s】已经270天未签单,已经自动释放!", "私有", u.getUserName()),
- u.getUid()));
- }
- }
- if(!nl.isEmpty())addNoticeBatch(nl);
- }
-
-
-
-
- private void addChannelNotice(List<userDaysBo> hsList, List<userDaysBo> sfList) {
- List<Notice> nl=new ArrayList<Notice>();
- for (userDaysBo hs : hsList) {
- nl.add(new Notice(UUID.randomUUID().toString(), new Date(), 0, hs.getAid(),
- NoticeStatus.CUSTOMER_CHENNEL_RECOVERY.getCode(),
- String.format("您的%s客户【%s】已经90天未跟进,已经自动回收!", "渠道", hs.getName()),
- hs.getUid()));
- }
-
- for (userDaysBo sf : sfList) {
- nl.add(new Notice(UUID.randomUUID().toString(), new Date(), 0, sf.getAid(),
- NoticeStatus.CUSTOMER_CHENNEL_LOSE.getCode(),
- String.format("您的%s客户【%s】已经90天未跟进,已经自动释放!", "渠道", sf.getName()),
- sf.getUid()));
- }
- if(!nl.isEmpty())addNoticeBatch(nl);
- }
- }
|