package cn.superdesk.uniorder.executor.scheduler.xxljob.accounting.customer;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import cn.superdesk.uniorder.common.enums.common.CommonNeedReviseMarkEnum;
import cn.superdesk.uniorder.common.security.dto.LoginSysUser;
import cn.superdesk.uniorder.dto.param.accounting.score.customer.AccountingOrderScoreCustomerQueryCriteria;
import cn.superdesk.uniorder.dto.vo.accounting.score.customer.AccountingOrderScoreCustomerListItemVo;
import cn.superdesk.uniorder.service.accounting.score.customer.AccountingScoreCustomerService;
import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @Description: Java类作用描述
 * @Author: linjinyu
 * @CreateDate: 2022/5/19 7:11 下午
 * @UpdateUser: linjinyu
 * @UpdateDate: 2022/5/19 7:11 下午
 * @UpdateRemark: 修改内容
 * @Version: 1.0
 */
@Slf4j
@Component
@RequiredArgsConstructor
public class AccountingOrderScoreCustomerTask {

    private final AccountingScoreCustomerService accountingScoreCustomerService;

    /**
     * 补丁类
     */
    @XxlJob("AccountingOrderScoreCustomerPatchNeedReviseMarkStatistics")
    public void patchNeedReviseMarkStatistics() {

        String jobParam = XxlJobHelper.getJobParam();
        log.info("XxlJob patchNeedReviseMarkStatistics jobParam : {}", jobParam);

        List<AccountingOrderScoreCustomerListItemVo> resultList = null;
        LoginSysUser loginSysUser = LoginSysUser
                .builder()
                .sysUserId(996L)
                .fullName("任务执行者")
                .sysUserName("xxljob")
                .build();

        /**************************************** 任务开始 start ****************************************/

        resultList = accountingScoreCustomerService.getAccountingOrderList(
                AccountingOrderScoreCustomerQueryCriteria
                        .builder()
                        .needReviseMark(CommonNeedReviseMarkEnum.修正.getKey())

                        .pageNumber(1)
                        .pageSize(100)

                        .build(),
                loginSysUser
        );

        Integer taskSize = CollUtil.isEmpty(resultList) ? 0 : resultList.size();

        XxlJobHelper.log(StrUtil.format("任务 patchNeedReviseMarkStatistics size {}", taskSize));

        accountingScoreCustomerService.patchNeedReviseMarkStatistics(resultList, loginSysUser);


        /**************************************** 任务开始   end ****************************************/
    }

    /**
     * 补丁类
     */
    @XxlJob("AccountingOrderScoreCustomerPatchNeedReviseMarkInvoiceStatus")
    public void patchNeedReviseMarkInvoiceStatus() {

        String jobParam = XxlJobHelper.getJobParam();
        log.info("XxlJob patchNeedReviseMarkInvoiceStatus jobParam : {}", jobParam);

        List<AccountingOrderScoreCustomerListItemVo> resultList = null;
        LoginSysUser loginSysUser = LoginSysUser
                .builder()
                .sysUserId(996L)
                .fullName("任务执行者")
                .sysUserName("xxljob")
                .build();

        /**************************************** 任务开始 start ****************************************/

        resultList = accountingScoreCustomerService.getAccountingOrderList(
                AccountingOrderScoreCustomerQueryCriteria
                        .builder()
                        .needReviseMark(CommonNeedReviseMarkEnum.修数据_20220518.getKey())

                        .pageNumber(1)
                        .pageSize(100)

                        .build(),
                loginSysUser
        );

        Integer taskSize = CollUtil.isEmpty(resultList) ? 0 : resultList.size();

        XxlJobHelper.log(StrUtil.format("任务 patchNeedReviseMarkInvoiceStatus size {}", taskSize));

        accountingScoreCustomerService.patchNeedReviseMarkInvoiceStatus(resultList, loginSysUser);


        /**************************************** 任务开始   end ****************************************/
    }

    /**
     * 补丁类
     */
    @XxlJob("AccountingOrderScoreCustomerPatchNeedReviseMarkMailTickStatus")
    public void patchNeedReviseMarkMailTickStatus() {

        String jobParam = XxlJobHelper.getJobParam();
        log.info("XxlJob patchNeedReviseMarkMailTickStatus jobParam : {}", jobParam);

        List<AccountingOrderScoreCustomerListItemVo> resultList = null;
        LoginSysUser loginSysUser = LoginSysUser
                .builder()
                .sysUserId(996L)
                .fullName("任务执行者")
                .sysUserName("xxljob")
                .build();

        /**************************************** 任务开始 start ****************************************/

        resultList = accountingScoreCustomerService.getAccountingOrderList(
                AccountingOrderScoreCustomerQueryCriteria
                        .builder()
                        .needReviseMark(CommonNeedReviseMarkEnum.修数据_20220505.getKey())

                        .pageNumber(1)
                        .pageSize(100)

                        .build(),
                loginSysUser
        );

        Integer taskSize = CollUtil.isEmpty(resultList) ? 0 : resultList.size();

        XxlJobHelper.log(StrUtil.format("任务 patchNeedReviseMarkMailTickStatus size {}", taskSize));

        accountingScoreCustomerService.patchNeedReviseMarkMailTickStatus(resultList, loginSysUser);


        /**************************************** 任务开始   end ****************************************/
    }

    /**
     * 补丁类
     */
    @XxlJob("AccountingOrderScoreCustomerPatchNeedReviseMarkServiceNoSourceFrom")
    public void patchNeedReviseMarkServiceNoSourceFrom() {

        String jobParam = XxlJobHelper.getJobParam();
        log.info("XxlJob patchNeedReviseMarkServiceNoSourceFrom jobParam : {}", jobParam);

        List<AccountingOrderScoreCustomerListItemVo> resultList = null;
        LoginSysUser loginSysUser = LoginSysUser
                .builder()
                .sysUserId(996L)
                .fullName("任务执行者")
                .sysUserName("xxljob")
                .build();

        /**************************************** 任务开始 start ****************************************/

        resultList = accountingScoreCustomerService.getAccountingOrderList(
                AccountingOrderScoreCustomerQueryCriteria
                        .builder()
                        .needReviseMark(CommonNeedReviseMarkEnum.修数据_20220519.getKey())

                        .pageNumber(1)
                        .pageSize(100)

                        .build(),
                loginSysUser
        );

        Integer taskSize = CollUtil.isEmpty(resultList) ? 0 : resultList.size();

        XxlJobHelper.log(StrUtil.format("任务 patchNeedReviseMarkServiceNoSourceFrom size {}", taskSize));

        accountingScoreCustomerService.patchNeedReviseMarkServiceNoSourceFrom(resultList, loginSysUser);


        /**************************************** 任务开始   end ****************************************/
    }
}
