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.biz.EmployBiz; import com.engine.salary.component.SalaryWeaTable; import com.engine.salary.entity.datacollection.AddUpDeduction; import com.engine.salary.entity.datacollection.DataCollectionEmployee; 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.*; 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) { EmployBiz employBiz = new EmployBiz(); AddUpDeductionBiz biz = new AddUpDeductionBiz(); AddUpDeductionQueryParam queryParam = (AddUpDeductionQueryParam) params.get("queryParam"); if (queryParam == null) { throw new SalaryRunTimeException("参数异常"); } 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 = employBiz.getEmployeeByIds(Collections.singletonList(po.getEmployeeId())); if (CollectionUtils.isEmpty(employeeList)) { throw new SalaryRunTimeException("员工信息不存在"); } //查询参数 queryParam.setEmployeeId(po.getEmployeeId()); //申报月份 List declareMonth = queryParam.getDeclareMonth(); if (CollectionUtils.isNotEmpty(declareMonth)) { queryParam.setDeclareMonth(declareMonth.stream().map(e -> e + "-01 00:00:00").collect(Collectors.toList())); } 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, AddUpDeductionRecordDTO.class); table.setBackfields(fields); 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) { 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; } }