weaver-hrm-salary/src/com/engine/salary/cmd/datacollection/AddUpSituationGetDetailList...

190 lines
8.4 KiB
Java

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.AddUpSituationBiz;
import com.engine.salary.biz.EmployBiz;
import com.engine.salary.component.SalaryWeaTable;
import com.engine.salary.entity.datacollection.AddUpSituation;
import com.engine.salary.entity.datacollection.DataCollectionEmployee;
import com.engine.salary.entity.datacollection.dto.AddUpSituationRecordDTO;
import com.engine.salary.entity.datacollection.param.AddUpSituationQueryParam;
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 AddUpSituationGetDetailListCmd extends AbstractCommonCommand<Map<String, Object>> {
public AddUpSituationGetDetailListCmd(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) {
EmployBiz employBiz = new EmployBiz();
AddUpSituationBiz biz = new AddUpSituationBiz();
AddUpSituationQueryParam queryParam = (AddUpSituationQueryParam) params.get("queryParam");
if (queryParam == null) {
throw new SalaryRunTimeException("参数异常");
}
Long id = queryParam.getAccumulatedSituationId();
if (id == null) {
throw new SalaryRunTimeException("累计情况id不能为空");
}
AddUpSituation po = biz.getById(id);
if (po == null) {
throw new SalaryRunTimeException(String.format("累计情况不存在[id:%s]", id));
}
List<DataCollectionEmployee> employeeList = employBiz.getEmployeeByIds(Collections.singletonList(po.getEmployeeId()));
if (CollectionUtils.isEmpty(employeeList)) {
throw new SalaryRunTimeException("员工信息不存在");
}
//构建查询参数
queryParam.setEmployeeId(po.getEmployeeId());
//申报月份
List<String> taxYearMonths = queryParam.getTaxYearMonth();
if (CollectionUtils.isNotEmpty(taxYearMonths)) {
queryParam.setTaxYearMonth(taxYearMonths.stream().map(e -> e + "-01 00:00:00").collect(Collectors.toList()));
}
String fields = " t1.id," +
" t1.tax_year_month as taxYearMonth," +
" 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_income as addUpIncome," +
" t1.add_up_subtraction as addUpSubtraction," +
" t1.add_up_social_security_total as addUpSocialSecurityTotal," +
" t1.add_up_accumulation_fund_total as addUpAccumulationFundTotal," +
" 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," +
" t1.add_up_enterprise_and_other as addUpEnterpriseAndOther," +
" t1.add_up_other_deduction as addUpOtherDeduction," +
" t1.add_up_tax_exempt_income as addUpTaxExemptIncome," +
" t1.add_up_allowed_donation as addUpAllowedDonation," +
" t1.add_up_infant_care as addUpInfantCare," +
" t1.add_up_tax_savings as addUpTaxSavings," +
" t1.add_up_illness_medical as addUpIllnessMedical," +
" t1.add_up_advance_tax as addUpAdvanceTax";
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 hrmresource e ON e.id = t1.employee_id" +
" LEFT JOIN hrmdepartment d ON d.id = e.departmentid" +
" LEFT JOIN hrsa_tax_agent t2 ON t1.tax_agent_id = t2.id";
SalaryWeaTable<AddUpSituationRecordDTO> table = new SalaryWeaTable<AddUpSituationRecordDTO>(user, AddUpSituationRecordDTO.class);
table.setBackfields(fields);
table.setSqlform(fromSql);
table.setSqlwhere(makeSqlWhere(queryParam));
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(AddUpSituationQueryParam queryParam) {
String sqlWhere = "t1.delete_type = 0 AND t2.delete_type = 0 AND e.status not in (7)";
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 + ")";
}
Integer year = queryParam.getYear();
if (year != null) {
sqlWhere += " AND t1.year =" + year;
}
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<String> taxYearMonth = queryParam.getTaxYearMonth();
if (CollectionUtils.isNotEmpty(taxYearMonth)) {
if (taxYearMonth.size() == 1) {
sqlWhere += " AND t1.tax_year_month = '" + taxYearMonth.get(0) + "'";
}
if (taxYearMonth.size() == 2) {
sqlWhere += " AND (t1.tax_year_month BETWEEN '" + taxYearMonth.get(0) + "' AND '" + taxYearMonth.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<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) {
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;
}
}