package org.dromara.payment.timer;

import cn.hutool.core.date.DateUtil;
import com.xxl.job.core.handler.annotation.XxlJob;
import org.dromara.payment.bill.mapper.MerBillDetailMapper;
import org.dromara.payment.worker.domain.UserWorkerBill;
import org.dromara.payment.worker.mapper.UserWorkerBillMapper;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author sunzexing
 * @version 1.0
 * @title CntWorkerBillInfoJob
 * @description
 * @create 2024-09-03 16:54
 */


@Component
public class CntWorkerBillInfoJob {

    @Resource
    public UserWorkerBillMapper userWorkerBillMapper;


    @XxlJob("CntWorkerBillInfoJob")
    public void updateInfo(){
        Date currentDate = new Date();
        Date startTime = DateUtil.beginOfYear(currentDate);
        Date endTime = DateUtil.endOfYear(currentDate);

        Map paraMap = new HashMap();
        paraMap.put("startTime",startTime);
        paraMap.put("endTime",endTime);

        List<UserWorkerBill> list = this.userWorkerBillMapper.selectCurentDayWorkerBillInfo(paraMap);
        int dtmYear = DateUtil.year(currentDate);
        for(UserWorkerBill bill : list){
            paraMap.clear();
            paraMap.put("workerId",bill.getWorkerId());
            paraMap.put("sydId",bill.getSydId());
            paraMap.put("busType",bill.getBusType());
            paraMap.put("merId",bill.getMerId());
            paraMap.put("dtmYear",dtmYear);
            this.userWorkerBillMapper.deleteUserWorkerBillByInfo(paraMap);
            bill.setDtmYear(dtmYear+"");
            this.userWorkerBillMapper.insert(bill);
        }




    }
}
