package com.kingdee.eas.custom.attendance.service;

import com.kingdee.bos.Context;
import com.kingdee.eas.basedata.person.PersonCollection;
import com.kingdee.eas.basedata.person.PersonFactory;
import com.kingdee.eas.basedata.person.PersonInfo;
import com.kingdee.eas.hr.affair.EmpHireBizBillInfo;
import com.kingdee.shr.affair.web.service.GetPersonEmpHireBizBillInfoService;

import java.util.HashMap;
import java.util.Map;

/**
 * 员工用工状态校验
 */
public class GetPersonEmpHireBizBillInfoServiceEx extends GetPersonEmpHireBizBillInfoService {
    @Override
    public Object process(Context context, Map param) {
        String personNumber = (String)param.get("personNumber");
        StringBuilder errLog = new StringBuilder();
        if (com.aliyun.odps.utils.StringUtils.isBlank(personNumber)) {
            errLog.append("员工工号不能为空;");
        }
        EmpHireBizBillInfo billInfo = new EmpHireBizBillInfo();
        //申请人工号
        try {
            PersonCollection presonCollection = PersonFactory.getLocalInstance(context).getPersonCollection("where number='" + personNumber + "'");
            if (presonCollection.size() > 0){
                PersonInfo personInfo = presonCollection.get(0);
                String personId = personInfo.getId().toString();
                HashMap<String, Object> map = new HashMap<>();
                map.put("personId",personId);
                billInfo = (EmpHireBizBillInfo) super.process(context, map);
            }else {
                errLog.append("未找到员工工号为" + personNumber + "员工信息;");
            }
        } catch (Exception e) {
            e.getMessage();
            errLog.append(e.getMessage());
        }
        if (errLog.length() > 0){
            return errLog.toString();
        }
        return billInfo;
    }

}
