package weaver.interfaces.htxc.job;

import com.engine.htxc.commonutil.db.DbTools;
import com.engine.htxc.commonutil.log.CustomizeLog;
import com.engine.htxc.workflow.create.business.contract.util.ContractUpdateStatus;
import com.engine.integration.util.StringUtils;
import weaver.general.Util;
import weaver.hrm.User;
import weaver.interfaces.htsc.comInfo.PropBean;
import weaver.interfaces.schedule.BaseCronJob;
import java.util.*;
import static com.engine.htxc.workflow.create.business.contract.init.ContractType.ThePerformanceToComplete;

/**
 *    <p>定时任务触发合同履约</p>
 * @title ContractPerformanceThread
 * @author K1810015
 * @updateTime 2022/8/17 11:19
 */
public class ContractPerformanceThread extends BaseCronJob {
    DbTools dbtools = new DbTools();
    PropBean pb = new PropBean();

    @Override
    public void execute() {
     CustomizeLog.printLog("合同履约办结--开始");
     updatestatus();

    }

    /**
     * <p>定时任务合同履约办结修改状态</p>
     * @title updatestatus
     * @author K1810015
     * @updateTime 2022/8/17 11:19
     */
    public void updatestatus() {

    String tablename=dbtools.getUnnumberToTablename( pb.getPropName("contract.convertion.unnumber"));
        CustomizeLog.printLog("合同履约tablename"+tablename);
    if(StringUtils.isBlank(tablename)){
        return ;
    }
    String  sql="select requestid,ngr from "+tablename+" where (lyjszt!='1' or lyjszt is null) and sysdate>=to_date(lyjs,'yyyy-MM-dd') and lyjs is not null";
    CustomizeLog.printLog("合同履约sql"+sql);
    List<Map<String,Object>> listmap= dbtools.getSqlToList(sql);
    if(listmap==null || listmap.size()<=0){
        return ;
    }
    listmap.forEach((item)->{
        Map<String,Object> map=(HashMap) item;
        String requestid=Util.null2String(map.get("requestid"));
        String ngr=Util.null2String(map.get("ngr"));
        if(!StringUtils.isBlank(requestid) && !StringUtils.isBlank(ngr)){
            Map<String,String> tablesetmap=new HashMap<>(1);
            tablesetmap.put("lyjszt", "1");
            ContractUpdateStatus.createContractUpdateStatus(requestid,new User(Util.getIntValue(ngr,-1)))
                    .modeupdatezt(ThePerformanceToComplete.getValue()).tableUpdateType(tablesetmap);
        }
    });
    }
}
