package com.mortals.xhx.daemon.task;

import com.mortals.framework.exception.AppException;
import com.mortals.framework.service.ITask;
import com.mortals.framework.service.ITaskExcuteService;
import com.mortals.xhx.module.staff.dao.StaffDao;
import com.mortals.xhx.module.staff.model.StaffEntity;
import com.mortals.xhx.module.staff.service.StaffService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

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

/**
 * 员工名片日访问数初始化
 */
@Slf4j
@Service("StaffViewsByDayInit")
public class StaffViewsByDayInitTaskImpl implements ITaskExcuteService {
    @Autowired
    private StaffService staffService;

    @Override
    public void excuteTask(ITask task) throws AppException {
        List<StaffEntity> staffEntityList = staffService.getAllList();
        List<StaffEntity> updateList = new ArrayList<>();
        for (StaffEntity entity:staffEntityList){
            StaffEntity update = new StaffEntity();
            update.setId(entity.getId());
            update.setViewsByDay(0);
            updateList.add(update);
        }
        if(updateList.size()>0){
            staffService.update(updateList);
        }
    }

    @Override
    public void stopTask(ITask task) throws AppException {

    }
}
