package com.qy.worksheetsystem.service.impl;

import com.qy.worksheetsystem.model.mapper.PersonMapper;
import com.qy.worksheetsystem.model.mapper.PersonWorkMapper;

import com.qy.worksheetsystem.service.PersonService;
import com.qy.worksheetsystem.service.PersonWorkService;
import com.qy.worksheetsystem.vo.InsertJobWorkingVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @BelongsProject: workSheetSystem
 * @BelongsPackage: com.qy.worksheetsystem.service.impl
 * @Author: lhbj
 * @CreateTime: 2024-12-03  15:18
 * @Description: TODO
 * @Version: 1.0
 */
@Slf4j
@Service
public class PersonWorkServiceImpl implements PersonWorkService {
    private static final BigDecimal h8 = new BigDecimal(8);
    @Resource
    private PersonWorkMapper personWorkMapper;
    @Resource
    private PersonService personService;

    @Override
    @Transactional
    public Map<String,Object> insertWork(Map<String,Object> param){


        Map<String, String> billMap = new HashMap<>();
        billMap.put("affiliatedProject","");
        billMap.put("fillingStartDate","");
        billMap.put("fillingEndDate","");
        billMap.put("adminOrg","");
        billMap.put("hrOrgUnit","");
        billMap.put("billState","");
        billMap.put("number","");
        billMap.put("CU","");
        billMap.put("bizDate","");
        billMap.put("creator","");
        billMap.put("createTime","");
        billMap.put("lastUpdateUser","");
        billMap.put("lastUpdateTime","");
        



        return null;
    }

    @Override
    public List<Map<String, Object>> getAvailableDateInfo(String number, String startDate, String endDate) {
        Map<String,String> person = personService.getPersonByJobNo(number);
        List<Map<String,Object>> list = personWorkMapper.getAvailableDateInfo(person.get("id"),startDate,endDate);
        for(Map<String,Object> map : list){
            BigDecimal workHours = (BigDecimal) map.get("workHours");
            if(null!=workHours) {
                map.put("availableWorkHous", h8.subtract(workHours));
            }else{
                map.put("workHours", BigDecimal.ZERO);
                map.put("availableWorkHous", h8);
            }
        }
        return list;
    }


}
