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.component.SalaryWeaTable; import com.engine.salary.entity.datacollection.dto.AddUpDeductionDTO; import com.engine.salary.entity.datacollection.param.AddUpDeductionQueryParam; 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 AddUpDeductionListCmd extends AbstractCommonCommand> { public AddUpDeductionListCmd(Map params, User user) { this.user = user; this.params = params; } @Override public BizLogContext getLogContext() { return null; } @Override public Map execute(CommandContext commandContext) { String fields = " t1.id," + " t1.declare_month as declareMonth," + " t1.employee_id as employeeId," + " e.lastname as username," + " d.departmentname AS departmentName," + " e.mobile," + " e.workcode as jobNum," + " e.companystartdate as hiredate," + " t2.name AS taxAgentName," + " t1.add_up_child_education as addUpChildEducation," + " t1.add_up_continuing_education as addUpContinuingEducation," + " t1.add_up_housing_loan_interest as addUpHousingLoanInterest," + " t1.add_up_housing_rent as addUpHousingRent," + " t1.add_up_support_elderly as addUpSupportElderly"; 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, AddUpDeductionDTO.class); table.setBackfields(fields); table.setSqlform(fromSql); table.setSqlwhere(makeSqlWhere()); table.setSqlorderby("t1.id 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 = (AddUpDeductionQueryParam) params.get("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.companystartdate BETWEEN '"+hiredate.get(0)+"' AND '"+hiredate.get(1)+"')"; } //手机号 String mobile = queryParam.getMobile(); if (StringUtils.isNotBlank(mobile)) { sqlWhere += " AND e.mobile like '%" + mobile + "%'"; } return sqlWhere; } }