AutoWork.java 5.28 KB
Newer Older
Zhou Yang's avatar
Zhou Yang committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156
package com.hmit.kernes.auto;

import com.hmit.kernes.entity.AppAnnounceEntity;
import com.hmit.kernes.entity.AppAnnounceMapEntity;
import com.hmit.kernes.entity.CloudChairmanInfoEntity;
import com.hmit.kernes.entity.ZhghClickCountEntity;
import com.hmit.kernes.service.AppAnnounceService;
import com.hmit.kernes.service.CloudBaseInfoService;
import com.hmit.kernes.service.CloudChairmanInfoService;
import com.hmit.kernes.service.ZhghClickCountService;
import com.hmit.kernes.utils.CaiyunUtil;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.io.File;
import java.util.*;

@Component
@EnableScheduling
public class AutoWork {

    @Autowired
    CloudChairmanInfoService cloudChairmanInfoService;
    @Autowired
    private CloudBaseInfoService cloudBaseInfoService;
    @Autowired
    ZhghClickCountService zhghClickCountService;
    @Autowired
    AppAnnounceService appAnnounceService;

/*

    @Scheduled(cron = "0/5 * * * * ?")
    public void dodo(){
        System.out.println(new Date());
    }

*/



    @Scheduled(cron = "0 0 5 * * ?")  // 每天5点,正式用
   //@Scheduled(cron = "0/5 * * * * ?") //测试用
    public void createTomorrow(){
      
        Date date=new Date();
        Calendar calendar=new GregorianCalendar();
        calendar.setTime(date);
        calendar.add(calendar.DATE,1);
        date=calendar.getTime();

        ZhghClickCountEntity z=new ZhghClickCountEntity();
        java.sql.Date sqlDate=new java.sql.Date(date.getTime());
        z.setcTime(sqlDate);
        z.setAppClick(0);
        z.setWebClick(0);
        z.setWeixin(0);

        zhghClickCountService.save(z);


    }
    @Scheduled(cron = "0 15 5 * * ?")
    public void qToday(){
        List<ZhghClickCountEntity> list= zhghClickCountService.queryToday();
        if(list.size()==0 || list.isEmpty()){
            Date date=new Date();
            java.sql.Date sqlDate=new java.sql.Date(date.getTime());
            ZhghClickCountEntity z=new ZhghClickCountEntity();
            z.setcTime(sqlDate);
            z.setAppClick(0);
            z.setWebClick(0);
            z.setWeixin(0);
            zhghClickCountService.save(z);
        }
    }
    @Scheduled(cron = "0 5 8 * * ?")
   //@Scheduled(cron = "0 0/1 * * * ?") //测试用
    public void updateAppAndWx(){

        ZhghClickCountEntity zhghClickCountEntity=new ZhghClickCountEntity();
        zhghClickCountEntity.setAppClick(CaiyunUtil.getUserListSize());
        zhghClickCountEntity.setWeixin(CaiyunUtil.getWX());
        Date date=new Date();
        java.sql.Date dd=new java.sql.Date(date.getTime());
        zhghClickCountEntity.setcTime(dd);
        Map<String,Object> map=new HashMap<>();
        map.put("day1",3);
        map.put("day2",60);
        List<Map> mapList=cloudBaseInfoService.getInfoCount(map);
        int i=Integer.parseInt(mapList.get(0).get("sun").toString())+Integer.parseInt(mapList.get(1).get("sun").toString());
        zhghClickCountEntity.setInfo(i);
        zhghClickCountService.updateAppAll(zhghClickCountEntity);

    }



    @Scheduled(cron = "0 15 6 * * ?")
    public void annPushMsg(){
        List<AppAnnounceEntity> list=appAnnounceService.queryTodayAnn();
        String title ="您今天有一个会议安排";
        String action="183.247.237.44:8288/cy/cyLogin";
        if(list.size()>0 & !list.isEmpty()){
            for(AppAnnounceEntity ap:list){
                String contex=ap.getActName();
                List<String> receList=new ArrayList<>();
                if(contex.length()>=20)
                    contex=contex.substring(0,15)+"...";
                List<AppAnnounceMapEntity> maplist=ap.getList();
                for(AppAnnounceMapEntity apmap:maplist){
                    String tel=apmap.getReceiveTel();
                    if(!StringUtils.isBlank(tel)){
                        receList.add(tel);
                    }
                }
                CaiyunUtil.pushMsgToUser(title,contex,action,receList);
            }
        }
    }


    @Scheduled(cron = "0 0 5 * * ?")
    public void autoCardCalculate() {
        List<CloudChairmanInfoEntity> list= cloudChairmanInfoService.queryBirthday();

        if(list!=null &&list.size()>0){
            List<String> stringList=new ArrayList<>();
            String title="happy birthday";
            String content="happy birthday";
            String action=" ";
            for(CloudChairmanInfoEntity c:list) {
                stringList.add(c.getTel());
            }
            CaiyunUtil.pushMsgToUser(title,content,action,stringList);
        }

    }

    @Scheduled(cron = "0 0 5 2 1/1 ?")
    public void autoDel() {
       // C:\web\tomcat\webapps\ROOT\doc\img
        File dir=new File("C:/web/tomcat/webapps/ROOT/doc/img");//这里需要绝对路径
        File[] lst=dir.listFiles();
        for (File f:lst){
            if (new Date().getTime()-f.lastModified()>24*60*60*1000*30*6) {//自动删除6个月前的
                f.delete();
            }
        }
    }


}