package com.lz.modules.job.task;

import com.alibaba.fastjson.JSON;
import com.google.common.collect.Lists;
import com.lz.modules.app.entity.StaffEntity;
import com.lz.modules.app.service.StaffService;
import com.lz.modules.job.business.DingtalkBusiness;
import com.lz.modules.performance.enums.ResultFlowProcessEnum;
import com.lz.modules.sys.service.app.ResultRecordService;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author: djc
 * @Desc:
 * @Date: 2020/12/10 10:26
 */

@Component("resultTaskNoticJob")
public class ResultTaskNoticJob implements ITask {
    private Logger logger = LoggerFactory.getLogger(getClass());

    @Autowired
    DingtalkBusiness dingtalkBusiness;
    @Autowired
    private ResultRecordService resultRecordService;
    @Autowired
    private StaffService staffService;

    static final List<Integer> process = Lists.newArrayList(ResultFlowProcessEnum.TARGET.getStatus(), ResultFlowProcessEnum.CONFIRM.getStatus(),
            ResultFlowProcessEnum.DO.getStatus(), ResultFlowProcessEnum.WRITE.getStatus());

    @Override
    public void run(String params) {
        logger.info("绩效任务填写通知开始。。。");
        List<Long> ids = resultRecordService.selectStaffIdsByFlowProcess(process);
        if(CollectionUtils.isNotEmpty(ids)){
            logger.info("通知人员id: " + JSON.toJSONString(ids));
            List<StaffEntity> staffEntities = staffService.selectByIds(ids);
            String res = dingtalkBusiness.sendTaskInputMsg(staffEntities);
            logger.info("绩效任务填写通知响应：" + res);
        }


    }
}
