package com.engine.salary.remote.attend.service.impl; import com.alibaba.druid.support.json.JSONUtils; import com.alibaba.fastjson.JSONObject; import com.engine.core.impl.Service; import com.engine.salary.remote.attend.cmd.GetKQReportCmd; import com.engine.salary.remote.attend.entity.Attend4Salary; import com.engine.salary.remote.attend.service.RemoteAttend4SalaryService; import com.engine.salary.util.SalaryDateUtil; import com.engine.salary.util.valid.ValidUtil; import com.google.common.collect.Maps; import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; import weaver.general.BaseBean; import weaver.general.Util; import java.util.*; import java.util.stream.Collectors; @Slf4j public class RemoteAttend4SalaryServiceImpl extends Service implements RemoteAttend4SalaryService { private final Boolean isLog = "true".equals(new BaseBean().getPropValue("hrmSalary", "log")); @Override public List> getColumns() { Map paramsMap = new HashMap(); // paramsMap.put("pageIndex", 1); // paramsMap.put("pageSize", 10); paramsMap.put("typeselect", "6"); paramsMap.put("viewScope", "3"); paramsMap.put("isNoAccount", "1"); paramsMap.put("attendanceSerial", ""); paramsMap.put("isFromMyAttendance", "1"); Map temp = new HashMap(); temp.put("data", JSONObject.toJSONString(paramsMap)); temp.put("reportType", "month"); List datas = (List) commandExecutor.execute(new GetKQReportCmd(temp, user)).get("columns"); List> columns = new ArrayList<>(); datas.stream().filter(column -> Objects.nonNull(column.get("dataIndex"))).forEach(column -> { String dataIndex = column.get("dataIndex").toString(); //请假 if (dataIndex.equals("leave") && column.get("children") != null) { List list = (List) column.get("children"); if (CollectionUtils.isNotEmpty(list)) { list.stream() .filter(leave -> leave.get("dataIndex") != null && StringUtils.isNotBlank(leave.get("dataIndex").toString())) .forEach(leave -> { Map map = Maps.newHashMapWithExpectedSize(2); map.put("code", leave.get("dataIndex").toString()); map.put("name", Util.null2String(column.get("title")) + "-" + leave.get("title") + "(" + leave.get("unit").toString() + ")"); columns.add(map); }); } } //加班 else if (dataIndex.equals("overtime") && column.get("children") != null) { List list = (List) column.get("children"); if (CollectionUtils.isNotEmpty(list)) { for (int i = 0; i < list.size(); i++) { Map overtimeMap = list.get(i); if (overtimeMap.get("dataIndex") != null && StringUtils.isNotBlank(overtimeMap.get("dataIndex").toString()) && overtimeMap.get("children") == null) { Map map = Maps.newHashMapWithExpectedSize(2); map.put("code", overtimeMap.get("dataIndex").toString()); map.put("name", Util.null2String(column.get("title")) + "-" + overtimeMap.get("title") + "(" + overtimeMap.get("unit").toString() + ")"); columns.add(map); } if (overtimeMap.get("dataIndex") != null && StringUtils.isNotBlank(overtimeMap.get("dataIndex").toString()) && overtimeMap.get("children") != null) { List overtimes = (List) overtimeMap.get("children"); if (CollectionUtils.isNotEmpty(overtimes)) { overtimes.stream().filter(leave -> leave.get("dataIndex") != null && StringUtils.isNotBlank(leave.get("dataIndex").toString())) .forEach(leave -> { Map map = Maps.newHashMapWithExpectedSize(2); map.put("code", leave.get("dataIndex").toString()); map.put("name", Util.null2String(column.get("title")) + "-" + Util.null2String(overtimeMap.get("title")) + "-" + leave.get("title") + "(" + leave.get("unit").toString() + ")"); columns.add(map); }); } } } } } //普通考勤 else { if (column.get("unit") != null && StringUtils.isNotBlank(column.get("unit").toString())) { Map map = Maps.newHashMapWithExpectedSize(2); map.put("code", dataIndex); map.put("name", column.get("title") + "(" + column.get("unit").toString() + ")"); columns.add(map); } } }); return columns; } @Override public List> getDatas(Attend4Salary attend4Salary) { ValidUtil.doValidator(attend4Salary); log.info("开始获取的考勤数据,参数{}", attend4Salary); List> list = new ArrayList<>(); try { Map paramsMap = new HashMap(); // paramsMap.put("pageIndex", 1); // paramsMap.put("pageSize", 500); paramsMap.put("typeselect", "6"); paramsMap.put("fromDate", SalaryDateUtil.getFormatLocalDate(attend4Salary.getBeginDate())); paramsMap.put("toDate", SalaryDateUtil.getFormatLocalDate(attend4Salary.getEndDate())); paramsMap.put("viewScope", "3"); List resourceIds = attend4Salary.getOnlyEmpIds().stream().map(String::valueOf).collect(Collectors.toList()); paramsMap.put("resourceId", String.join(",", resourceIds)); paramsMap.put("isNoAccount", "1"); paramsMap.put("attendanceSerial", ""); paramsMap.put("isFromMyAttendance", "1"); Map temp = new HashMap(); temp.put("data", JSONObject.toJSONString(paramsMap)); temp.put("reportType", "month"); list = (List>) commandExecutor.execute(new GetKQReportCmd(temp, user)).get("datas"); if (isLog) { log.info("获取的考勤数据,{}", JSONUtils.toJSONString(list)); } } catch (Exception e) { log.error("获取考勤数据失败", e); } return list; } }