package xiaoqu.home.open.task;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import xiaoqu.home.open.model.db2.TaskDistrictParam;
import xiaoqu.home.open.model.db2.TaskUser;
import xiaoqu.home.open.service.RedisService4;
import xiaoqu.home.open.service.RedisService5;
import xiaoqu.home.open.service.db2.TaskDistrictParamService;
import xiaoqu.home.open.utils.WrapperUtils;

@Component
@Slf4j(topic = "task")
public class BeaconTask {

    @Autowired
    private RedisService5 redisService5;
    @Autowired
    private TaskDistrictParamService taskDistrictParamService;


    @Scheduled(cron = "* * * * * ?")
    public void setBeaconNoToDB() {
        String districtId = redisService5.rightPop("DistrictBeaconNoChange");
        while (districtId != null) {
            String beaconNo = redisService5.get("DistrictBeaconNo:" + districtId);
            if(beaconNo!=null){
                log.info("【setBeaconNoToDB】"+districtId+":"+beaconNo);
                UpdateWrapper<TaskDistrictParam> taskParamwrapper = WrapperUtils.getUpdateWrapper(false);
//        QueryWrapper<TaskUser> taskUserwrapper = WrapperUtils.getWrapper(false);
//                taskUserwrapper.in("task_id",taskIds);
                taskParamwrapper.eq("district_id",districtId);

                taskParamwrapper.set("beacon_no",beaconNo);
                taskDistrictParamService.update(taskParamwrapper);
            }
            districtId = redisService5.rightPop("DistrictBeaconNoChange");
        }

    }

}
