ZrTask.java 4.3 KB
package com.chinagas.modules.job.task;

import com.chinagas.api.fksb.RemoteFksbService;
import com.chinagas.api.mcsb.RemoteMcsbService;
import com.chinagas.api.system.RemoteDataSyncService;
import com.chinagas.common.core.constants.Constants;
import com.chinagas.common.core.domain.R;
import com.chinagas.common.security.utils.SecurityUtils;
import com.chinagas.modules.job.mapper.SysJobMapper;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.util.Random;

/**
 * @ClassName ZrTask
 * @Author lidengwei
 * @Description TODO
 * @CreateTime 2022/10/13 16:08
 */
@Component("ZrTask")
public class ZrTask {

    @Autowired
    private RemoteDataSyncService dataSyncService;

    @Autowired
    private RemoteMcsbService mcsbService;

    @Autowired
    private RemoteFksbService fksbService;

    @Autowired
    private SysJobMapper sysJobMapper;


    public void syncOrgData(String ifacecode) throws JobExecutionException, IOException {
        R<Integer> res = dataSyncService.dataSync(ifacecode);
        if(Constants.FAIL.equals(res.getCode())){
            throw new JobExecutionException(res.getMsg());
        }
    }

    /**
     * 定时修改密码
     */
    public void syncUpdatePassword(){
        String randomString = generateRandomString(12);
        sysJobMapper.updateUserPassword(SecurityUtils.encryptPassword(randomString));
    }

    private static final String LOWER_CASE = "abcdefghijklmnopqrstuvwxyz";
    private static final String UPPER_CASE = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    private static final String DIGITS = "0123456789";
    private static final String SPECIAL_CHARACTERS = "!@#$%^&*()-_=+[{]}\\|;:'\",<.>/?";

    public static String generateRandomString(int length) {
        StringBuilder sb = new StringBuilder(length);
        Random random = new Random();

        // 确保至少包含一个小写字母、大写字母、数字和特殊字符
        sb.append(getRandomChar(LOWER_CASE, random));
        sb.append(getRandomChar(UPPER_CASE, random));
        sb.append(getRandomChar(DIGITS, random));
        sb.append(getRandomChar(SPECIAL_CHARACTERS, random));

        // 填充剩余的字符
        for (int i = 4; i < length; i++) {
            String charSet = LOWER_CASE + UPPER_CASE + DIGITS + SPECIAL_CHARACTERS;
            char nextChar = getRandomChar(charSet, random);
            // 避免连续的字符
            if (i > 0 && sb.charAt(i - 1) == nextChar) {
                do {
                    nextChar = getRandomChar(charSet, random);
                } while (sb.charAt(i - 1) == nextChar);
            }
            sb.append(nextChar);
        }

        // 打乱顺序以避免连续的字符
        shuffle(sb, random);

        return sb.toString();
    }

    private static char getRandomChar(String charSet, Random random) {
        int index = random.nextInt(charSet.length());
        return charSet.charAt(index);
    }

    private static void shuffle(StringBuilder sb, Random random) {
        for (int i = sb.length() - 1; i > 0; i--) {
            int j = random.nextInt(i + 1);
            char temp = sb.charAt(i);
            sb.setCharAt(i, sb.charAt(j));
            sb.setCharAt(j, temp);
        }
    }



//    //读取财务报表excel文件
//    public void readMcsbExcel() throws JobExecutionException {
//        R<Integer> res = mcsbService.readMcsbExcel();
//        if(Constants.FAIL.equals(res.getCode())){
//            throw new JobExecutionException(res.getMsg());
//        }
//    }
//
//    //读取非控股公司指标报表excel文件
//    public void readFksbExcel() throws JobExecutionException {
//        R<Integer> res = fksbService.readFksbExcel();
//        if(Constants.FAIL.equals(res.getCode())){
//            throw new JobExecutionException(res.getMsg());
//        }
//    }

//    public void ysEntitySync() throws JobExecutionException{
//        R<Integer> res = dataSyncService.ysEntitySync();
//        if(Constants.FAIL.equals(res.getCode())){
//            throw new JobExecutionException(res.getMsg());
//        }
//    }

//    public void sendFestivalMsg(){
//        remoteCustomerService.sendFestivalMsg();
//    }
//
//    public void sendBirthdayMsg(){
//        remoteCustomerService.sendBirthdayMsg();
//    }

}