| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396 |
- package com.goafanti.common.task;
- import java.math.BigDecimal;
- import java.util.*;
- import com.goafanti.admin.bo.AdminListBo;
- import com.goafanti.common.bo.ErrorDunListBo;
- import com.goafanti.common.dao.*;
- import com.goafanti.core.shiro.token.TokenManager;
- import com.goafanti.order.bo.*;
- import com.goafanti.order.service.LegalAffairsService;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
- 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.transaction.annotation.Transactional;
- import com.goafanti.common.bo.EmailBo;
- import com.goafanti.common.constant.AFTConstants;
- import com.goafanti.common.enums.NoticeStatus;
- import com.goafanti.common.model.Notice;
- import com.goafanti.common.model.PaymentNode;
- import com.goafanti.common.model.TArrearsDun;
- import com.goafanti.common.model.TOrderMid;
- import com.goafanti.common.model.TOrderNew;
- import com.goafanti.common.utils.AsyncUtils;
- import com.goafanti.common.utils.LoggerUtils;
- import com.goafanti.order.enums.OrderDunProjectType;
- import com.goafanti.order.service.NewOrderDunService;
- import com.goafanti.order.service.OrderNewService;
- import com.goafanti.order.service.OrderProjectService;
- import com.goafanti.organization.bo.OutPaymentNode;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.RequestMethod;
- import org.springframework.web.bind.annotation.RestController;
- @Component
- //@RestController
- public class OrderDunTask {
- @Autowired
- private OrderNewService orderNewService;
- @Autowired
- private NewOrderDunService newOrderDunService;
- @Autowired
- private TOrderNewMapper tOrderNewMapper;
- @Autowired
- private TArrearsDunMapper tArrearsDunMapper;
- @Autowired
- private TOrderMidMapper tOrderMidMapper;
- @Autowired
- private AdminMapper adminMapper;
- @Autowired
- private PaymentNodeMapper paymentNodeMapper;
- @Autowired
- private OrderProjectService orderProjectService;
- @Autowired
- private LegalAffairsService legalAffairsService;
- @Value(value = "${dev.name}")
- private String devName=null;
- @Autowired
- private AsyncUtils asyncUtils;
- Logger logger = LoggerFactory.getLogger(OrderDunTask.class);
- /**
- * 每天凌晨3点轮
- */
- // @ResponseBody
- @Scheduled(cron = "0 0 3 * * ?")
- // @RequestMapping(value = "/open/test", method = RequestMethod.GET)
- // @Scheduled(cron = "0 47 11 * * ?")
- @Transactional(rollbackFor=Exception.class)
- public void startTask() throws InterruptedException {
- updateNewOrderDun();
- Thread.sleep(2000);
- updatePaymentNode();
- Thread.sleep(2000);
- pushLegalAffairs();
- }
- /**
- * 法务订单催款处理
- */
- // @RequestMapping(value = "/open/pushLegalAffairs", method = RequestMethod.GET)
- public void pushLegalAffairs() {
- InputOrderListBo in = new InputOrderListBo();
- in.setType(0);
- in.setLegalAffairs(0);
- List<OutOrderLegalAffairsListBo> list=legalAffairsService.getLegalAffairsOrder(in);
- ArrayList<String> addList = new ArrayList<>();
- Date now=new Date();
- for (OutOrderLegalAffairsListBo out : list) {
- Long l=out.getDunStartTime().getTime()+AFTConstants.DUN_START_LIMIT_MS;
- if (l<now.getTime()){
- addList.add(out.getOrderNo());
- }
- }
- List<String> addList2=new ArrayList<>();
- if (!addList.isEmpty())
- for (int i=0;i<addList.size();i++){
- addList2.add(addList.get(i));
- if (50 == addList2.size() || i == addList.size() - 1){
- tOrderMidMapper.updateByList(addList2);
- legalAffairsService.addLagalAffairsLogList(addList2);
- addList2.clear();
- }
- }
- }
- /**
- * 询处理需要新催款的信息
- */
- // @RequestMapping(value = "/open/updateNewOrderDun", method = RequestMethod.GET)
- public void updateNewOrderDun(){
- try {
- LoggerUtils.debug(logger, "======================新催款任务轮询启动===================");
- List<OutNewOrderDunBo> list= newOrderDunService.selectAllOrderDun();
- Calendar now=Calendar.getInstance();
- Calendar now2=Calendar.getInstance();
- Date date =new Date();
- for (OutNewOrderDunBo o : list) {
- now.setTime(date);
- now2.setTime(o.getCreateTime());
- //计算特批首期款 特批通过 为催款为首期款 催款时间不为空则计算触发
- if (o.getApproval()!=null&& o.getApproval()==2&& o.getDunType()==1&&o.getWaitDay()!=null) {
- now2.add(Calendar.DATE, o.getWaitDay());
- updateOrderDun(o,now,now2);
- //会员-期限计算
- }else if(o.getProjectType().equals(OrderDunProjectType.HY.getCode())&&o.getDunType()==2) {
- now2.add(Calendar.DATE, o.getEffectiveCount()*180);
- CalendarTimeCleared(now2);
- updateOrderDun(o,now,now2);
- //财税-期限 计算时间
- } else if(o.getProjectType().equals(OrderDunProjectType.CS.getCode())&&o.getDunType()==2) {
- //获取年
- int year = now2.get(Calendar.YEAR);
- //获取月份,0表示1月份
- int month = now2.get(Calendar.MONTH) + 1;
- if(month<10)year=year+1;
- if(month>9)year=year+2;
- now2.set(year, 5, 1);
- CalendarTimeCleared(now2);
- updateOrderDun(o,now,now2);
- //自定义 超过设置的时间则触发
- }else if (o.getDunType()==0) {
- now2.setTime(o.getCustomizeTime());
- CalendarTimeCleared(now);
- updateOrderDun(o,now,now2);
- }
- }
- calibrationDun();
- } catch (Exception e) {
- EmailBo emailBo = new EmailBo( "催款处理失败", AFTConstants.ADMIN_EMAIL, "超管", "平台", "系统", devName+"催款处理失败");
- asyncUtils.send(emailBo);
- LoggerUtils.error(getClass(), "===================新催款的信息处理失败======================", e);
- }
- }
- /**
- * 如果有不对的数据就校准数据
- */
- private void calibrationDun() {
- List<ErrorDunListBo> el = tOrderMidMapper.selectErrorDun();
- if (!el.isEmpty()){
- StringBuffer sb=new StringBuffer();
- for (ErrorDunListBo e : el) {
- sb.append(e.toString());
- }
- EmailBo emailBo=new EmailBo("催款异常核对",AFTConstants.ADMIN_EMAIL,sb.toString());
- asyncUtils.send(emailBo);
- tOrderMidMapper.updateErrorDun();
- }
- }
- /**
- * 处理付款催款
- */
- private void updatePaymentNode() {
- LoggerUtils.debug(logger, "======================催款任务结束,付款催款开始===================");
- Calendar now=Calendar.getInstance();
- Calendar now2=Calendar.getInstance();
- try {
- List<OutPaymentNode> list2=paymentNodeMapper.selectByStatus(0);
- for (OutPaymentNode pn : list2) {
- now2.setTime(pn.getCreateTime());
- if(pn.getProjectType().equals(OrderDunProjectType.HY.getCode())&&pn.getDunType()==2) {
- now2.add(Calendar.DATE, pn.getEffectiveCount()*180);
- CalendarTimeCleared(now2);
- }else if(pn.getProjectType().equals(OrderDunProjectType.CS.getCode())&&pn.getDunType()==2) {
- // 获取年
- int year = now2.get(Calendar.YEAR);
- //获取月份,0表示1月份
- int month = now2.get(Calendar.MONTH) + 1;
- if(month<10)year=year+1;
- if(month>9)year=year+2;
- now2.set(year, 5, 1);
- CalendarTimeCleared(now2);
- }else if (pn.getDunType()==0) {
- now2.setTime(pn.getPartyTime());
- CalendarTimeCleared(now);
- }
- if (now.getTimeInMillis() > now2.getTimeInMillis()) {//当前时间大于计算后时间则触发
- updatePaymentNode(pn);
- Thread.sleep(1000);
- }
- }
- } catch (InterruptedException e) {
- LoggerUtils.error(getClass(), "===========================付款催款失败==========================", e);
- }
- }
- /**
- * 每月1号凌晨4点轮询处理需要欠款催款的信息
- *
- */
- @Scheduled(cron = "0 0 4 1 * ?")
- // @RequestMapping(value = "/open/pushOrderArrearsDun", method = RequestMethod.GET)
- public void pushOrderArrearsDun(){
- try {
- LoggerUtils.debug(logger, "======================欠款催款启动===================");
- Date date=new Date();
- //运算 list(未启动) list2(催款中) list3(已完成)订单的欠款催款
- List<TArrearsDun> list=tArrearsDunMapper.selectStatusAll(0);
- List<TArrearsDun> list2=tArrearsDunMapper.selectStatusAll(1);
- List<TArrearsDun> list3=tArrearsDunMapper.selectStatusAndAmount(2);
- for (TArrearsDun td : list) {
- TOrderNewBo b = tOrderNewMapper.getSaleIdByOno(td.getOrderNo());
- AdminListBo a = adminMapper.getDeptNameByAid(TokenManager.getAdminId()==null?"1":TokenManager.getAdminId());
- TOrderMid tm=tOrderMidMapper.selectByOrderNo(td.getOrderNo());
- //如果欠款大于0则需要触发邮件
- if (tm.getOrderArrears().compareTo(new BigDecimal(0))>0) {
- td.setDunStatus(1);
- td.setStartTime(date);
- td.setOrderArrears(tm.getOrderArrears());
- td.setOrderReceivables(tm.getOrderReceivables());
- orderNewService.addNotic(NoticeStatus.ORDER_ARREARS_DUN.getCode(),a,b);
- tArrearsDunMapper.updateByPrimaryKeySelective(td);
- }else if(tm.getOrderArrears().compareTo(new BigDecimal(0))<1) {
- td.setDunStatus(2);
- td.setEndTime(date);
- td.setOrderArrears(tm.getOrderArrears());
- tArrearsDunMapper.updateByPrimaryKeySelective(td);
- }
- Thread.sleep(2000);
- }
- for (TArrearsDun ta : list2) {
- TOrderMid tm=tOrderMidMapper.selectByOrderNo(ta.getOrderNo());
- TOrderNewBo b = tOrderNewMapper.getSaleIdByOno(ta.getOrderNo());
- AdminListBo a = adminMapper.getDeptNameByAid(TokenManager.getAdminId()==null?"1":TokenManager.getAdminId());
- //如果欠款大于0则需要触发邮件
- if (tm.getOrderArrears().compareTo(new BigDecimal(0))>0) {
- ta.setDunStatus(3);
- tArrearsDunMapper.updateByPrimaryKeySelective(ta);
- ta.setId(null);
- ta.setDunStatus(1);
- ta.setStartTime(date);
- ta.setOrderArrears(tm.getOrderArrears());
- ta.setOrderReceivables(tm.getOrderReceivables());
- tArrearsDunMapper.insertSelective(ta);
- orderNewService.addNotic(NoticeStatus.ORDER_ARREARS_DUN.getCode(),a,b);
- }else if(tm.getOrderArrears().compareTo(new BigDecimal(0))<1) {
- ta.setDunStatus(2);
- ta.setOrderArrears(tm.getOrderArrears());
- tArrearsDunMapper.updateByPrimaryKeySelective(ta);
- }
- Thread.sleep(2000);
- }
- for (TArrearsDun ta : list3) {
- TOrderMid tm=tOrderMidMapper.selectByOrderNo(ta.getOrderNo());
- TOrderNewBo b = tOrderNewMapper.getSaleIdByOno(ta.getOrderNo());
- AdminListBo a = adminMapper.getDeptNameByAid(TokenManager.getAdminId()==null?"1":TokenManager.getAdminId());
- //如果欠款大于0则需要触发邮件
- if (tm.getOrderArrears().compareTo(new BigDecimal(0))>0) {
- ta.setDunStatus(3);
- tArrearsDunMapper.updateByPrimaryKeySelective(ta);
- ta.setId(null);
- ta.setDunStatus(1);
- ta.setStartTime(date);
- ta.setOrderArrears(tm.getOrderArrears());
- ta.setOrderReceivables(tm.getOrderReceivables());
- tArrearsDunMapper.insertSelective(ta);
- orderNewService.addNotic(NoticeStatus.ORDER_ARREARS_DUN.getCode(),a,b);
- }else if(tm.getOrderArrears().compareTo(new BigDecimal(0))<1) {
- ta.setDunStatus(2);
- ta.setOrderReceivables(tm.getOrderReceivables());
- ta.setOrderArrears(tm.getOrderArrears());
- tArrearsDunMapper.updateByPrimaryKeySelective(ta);
- }
- Thread.sleep(2000);
- }
- } catch (Exception e) {
- LoggerUtils.error(getClass(), "===========================欠款催款失败==========================", e);
- }
- }
- // /**
- // * 旧催款处理
- // *
- // */
- // public void updateorderDun(){
- // try {
- // LoggerUtils.debug(logger, "======================催款任务轮询启动===================");
- // List<OrderDunTaskBo> list=orderNewService.selectAllOrderDun();
- // for (OrderDunTaskBo t : list) {
- // if (t.getDunSubject()/10==1) {//1则为订单催款信息否则为项目催款信息
- // if (t.getDunSubject()%10==t.getOrderStatus()&&t.getSettlementAmount().compareTo(t.getMoney()) == -1) {
- // updateOrderDun(t);
- // Thread.sleep(2000);
- // }
- // }else {
- // if (t.getDunSubject()%10>=t.getProjectStatus()&&t.getSettlementAmount().compareTo(t.getMoney()) == -1) {
- // updateOrderDun(t);
- // Thread.sleep(2000);
- // }
- // }
- // }
- // } catch (Exception e) {
- // LoggerUtils.error(getClass(), "==========================催款的信息处理失败==========================", e);
- // }
- //
- // }
- private void updatePaymentNode(OutPaymentNode pn) {
- PaymentNode p=new PaymentNode();
- p.setId(pn.getId());
- p.setDunStatus(1);
- p.setStartTime(new Date());
- paymentNodeMapper.updateByPrimaryKeySelective(p);
- orderProjectService.addNoticAndEmail(pn,NoticeStatus.PAYMENT_DUN.getCode());
- }
- private void CalendarTimeCleared(Calendar now) {
- now.set(Calendar.HOUR_OF_DAY, 0);
- now.set(Calendar.MINUTE, 0);
- now.set(Calendar.SECOND, 0);
- now.set(Calendar.MILLISECOND, 0);
- }
- /**
- * 定时催款触发
- * 如果当前时间大于等于触发时间才触发流程
- * @param t
- * @param now 当前时间
- * @param now2 触发时间
- */
- private void updateOrderDun(OutNewOrderDunBo t,Calendar now,Calendar now2) {
- if (now.getTimeInMillis() >= now2.getTimeInMillis()) {
- InputNewOrderDunBo o=new InputNewOrderDunBo();
- TOrderNew orderNew=tOrderNewMapper.selectByPrimaryKey(t.getOrderNo());
- Date date = new Date();
- o.setId(t.getId());
- o.setStatus(1);
- o.setStartTime(date);
- if (t.getMoney()==null)t.setMoney(new BigDecimal(0));
- newOrderDunService.updateDun(o);
- TOrderMid tm=orderNewService.pushOrderMidDun(t.getOrderNo(),orderNew.getSettlementAmount(),date,t);
- TArrearsDun td=new TArrearsDun();
- td.setOrderArrears(tm.getOrderArrears());
- td.setOrderReceivables(tm.getOrderReceivables());
- if (tArrearsDunMapper.checkOrderNo(t.getOrderNo(),null)<1) {
- td.setOrderNo(t.getOrderNo());
- tArrearsDunMapper.insertSelective(td);
- }else if(tArrearsDunMapper.checkOrderNo(t.getOrderNo(),0)>0){
- Integer i=tArrearsDunMapper.selectByStatus(t.getOrderNo(), 0);
- td.setId(i);
- tArrearsDunMapper.updateByPrimaryKeySelective(td);
- }
- orderNewService.addTimingTaskNewDunNoticAndSendEmail(orderNew, t);
- try {
- Thread.sleep(2000);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
- }
- }
|