package com.pj.api.service;

import cn.hutool.core.bean.BeanUtil;
import com.pj.api.bo.InOutRecordBO;
import com.pj.project.tb_business.TbBusinessService;
import com.pj.project.tb_costomer.TbCostomer;
import com.pj.project.tb_costomer.TbCostomerService;
import com.pj.project.tb_pass_record.TbPassRecord;
import com.pj.project.tb_pass_record.TbPassRecordService;
import com.pj.utils.so.SoMap;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

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

/**
 */

@Service
@Transactional(rollbackFor = Exception.class)
@Slf4j
public class ApiService {

    @Resource
    TbCostomerService tbCostomerService;
    @Resource
    TbBusinessService tbBusinessService;
    @Resource
    TbPassRecordService tbPassRecordService;

    public List<InOutRecordBO> getInOutRecord(SoMap so){
        List<TbPassRecord> passRecords = tbPassRecordService.getList(so);
        List<InOutRecordBO> recordList = new ArrayList<>();
        for (TbPassRecord passRecord : passRecords) {
            InOutRecordBO record = new InOutRecordBO();
            BeanUtil.copyProperties(passRecord, record);
            TbCostomer costomer = tbCostomerService.getById(passRecord.getCustomerId());
            record.setCustomerContact(costomer.getPhone()).setDutyPeople(costomer.getDutyPeople());
            recordList.add(record);
        }
        return recordList;
    }

    public List<TbCostomer> getCustomerList(SoMap so) {
        List<TbCostomer> list = tbCostomerService.getList(so);
        return list;
    }

    public void confirmCustomer(Long customerId, String judgeContent) {
        TbCostomer costomer = tbCostomerService.getById(customerId);
        if(costomer != null && costomer.getJudgeStatus() == 1){
            tbCostomerService.judge(customerId + "", 2, judgeContent);
        }
    }
}
