weaver-hrm-salary/src/com/engine/salary/cmd/datacollection/AddUpSituationListCmd.java

159 lines
6.7 KiB
Java
Raw Normal View History

2022-03-08 13:17:54 +08:00
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;
2022-03-08 16:35:05 +08:00
import com.engine.salary.component.SalaryWeaTable;
2022-03-08 18:10:03 +08:00
import com.engine.salary.entity.datacollection.dto.AddUpSituationDTO;
import com.engine.salary.entity.datacollection.param.AddUpSituationQueryParam;
2022-03-08 13:17:54 +08:00
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import weaver.hrm.User;
2022-03-08 18:14:20 +08:00
import java.util.*;
2022-03-08 13:17:54 +08:00
import java.util.stream.Collectors;
public class AddUpSituationListCmd extends AbstractCommonCommand<Map<String, Object>> {
public AddUpSituationListCmd(Map<String, Object> params, User user) {
this.user = user;
this.params = params;
}
@Override
public BizLogContext getLogContext() {
return null;
}
@Override
public Map<String, Object> execute(CommandContext commandContext) {
2022-03-08 18:10:03 +08:00
String fileds = " t1.id," +
" t1.tax_year_month," +
2022-03-08 13:17:54 +08:00
" t1.employee_id," +
" e.lastname as username," +
2022-03-08 18:10:03 +08:00
" d.departmentName AS departmentName," +
2022-03-08 13:17:54 +08:00
" e.mobile," +
" e.workcode as job_num," +
2022-03-08 18:10:03 +08:00
" e.companystartdate as hiredate," +
2022-03-08 13:17:54 +08:00
" t2.name AS tax_agent_name," +
2022-03-08 18:10:03 +08:00
" t1.add_up_income," +
" t1.add_up_subtraction," +
" t1.add_up_social_security_total," +
" t1.add_up_accumulation_fund_total," +
2022-03-08 13:17:54 +08:00
" t1.add_up_child_education," +
" t1.add_up_continuing_education," +
" t1.add_up_housing_loan_interest," +
" t1.add_up_housing_rent," +
2022-03-08 18:10:03 +08:00
" t1.add_up_support_elderly," +
" t1.add_up_enterprise_and_other," +
" t1.add_up_other_Situation," +
" t1.add_up_tax_exempt_income," +
" t1.add_up_allowed_donation," +
" t1.add_up_advance_tax";
2022-03-08 13:17:54 +08:00
2022-03-08 18:10:03 +08:00
String fromSql = " FROM " +
" hrsa_add_up_situation t1" +
" INNER JOIN" +
" (SELECT employee_id, MAX(tax_year_month) tax_year_month FROM hrsa_add_up_situation GROUP BY employee_id) t ON" +
" t.employee_id = t1.employee_id AND t.tax_year_month = t1.tax_year_month" +
" LEFT JOIN {$publicdb}.EMPLOYEE e ON e.id = t1.employee_id" +
" LEFT JOIN {$publicdb}.DEPARTMENT d ON d.id = e.department" +
" LEFT JOIN hrsa_tax_agent t2 ON t1.tax_agent_id = t2.id";
2022-03-08 13:17:54 +08:00
2022-03-08 18:10:03 +08:00
SalaryWeaTable<AddUpSituationDTO> table = new SalaryWeaTable<AddUpSituationDTO>(user, AddUpSituationDTO.class);
2022-03-08 13:17:54 +08:00
table.setBackfields(fileds);
table.setSqlform(fromSql);
table.setSqlwhere(makeSqlWhere());
table.setSqlorderby("t1.id DESC");
table.setSqlprimarykey("t1.id");
table.setSqlisdistinct("false");
2022-03-08 18:14:20 +08:00
table.setCheckboxList(new ArrayList<>());
table.setCheckboxpopedom(null);
2022-03-08 16:35:05 +08:00
WeaResultMsg result = new WeaResultMsg(false);
2022-03-08 13:17:54 +08:00
result.putAll(table.makeDataResult());
result.success();
2022-03-08 16:35:05 +08:00
return result.getResultMap();
2022-03-08 13:17:54 +08:00
}
private String makeSqlWhere() {
2022-03-08 18:10:03 +08:00
AddUpSituationQueryParam queryParam = (AddUpSituationQueryParam) params.get("queryParam");
2022-03-08 13:17:54 +08:00
//申报月份
2022-03-08 18:10:03 +08:00
List<String> taxYearMonths = queryParam.getTaxYearMonth();
if (CollectionUtils.isNotEmpty(taxYearMonths)) {
queryParam.setTaxYearMonth(taxYearMonths.stream().map(e -> e + "-01 00:00:00").collect(Collectors.toList()));
2022-03-08 13:17:54 +08:00
}
2022-03-08 18:10:03 +08:00
String sqlWhere = "t1.delete_type = 0 AND t2.delete_type = 0 AND e.status not in (7)";
2022-03-08 13:17:54 +08:00
Collection<Long> ids = queryParam.getIds();
if (CollectionUtils.isNotEmpty(ids)) {
String idsStr = ids.stream().map(String::valueOf).collect(Collectors.joining(","));
sqlWhere += " AND t1.id IN (" + idsStr + ")";
}
2022-03-08 18:10:03 +08:00
Integer year = queryParam.getYear();
if (year != null) {
sqlWhere += " AND t1.year =" + year;
}
2022-03-08 13:17:54 +08:00
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 + "%'" +
2022-03-08 18:10:03 +08:00
" OR e.workcode like ''%" + keyword + "%'" +
2022-03-08 13:17:54 +08:00
" )";
}
2022-03-08 18:10:03 +08:00
// 税款所属期
List<String> taxYearMonth = queryParam.getTaxYearMonth();
if (CollectionUtils.isNotEmpty(taxYearMonth)) {
if (taxYearMonth.size() == 1) {
sqlWhere += " AND t1.declare_month = '" + taxYearMonth.get(0) + "'";
2022-03-08 13:17:54 +08:00
}
2022-03-08 18:10:03 +08:00
if (taxYearMonth.size() == 2) {
sqlWhere += " AND (t1.declare_month BETWEEN '" + taxYearMonth.get(0) + "' AND '" + taxYearMonth.get(1) + "')";
2022-03-08 13:17:54 +08:00
}
}
//姓名
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<Long> 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<Date> hiredate = queryParam.getHiredate();
if (CollectionUtils.isNotEmpty(hiredate) && hiredate.size() == 2) {
2022-03-08 18:10:03 +08:00
sqlWhere += " AND (e.companystartdate BETWEEN '" + hiredate.get(0) + "' AND '" + hiredate.get(1) + "')";
2022-03-08 13:17:54 +08:00
}
//手机号
String mobile = queryParam.getMobile();
if (StringUtils.isNotBlank(mobile)) {
sqlWhere += " AND e.mobile like '%" + mobile + "%'";
}
return sqlWhere;
}
}