package com.goafanti.common.task; import java.util.ArrayList; import java.util.Date; import java.util.List; import javax.annotation.Resource; 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 com.goafanti.common.model.User; import com.goafanti.common.utils.LoggerUtils; 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 customerServiceImpl; @Resource private UserService userServiceImpl; int pointsDataLimit=100; /** * 每天凌晨一点将客户和业务转为待释放 */ // @Scheduled(cron = "0 0 1 * * ?") @RequestMapping(value = "/open/updateUser", method = RequestMethod.GET) public void updateUser(){ try { List userList = userServiceImpl.selectUserByRoleName("营销员","营销经理"); List lockUserList = new ArrayList(); List lockBusinessList = new ArrayList(); List userTmpList = null; List businessTmpList = null; for(User u : userList){ userTmpList = customerServiceImpl.selectWaitReleaseCustomer(u.getId()); // userTmpList = customerServiceImpl.selectWaitReleaseCustomer("1"); lockUserList.addAll(userTmpList); businessTmpList = customerServiceImpl.selectWaitReleaseBusiness(u.getId()); // businessTmpList = customerServiceImpl.selectWaitReleaseBusiness("1"); lockBusinessList.addAll(businessTmpList); } List newList=new ArrayList(); if (lockUserList.size()>0) { for(int i=0;i0) customerServiceImpl.updatePendingReleaseLock(newList); newList.clear(); Thread.sleep(2000); } } } if (lockBusinessList.size()>0) { for(int i=0;i0) customerServiceImpl.updatePendingReleaseLock(newList); newList.clear(); Thread.sleep(2000); } } } /*if(lockUserList.size()>0) customerServiceImpl.updateReleaseLock(lockUserList,releaseTime); if(lockBusinessList.size()>0) customerServiceImpl.updateReleaseLock(lockBusinessList,releaseTime); if(lockUserList.size()>0) userServiceImpl.updateReleaseLock(lockUserList);*/ } catch (Exception e) { LoggerUtils.error(getClass(), "============================================="); LoggerUtils.error(getClass(), "客户标记待释放失败", e); LoggerUtils.error(getClass(), "============================================="); } } /** * 将待释放客户与业务释放 */ // @Scheduled(cron = "0 0 2 * * ?") @RequestMapping(value = "/open/releaseUser", method = RequestMethod.GET) public void releaseUser(){ Date releaseTime = new Date(); try { List lockList=customerServiceImpl.selectPendinglockUserList(); List newList=new ArrayList<>(); List userList=new ArrayList<>(); if (lockList.size()>0) { for(int i=0;i0) customerServiceImpl.updateReleaseLock(newList,releaseTime); newList.clear(); Thread.sleep(2000); } if (lockList.get(i).getType().equals("0")) { userList.add(lockList.get(i)); if(pointsDataLimit == userList.size()||i == lockList.size()-1){ if(userList.size()>0) userServiceImpl.updateReleaseLock(userList); } } } } } catch (Exception e) { LoggerUtils.error(getClass(), "============================================="); LoggerUtils.error(getClass(), "客户释放失败", e); LoggerUtils.error(getClass(), "============================================="); } } }