package com.jpsoft.shinestar.mq.listener;

import com.jpsoft.shinestar.modules.base.entity.PersonDeviceRelation;
import com.jpsoft.shinestar.modules.base.entity.PersonInfo;
import com.jpsoft.shinestar.modules.base.service.PersonDeviceRelationService;
import com.jpsoft.shinestar.modules.base.service.PersonInfoService;
import com.jpsoft.shinestar.modules.business.entity.GuestInfoRecord;
import com.jpsoft.shinestar.modules.business.entity.RequestForLeaveInfo;
import com.jpsoft.shinestar.modules.business.service.GuestInfoRecordService;
import com.jpsoft.shinestar.modules.business.service.RequestForLeaveInfoService;
import com.jpsoft.shinestar.modules.pacs.dto.PacsMsgResult;
import com.jpsoft.shinestar.modules.pacs.service.IGuardService;
import com.jpsoft.shinestar.modules.sys.service.SysLogService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.List;

@Slf4j
@Component
@RabbitListener(queues = "updateWorkStatusQueue",concurrency = "10")
public class UpdateWorkStatusListener {

    @Autowired
    private PersonInfoService personInfoService;


    @RabbitHandler
    public void process(String id) {


        try {


            log.warn("收到访客访问记录：" + id);
            String[]sz=id.split("_");
            String type=sz[0];//A 修改为请假， b还原
            String thisid=sz[1];//id
            String status=sz[2];//之前的状态
          //  RequestForLeaveInfo target = requestForLeaveInfoService.get(id);
            PersonInfo info =personInfoService.get(Long.valueOf(thisid));
            Date now = new Date();
            if("A".equals(type)){
                info.setWorkStatus("4");

            }
            if("B".equals(type)){
                //如果是请假， 则修改回来， 否则不管
                if("4".equals(info.getWorkStatus())) {
                    info.setWorkStatus(status);
                }//连续请假可能造成的影响
                if("4".equals(info.getWorkStatus())) {
                    info.setWorkStatus("1");
                }
            }
            info.setUpdateTime(now);
            personInfoService.update(info);
        }
        catch (Exception ex){
            log.error(ex.getMessage(),ex);
        }
    }

}
