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

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.unified.supplier.AccountingOrderUnifiedSupplierQueryCriteria;
import cn.superdesk.uniorder.dto.vo.accounting.unified.supplier.AccountingOrderUnifiedSupplierListItemVo;
import cn.superdesk.uniorder.service.accounting.unified.supplier.AccountingUnifiedSupplierService;
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/20 12:14 下午
 * @UpdateUser: linjinyu
 * @UpdateDate: 2022/5/20 12:14 下午
 * @UpdateRemark: 修改内容
 * @Version: 1.0
 */
@Slf4j
@Component
@RequiredArgsConstructor
public class AccountingOrderUnifiedSupplierTask {

    private final AccountingUnifiedSupplierService accountingUnifiedSupplierService;

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

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

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

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

        resultList = accountingUnifiedSupplierService.queryAccountingOrderUnifiedSupplierList(

                AccountingOrderUnifiedSupplierQueryCriteria
                        .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));

        accountingUnifiedSupplierService.patchNeedReviseMarkStatistics(resultList, loginSysUser);


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

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

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

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

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

        resultList = accountingUnifiedSupplierService.queryAccountingOrderUnifiedSupplierList(

                AccountingOrderUnifiedSupplierQueryCriteria
                        .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));

        accountingUnifiedSupplierService.patchNeedReviseMarkServiceNoSourceFrom(resultList, loginSysUser);

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