package com.engine.salary.cmd.datacollection; import com.cloudstore.eccom.result.WeaResultMsg; import com.engine.common.biz.AbstractCommonCommand; import com.engine.common.entity.BizLogContext; import com.engine.core.interceptor.CommandContext; import com.engine.salary.biz.AddUpDeductionBiz; import com.engine.salary.component.SalaryWeaTable; import com.engine.salary.entity.datacollection.AddUpDeduction; import com.engine.salary.entity.datacollection.dto.AddUpDeductionRecordDTO; import com.engine.salary.entity.datacollection.param.AddUpDeductionQueryParam; import com.engine.salary.exception.SalaryRunTimeException; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; import weaver.hrm.User; import java.util.Collection; import java.util.Date; import java.util.List; import java.util.Map; import java.util.stream.Collectors; public class AddUpDeductionGetDetailListCmd extends AbstractCommonCommand> { public AddUpDeductionGetDetailListCmd(Map params, User user) { this.user = user; this.params = params; } @Override public BizLogContext getLogContext() { return null; } @Override public Map execute(CommandContext commandContext) { AddUpDeductionBiz biz = new AddUpDeductionBiz(); AddUpDeductionQueryParam queryParam = (AddUpDeductionQueryParam)params.get("queryParam"); Long id = queryParam.getAccumulatedSpecialAdditionalDeductionId(); if (id == null) { throw new SalaryRunTimeException("累计专项附加扣除id不能为空"); } AddUpDeduction po = biz.getById(id); if (po == null) { throw new SalaryRunTimeException(String.format("累计专项附加扣除不存在[id:%s]", id)); } // List employeeList = employeeService.getEmployeeByIds(Collections.singletonList(po.getEmployeeId()), tenantKey); // if (CollectionUtils.isEmpty(employeeList)) { // throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(tenantKey, employeeId, 100340, "员工信息不存在")); // } queryParam.setEmployeeId(po.getEmployeeId()); String fileds = " t1.id," + " t1.declare_month," + " t1.employee_id," + " e.lastname as username," + " d.departmentname AS departmentName," + " e.mobile," + " e.workcode as job_num," + " e.created as hiredate," + " t2.name AS tax_agent_name," + " t1.add_up_child_education," + " t1.add_up_continuing_education," + " t1.add_up_housing_loan_interest," + " t1.add_up_housing_rent," + " t1.add_up_support_elderly"; String fromSql = " FROM" + " hrsa_add_up_deduction t1" + " LEFT JOIN hrsa_tax_agent t2 ON t1.tax_agent_id = t2.id" + " LEFT JOIN hrmresource e ON t1.employee_id = e.id" + " LEFT JOIN hrmdepartment d ON e.departmentid = d.id"; SalaryWeaTable table = new SalaryWeaTable(user, AddUpDeductionRecordDTO.class); table.setBackfields(fileds); table.setSqlform(fromSql); table.setSqlwhere(makeSqlWhere(queryParam)); table.setSqlorderby("t1.declare_month DESC"); table.setSqlprimarykey("t1.id"); table.setSqlisdistinct("false"); WeaResultMsg result = new WeaResultMsg(false); result.putAll(table.makeDataResult()); result.success(); return result.getResultMap(); } private String makeSqlWhere( AddUpDeductionQueryParam queryParam) { //申报月份 List declareMonth = queryParam.getDeclareMonth(); if (CollectionUtils.isNotEmpty(declareMonth)) { queryParam.setDeclareMonth(declareMonth.stream().map(e -> e + "-01 00:00:00").collect(Collectors.toList())); } String sqlWhere = "t1.delete_type = 0 AND t2.delete_type = 0"; Collection ids = queryParam.getIds(); if (CollectionUtils.isNotEmpty(ids)) { String idsStr = ids.stream().map(String::valueOf).collect(Collectors.joining(",")); sqlWhere += " AND t1.id IN (" + idsStr + ")"; } Long employeeId = queryParam.getEmployeeId(); if (employeeId != null) { sqlWhere += " AND t1.employee_id =" + employeeId; } String keyword = queryParam.getKeyword(); if (StringUtils.isNotBlank(keyword)) { sqlWhere += " AND (" + " e.lastname like '%" + keyword + "%'" + " OR d.departmentname like '%" + keyword + "%'" + " OR e.workcode like ''%"+keyword+"%'" + " )"; } // 申报月份 List declareMonths = queryParam.getDeclareMonth(); if (CollectionUtils.isNotEmpty(declareMonths)) { if (declareMonths.size() == 1) { sqlWhere += " AND t1.declare_month = '" + declareMonths.get(0)+","; } if (declareMonths.size() == 2) { sqlWhere += " AND (t1.declare_month BETWEEN '" + declareMonths.get(0) + "' AND '" + declareMonths.get(1) + "')"; } } //姓名 String username = queryParam.getUsername(); if (StringUtils.isNotBlank(username)) { sqlWhere += " AND e.lastname like '%" + username + "%'"; } //个税扣缴义务人 Long taxAgentId = queryParam.getTaxAgentId(); if (taxAgentId != null) { sqlWhere += " AND t1.tax_agent_id = " + taxAgentId; } //部门 List departmentIds = queryParam.getDepartmentIds(); if (CollectionUtils.isNotEmpty(departmentIds)) { String departmentStrIds = departmentIds.stream().map(String::valueOf).collect(Collectors.joining(",")); sqlWhere += " AND d.id IN (" + departmentStrIds + ")"; } //工号 String jobNum = queryParam.getJobNum(); if (StringUtils.isNotBlank(jobNum)) { sqlWhere += " AND e.workcode like '%" + jobNum + "%'"; } //入职日期 List hiredate = queryParam.getHiredate(); if (CollectionUtils.isNotEmpty(hiredate) && hiredate.size() == 2) { sqlWhere += " AND (e.created BETWEEN "+hiredate.get(0)+" AND "+hiredate.get(1)+")"; } //手机号 String mobile = queryParam.getMobile(); if (StringUtils.isNotBlank(mobile)) { sqlWhere += " AND e.mobile like '%" + mobile + "%'"; } return sqlWhere; } }