package vip.xiaonuo.Timer;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import vip.xiaonuo.common.timer.CommonTimerTaskRunner;
import vip.xiaonuo.modular.ai.dailyInspection.entity.DailyInspection;
import vip.xiaonuo.modular.ai.dailyInspection.service.DailyInspectionService;
import vip.xiaonuo.sys.modular.user.entity.SysUser;
import vip.xiaonuo.sys.modular.user.service.SysUserService;

import javax.annotation.Resource;
import java.util.List;

@Slf4j
@Component
public class DailyInspectionTimer implements CommonTimerTaskRunner {

    @Resource
    private SysUserService sysUserService;

    @Resource
    private DailyInspectionService dailyInspectionService;


    @Override
    public void action() {
        List<SysUser> list = sysUserService.list(new QueryWrapper<SysUser>().lambda().isNotNull(SysUser::getWorkLocationId));
        if (ObjectUtil.isNotEmpty(list)){
            for (SysUser sysUser : list) {
                String[] workLocations = sysUser.getWorkLocationId().split(",");
                for (String workLocation : workLocations) {
                    System.out.println("用户id为:" + sysUser.getId());
                    System.out.println("单元id为:" + workLocation);
                    DailyInspection dailyInspection = new DailyInspection();
                    dailyInspection.setUnitId(workLocation);
                    dailyInspection.setNotifierId(sysUser.getId());
                    dailyInspectionService.save(dailyInspection);
                }
            }
        }
    }
}
