weaver-hrm-salary/src/com/engine/salary/web/OtherDeductionController.java

294 lines
12 KiB
Java
Raw Normal View History

2022-03-10 17:57:46 +08:00
package com.engine.salary.web;
import com.engine.common.util.ServiceUtil;
2022-05-31 11:21:51 +08:00
import com.engine.salary.entity.datacollection.dto.OtherDeductionListDTO;
import com.engine.salary.entity.datacollection.dto.OtherDeductionRecordDTO;
2022-03-10 17:57:46 +08:00
import com.engine.salary.entity.datacollection.param.OtherDeductionImportParam;
2022-10-26 18:35:23 +08:00
import com.engine.salary.entity.datacollection.param.OtherDeductionParam;
2022-04-28 17:44:26 +08:00
import com.engine.salary.entity.datacollection.param.OtherDeductionQueryParam;
2022-03-10 17:57:46 +08:00
import com.engine.salary.util.ResponseResult;
2022-09-26 18:51:17 +08:00
import com.engine.salary.util.SalaryDateUtil;
2022-05-31 11:21:51 +08:00
import com.engine.salary.util.page.PageInfo;
import com.engine.salary.wrapper.OtherDeductionWrapper;
2022-03-10 17:57:46 +08:00
import io.swagger.v3.oas.annotations.parameters.RequestBody;
2022-05-09 10:32:14 +08:00
import lombok.extern.slf4j.Slf4j;
2022-03-10 17:57:46 +08:00
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.jetbrains.annotations.Nullable;
import weaver.hrm.HrmUserVarify;
import weaver.hrm.User;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.StreamingOutput;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.text.ParseException;
import java.text.SimpleDateFormat;
2022-04-28 17:44:26 +08:00
import java.time.LocalDate;
2022-10-26 18:35:23 +08:00
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Map;
2022-03-10 17:57:46 +08:00
import java.util.stream.Collectors;
/**
* 数据采集-其他免税扣除
* <p>Copyright: Copyright (c) 2022</p>
* <p>Company: 泛微软件</p>
*
* @author qiantao
* @version 1.0
**/
2022-05-09 10:32:14 +08:00
@Slf4j
2022-03-10 17:57:46 +08:00
public class OtherDeductionController {
2022-05-31 11:21:51 +08:00
private OtherDeductionWrapper getOtherDeductionWrapper(User user) {
return ServiceUtil.getService(OtherDeductionWrapper.class, user);
2022-03-10 17:57:46 +08:00
}
/**
* 数据采集-累计专项附加扣除列表的高级搜索
*
* @return
*/
@GET
@Path("/getSearchCondition")
@Produces(MediaType.APPLICATION_JSON)
public String getSearchCondition(@Context HttpServletRequest request, @Context HttpServletResponse response) {
User user = HrmUserVarify.getUser(request, response);
2022-05-31 11:21:51 +08:00
return new ResponseResult<Map<String, Object>, Map<String, Object>>(user).run(getOtherDeductionWrapper(user)::getSearchCondition);
2022-03-10 17:57:46 +08:00
}
@POST
@Path("/list")
@Produces(MediaType.APPLICATION_JSON)
public String list(@Context HttpServletRequest request, @Context HttpServletResponse response, @RequestBody OtherDeductionQueryParam queryParam) {
User user = HrmUserVarify.getUser(request, response);
2022-05-31 11:21:51 +08:00
return new ResponseResult<OtherDeductionQueryParam, PageInfo<OtherDeductionListDTO>>(user).run(getOtherDeductionWrapper(user)::list, queryParam);
2022-03-10 17:57:46 +08:00
}
@POST
@Path("/getDetailList")
@Produces(MediaType.APPLICATION_JSON)
public String getDetailList(@Context HttpServletRequest request, @Context HttpServletResponse response, @RequestBody OtherDeductionQueryParam queryParam) {
User user = HrmUserVarify.getUser(request, response);
2022-05-31 11:21:51 +08:00
return new ResponseResult<OtherDeductionQueryParam, PageInfo<OtherDeductionRecordDTO>>(user).run(getOtherDeductionWrapper(user)::getDetailList, queryParam);
2022-03-10 17:57:46 +08:00
}
@GET
@Path("/downloadTemplate")
@Produces(MediaType.APPLICATION_OCTET_STREAM)
public Response getAll(@Context HttpServletRequest request, @Context HttpServletResponse response) {
try {
2022-05-09 10:32:14 +08:00
User user = HrmUserVarify.getUser(request, response);
OtherDeductionQueryParam param = buildParam(request);
2022-05-31 11:21:51 +08:00
XSSFWorkbook workbook = getOtherDeductionWrapper(user).downloadTemplate(param);
2022-05-09 10:32:14 +08:00
String fileName = "其他免税扣除导入模板" + LocalDate.now();
try {
fileName = URLEncoder.encode(fileName + ".xlsx", "UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
StreamingOutput output = outputStream -> {
workbook.write(outputStream);
outputStream.flush();
};
response.setContentType("application/octet-stream");
return Response.ok(output).header("Content-disposition", "attachment;filename=" + fileName).header("Cache-Control", "no-cache").build();
} catch (Exception e) {
log.error("其他免税扣除导入模板异常", e);
throw e;
2022-03-10 17:57:46 +08:00
}
}
/**
* 导出
*
* @param
* @return
*/
@GET
@Path("/export")
@Produces(MediaType.APPLICATION_OCTET_STREAM)
public Response export(@Context HttpServletRequest request, @Context HttpServletResponse response) {
try {
2022-05-09 10:32:14 +08:00
User user = HrmUserVarify.getUser(request, response);
OtherDeductionQueryParam param = buildParam(request);
2022-05-31 11:21:51 +08:00
XSSFWorkbook workbook = getOtherDeductionWrapper(user).export(param);
2022-05-09 10:32:14 +08:00
String fileName = null;
try {
fileName = URLEncoder.encode("其他免税扣除" + LocalDate.now() + ".xlsx", "UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
StreamingOutput output = outputStream -> {
workbook.write(outputStream);
outputStream.flush();
};
response.setContentType("application/octet-stream");
return Response.ok(output)
.header("Content-disposition", "attachment;filename=" + fileName)
.header("Cache-Control", "no-cache").build();
} catch (Exception e) {
log.error("其他免税扣除导出异常", e);
throw e;
2022-03-10 17:57:46 +08:00
}
}
@GET
@Path("/exportDetail")
@Produces(MediaType.APPLICATION_OCTET_STREAM)
public Response exportDetail(@Context HttpServletRequest request, @Context HttpServletResponse response) {
try {
2022-05-09 10:32:14 +08:00
User user = HrmUserVarify.getUser(request, response);
OtherDeductionQueryParam param = buildParam(request);
2022-05-31 11:21:51 +08:00
XSSFWorkbook workbook = getOtherDeductionWrapper(user).exportDetail(param);
2022-05-09 10:32:14 +08:00
2022-05-09 14:11:07 +08:00
String fileName = "其他免税扣除明细" + LocalDate.now();
2022-05-09 10:32:14 +08:00
try {
fileName = URLEncoder.encode(fileName + ".xlsx", "UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
StreamingOutput output = outputStream -> {
workbook.write(outputStream);
outputStream.flush();
};
response.setContentType("application/octet-stream");
return Response.ok(output)
.header("Content-disposition", "attachment;filename=" + fileName)
.header("Cache-Control", "no-cache").build();
} catch (Exception e) {
2022-05-09 14:11:07 +08:00
log.error("其他免税扣除明细导出异常", e);
2022-05-09 10:32:14 +08:00
throw e;
2022-03-10 17:57:46 +08:00
}
}
@Nullable
private OtherDeductionQueryParam buildParam(HttpServletRequest request) {
OtherDeductionQueryParam param = new OtherDeductionQueryParam();
String ids = request.getParameter("ids");
2022-05-09 10:32:14 +08:00
if (StringUtils.isNotBlank(ids)) {
param.setIds(Arrays.stream(ids.split(",")).map(Long::valueOf).collect(Collectors.toList()));
2022-03-10 17:57:46 +08:00
}
String keyword = request.getParameter("keyword");
2022-05-09 10:32:14 +08:00
if (StringUtils.isNotBlank(keyword)) {
2022-03-10 17:57:46 +08:00
param.setKeyword(keyword);
}
String id = request.getParameter("id");
2022-05-09 10:32:14 +08:00
if (StringUtils.isNotBlank(id)) {
2022-03-10 17:57:46 +08:00
param.setId(Long.valueOf(id));
}
String declareMonth = request.getParameter("declareMonth");
2022-05-09 10:32:14 +08:00
if (StringUtils.isNotBlank(declareMonth)) {
2022-09-26 18:51:17 +08:00
param.setDeclareMonth(Arrays.stream(declareMonth.split(",")).map(e -> e + "-01 00:00:00").collect(Collectors.toList()));
param.setDeclareMonthDate(Arrays.stream(declareMonth.split(",")).map(e -> e + "-01 00:00:00").map(SalaryDateUtil::dateStrToLocalTime).collect(Collectors.toList()));
2022-03-10 17:57:46 +08:00
}
String username = request.getParameter("username");
2022-05-09 10:32:14 +08:00
if (StringUtils.isNotBlank(username)) {
2022-03-10 17:57:46 +08:00
param.setUsername(username);
}
String employeeId = request.getParameter("employeeId");
2022-05-09 10:32:14 +08:00
if (StringUtils.isNotBlank(employeeId)) {
2022-03-10 17:57:46 +08:00
param.setEmployeeId(Long.valueOf(employeeId));
}
String taxAgentId = request.getParameter("taxAgentId");
2022-05-09 10:32:14 +08:00
if (StringUtils.isNotBlank(taxAgentId)) {
2022-03-10 17:57:46 +08:00
param.setTaxAgentId(Long.valueOf(taxAgentId));
}
String departmentIds = request.getParameter("departmentIds");
2022-05-09 10:32:14 +08:00
if (StringUtils.isNotBlank(departmentIds)) {
2022-03-10 17:57:46 +08:00
param.setDepartmentIds(Arrays.stream(departmentIds.split(",")).map(Long::valueOf).collect(Collectors.toList()));
}
String jobNum = request.getParameter("jobNum");
2022-05-09 10:32:14 +08:00
if (StringUtils.isNotBlank(jobNum)) {
2022-03-10 17:57:46 +08:00
param.setJobNum(jobNum);
}
String idNo = request.getParameter("idNo");
2022-05-09 10:32:14 +08:00
if (StringUtils.isNotBlank(idNo)) {
2022-03-10 17:57:46 +08:00
param.setIdNo(idNo);
}
String hiredate = request.getParameter("hiredate");
2022-05-09 10:32:14 +08:00
if (StringUtils.isNotBlank(hiredate)) {
2022-03-10 17:57:46 +08:00
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
List<Date> dates = Arrays.stream(hiredate.split(",")).map(d -> {
try {
return format.parse(d);
} catch (ParseException e) {
e.printStackTrace();
}
return null;
}).collect(Collectors.toList());
param.setHiredate(dates);
}
String mobile = request.getParameter("mobile");
2022-05-09 10:32:14 +08:00
if (StringUtils.isNotBlank(mobile)) {
2022-03-10 17:57:46 +08:00
param.setMobile(mobile);
}
String otherTaxExemptDeductionId = request.getParameter("otherTaxExemptDeductionId");
2022-05-09 10:32:14 +08:00
if (StringUtils.isNotBlank(otherTaxExemptDeductionId)) {
2022-03-10 17:57:46 +08:00
param.setOtherTaxExemptDeductionId(Long.valueOf(otherTaxExemptDeductionId));
}
return param;
}
@POST
@Path("/preview")
@Produces(MediaType.APPLICATION_JSON)
public String preview(@Context HttpServletRequest request, @Context HttpServletResponse response, @RequestBody OtherDeductionImportParam importParam) {
User user = HrmUserVarify.getUser(request, response);
2022-05-31 11:21:51 +08:00
return new ResponseResult<OtherDeductionImportParam, Map<String, Object>>(user).run(getOtherDeductionWrapper(user)::preview, importParam);
2022-03-10 17:57:46 +08:00
}
@POST
@Path("/importData")
@Produces(MediaType.APPLICATION_JSON)
public String importAddUpDeduction(@Context HttpServletRequest request, @Context HttpServletResponse response, @RequestBody OtherDeductionImportParam importParam) {
User user = HrmUserVarify.getUser(request, response);
2022-05-31 11:21:51 +08:00
return new ResponseResult<OtherDeductionImportParam, Map<String, Object>>(user).run(getOtherDeductionWrapper(user)::importData, importParam);
2022-03-10 17:57:46 +08:00
}
2022-10-26 18:35:23 +08:00
/**
* @description 编辑其他免税扣除
* @return String
* @author Harryxzy
* @date 2022/10/26 9:41
*/
@POST
@Path("/editData")
@Produces(MediaType.APPLICATION_JSON)
public String editOtherDeduction(@Context HttpServletRequest request, @Context HttpServletResponse response, @RequestBody OtherDeductionParam otherDeductionParam) {
User user = HrmUserVarify.getUser(request, response);
return new ResponseResult<OtherDeductionParam, Map<String, Object>>(user).run(getOtherDeductionWrapper(user)::editData, otherDeductionParam);
}
2022-03-10 17:57:46 +08:00
}