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

330 lines
13 KiB
Java
Raw Normal View History

2022-03-02 11:09:23 +08:00
package com.engine.salary.web;
2022-03-03 13:50:03 +08:00
import com.engine.common.util.ParamUtil;
import com.engine.common.util.ServiceUtil;
2022-05-25 16:51:43 +08:00
import com.engine.salary.entity.datacollection.dto.AddUpDeductionDTO;
import com.engine.salary.entity.datacollection.dto.AddUpDeductionRecordDTO;
2022-03-07 15:08:56 +08:00
import com.engine.salary.entity.datacollection.param.AddUpDeductionImportParam;
2022-03-03 13:50:03 +08:00
import com.engine.salary.entity.datacollection.param.AddUpDeductionQueryParam;
2022-10-26 18:35:23 +08:00
import com.engine.salary.entity.datacollection.param.AddUpDeductionRecordDeleteParam;
import com.engine.salary.entity.datacollection.param.AddUpDeductionRecordParam;
2022-03-03 13:50:03 +08:00
import com.engine.salary.util.ResponseResult;
2022-05-25 16:51:43 +08:00
import com.engine.salary.util.page.PageInfo;
import com.engine.salary.wrapper.AddUpDeductionWrapper;
2022-03-03 13:50:03 +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-08 13:17:54 +08:00
import org.apache.commons.lang3.StringUtils;
2022-03-10 11:12:13 +08:00
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
2022-03-08 13:17:54 +08:00
import org.jetbrains.annotations.Nullable;
2022-03-03 13:50:03 +08:00
import weaver.hrm.HrmUserVarify;
import weaver.hrm.User;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
2022-03-07 15:08:56 +08:00
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
2022-03-03 13:50:03 +08:00
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
2022-03-03 14:52:50 +08:00
import javax.ws.rs.core.Response;
2022-03-04 10:10:38 +08:00
import javax.ws.rs.core.StreamingOutput;
2022-03-03 14:52:50 +08:00
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
2022-03-08 13:17:54 +08:00
import java.text.ParseException;
import java.text.SimpleDateFormat;
2022-04-28 17:44:26 +08:00
import java.time.LocalDate;
2022-03-08 13:17:54 +08:00
import java.util.Arrays;
import java.util.Date;
import java.util.List;
2022-03-03 13:50:03 +08:00
import java.util.Map;
2022-03-08 13:17:54 +08:00
import java.util.stream.Collectors;
2022-03-03 13:50:03 +08:00
2022-05-09 10:32:14 +08:00
@Slf4j
2022-03-02 11:09:23 +08:00
public class AddUpDeductionController {
2022-03-03 13:50:03 +08:00
2022-05-25 16:51:43 +08:00
private AddUpDeductionWrapper getAddUpDeductionWrapper(User user) {
return ServiceUtil.getService(AddUpDeductionWrapper.class, user);
2022-03-03 13:50:03 +08:00
}
2022-03-04 10:10:38 +08:00
/**
* 数据采集-累计专项附加扣除列表的高级搜索
2022-03-07 15:08:56 +08:00
*
2022-03-04 10:10:38 +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-25 16:51:43 +08:00
return new ResponseResult<Map<String, Object>, Map<String, Object>>(user).run(getAddUpDeductionWrapper(user)::getSearchCondition, ParamUtil.request2Map(request));
2022-03-04 10:10:38 +08:00
}
2022-03-03 13:50:03 +08:00
@POST
@Path("/list")
@Produces(MediaType.APPLICATION_JSON)
public String list(@Context HttpServletRequest request, @Context HttpServletResponse response, @RequestBody AddUpDeductionQueryParam queryParam) {
User user = HrmUserVarify.getUser(request, response);
2022-05-25 16:51:43 +08:00
return new ResponseResult<AddUpDeductionQueryParam, PageInfo<AddUpDeductionDTO>>(user).run(getAddUpDeductionWrapper(user)::list, queryParam);
2022-03-03 13:50:03 +08:00
}
2022-03-03 14:52:50 +08:00
@GET
@Path("/downloadTemplate")
@Produces(MediaType.APPLICATION_OCTET_STREAM)
2022-03-04 10:10:38 +08:00
public Response getAll(@Context HttpServletRequest request, @Context HttpServletResponse response) {
2022-03-03 14:52:50 +08:00
try {
2022-05-09 10:32:14 +08:00
User user = HrmUserVarify.getUser(request, response);
AddUpDeductionQueryParam queryParam = buildParam(request);
2022-05-25 16:51:43 +08:00
XSSFWorkbook workbook = getAddUpDeductionWrapper(user).downloadTemplate(queryParam);
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-03 14:52:50 +08:00
}
2022-04-28 17:44:26 +08:00
2022-03-03 14:52:50 +08:00
}
2022-03-04 10:10:38 +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);
AddUpDeductionQueryParam param = buildParam(request);
2022-05-25 16:51:43 +08:00
XSSFWorkbook workbook = getAddUpDeductionWrapper(user).export(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-04 10:10:38 +08:00
}
}
2022-03-03 13:50:03 +08:00
2022-03-10 11:12:13 +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);
AddUpDeductionQueryParam param = buildParam(request);
2022-05-25 16:51:43 +08:00
XSSFWorkbook workbook = getAddUpDeductionWrapper(user).exportDetail(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 11:12:13 +08:00
}
}
2022-03-08 13:17:54 +08:00
@Nullable
private AddUpDeductionQueryParam buildParam(HttpServletRequest request) {
AddUpDeductionQueryParam param = new AddUpDeductionQueryParam();
String ids = request.getParameter("ids");
2022-04-28 17:44:26 +08:00
if (StringUtils.isNotBlank(ids)) {
param.setIds(Arrays.stream(ids.split(",")).map(Long::valueOf).collect(Collectors.toList()));
2022-03-08 13:17:54 +08:00
}
String keyword = request.getParameter("keyword");
2022-04-28 17:44:26 +08:00
if (StringUtils.isNotBlank(keyword)) {
2022-03-08 13:17:54 +08:00
param.setKeyword(keyword);
}
String id = request.getParameter("id");
2022-04-28 17:44:26 +08:00
if (StringUtils.isNotBlank(id)) {
2022-03-08 13:17:54 +08:00
param.setId(Long.valueOf(id));
}
String declareMonth = request.getParameter("declareMonth");
2022-04-28 17:44:26 +08:00
if (StringUtils.isNotBlank(declareMonth)) {
2022-03-08 13:17:54 +08:00
param.setDeclareMonth(Arrays.asList(declareMonth.split(",")));
}
String username = request.getParameter("username");
2022-04-28 17:44:26 +08:00
if (StringUtils.isNotBlank(username)) {
2022-03-08 13:17:54 +08:00
param.setUsername(username);
}
String employeeId = request.getParameter("employeeId");
2022-04-28 17:44:26 +08:00
if (StringUtils.isNotBlank(employeeId)) {
2022-03-08 13:17:54 +08:00
param.setEmployeeId(Long.valueOf(employeeId));
}
String taxAgentId = request.getParameter("taxAgentId");
2022-04-28 17:44:26 +08:00
if (StringUtils.isNotBlank(taxAgentId)) {
2022-03-08 13:17:54 +08:00
param.setTaxAgentId(Long.valueOf(taxAgentId));
}
String departmentIds = request.getParameter("departmentIds");
2022-04-28 17:44:26 +08:00
if (StringUtils.isNotBlank(departmentIds)) {
2022-03-08 13:17:54 +08:00
param.setDepartmentIds(Arrays.stream(departmentIds.split(",")).map(Long::valueOf).collect(Collectors.toList()));
}
String jobNum = request.getParameter("jobNum");
2022-04-28 17:44:26 +08:00
if (StringUtils.isNotBlank(jobNum)) {
2022-03-08 13:17:54 +08:00
param.setJobNum(jobNum);
}
String idNo = request.getParameter("idNo");
2022-04-28 17:44:26 +08:00
if (StringUtils.isNotBlank(idNo)) {
2022-03-08 13:17:54 +08:00
param.setIdNo(idNo);
}
String hiredate = request.getParameter("hiredate");
2022-04-28 17:44:26 +08:00
if (StringUtils.isNotBlank(hiredate)) {
2022-03-08 13:17:54 +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-04-28 17:44:26 +08:00
if (StringUtils.isNotBlank(mobile)) {
2022-03-08 13:17:54 +08:00
param.setMobile(mobile);
}
String accumulatedSpecialAdditionalDeductionId = request.getParameter("accumulatedSpecialAdditionalDeductionId");
2022-04-28 17:44:26 +08:00
if (StringUtils.isNotBlank(accumulatedSpecialAdditionalDeductionId)) {
2022-03-08 13:17:54 +08:00
param.setAccumulatedSpecialAdditionalDeductionId(Long.valueOf(accumulatedSpecialAdditionalDeductionId));
}
return param;
}
2022-03-09 16:40:14 +08:00
@POST
@Path("/preview")
@Produces(MediaType.APPLICATION_JSON)
public String preview(@Context HttpServletRequest request, @Context HttpServletResponse response, @RequestBody AddUpDeductionImportParam importParam) {
User user = HrmUserVarify.getUser(request, response);
2022-05-27 14:46:01 +08:00
return new ResponseResult<AddUpDeductionImportParam, Map<String, Object>>(user).run(getAddUpDeductionWrapper(user)::preview, importParam);
2022-03-09 16:40:14 +08:00
}
2022-03-07 15:08:56 +08:00
@POST
@Path("/importAddUpDeduction")
@Produces(MediaType.APPLICATION_JSON)
public String importAddUpDeduction(@Context HttpServletRequest request, @Context HttpServletResponse response, @RequestBody AddUpDeductionImportParam importParam) {
User user = HrmUserVarify.getUser(request, response);
2022-05-27 15:43:38 +08:00
return new ResponseResult<AddUpDeductionImportParam, Map<String, Object>>(user).run(getAddUpDeductionWrapper(user)::importAddUpDeduction, importParam);
2022-03-07 15:08:56 +08:00
}
2022-10-26 18:35:23 +08:00
/**
* @description 新建累计专项附加扣除
* @return String
* @author Harryxzy
* @date 2022/10/26 14:23
*/
@POST
@Path("/createAddUpDeduction")
@Produces(MediaType.APPLICATION_JSON)
public String createAddUpDeduction(@Context HttpServletRequest request, @Context HttpServletResponse response, @RequestBody AddUpDeductionRecordParam addUpDeduction) {
User user = HrmUserVarify.getUser(request, response);
return new ResponseResult<AddUpDeductionRecordParam, Map<String, Object>>(user).run(getAddUpDeductionWrapper(user)::createAddUpDeduction, addUpDeduction);
}
/**
* @description 编辑累计专项附加扣除
* @return String
* @author Harryxzy
* @date 2022/10/25 14:08
*/
@POST
@Path("/editAddUpDeduction")
@Produces(MediaType.APPLICATION_JSON)
public String editAddUpDeduction(@Context HttpServletRequest request, @Context HttpServletResponse response, @RequestBody AddUpDeductionRecordParam addUpDeduction) {
User user = HrmUserVarify.getUser(request, response);
return new ResponseResult<AddUpDeductionRecordParam, Map<String, Object>>(user).run(getAddUpDeductionWrapper(user)::editAddUpDeduction, addUpDeduction);
}
/**
* @description 累计专项附加扣除-删除所选
* @return String
* @author Harryxzy
* @date 2022/10/27 14:08
2022-10-26 18:35:23 +08:00
*/
@POST
@Path("/deleteSelectAddUpDeduction")
@Produces(MediaType.APPLICATION_JSON)
public String deleteSelectAddUpDeduction(@Context HttpServletRequest request, @Context HttpServletResponse response, @RequestBody AddUpDeductionRecordDeleteParam deleteParam) {
User user = HrmUserVarify.getUser(request, response);
return new ResponseResult<AddUpDeductionRecordDeleteParam, Map<String, Object>>(user).run(getAddUpDeductionWrapper(user)::deleteSelectAddUpDeduction, deleteParam);
}
/**
* @description 累计专项附加扣除-一键清空
* @return String
* @author Harryxzy
* @date 2022/10/27 14:08
2022-10-26 18:35:23 +08:00
*/
@POST
@Path("/deleteAllAddUpDeduction")
@Produces(MediaType.APPLICATION_JSON)
public String deleteAllAddUpDeduction(@Context HttpServletRequest request, @Context HttpServletResponse response, @RequestBody AddUpDeductionRecordDeleteParam deleteParam) {
2022-10-26 18:35:23 +08:00
User user = HrmUserVarify.getUser(request, response);
return new ResponseResult<AddUpDeductionRecordDeleteParam, Map<String, Object>>(user).run(getAddUpDeductionWrapper(user)::deleteAllAddUpDeduction, deleteParam);
2022-10-26 18:35:23 +08:00
}
2022-03-08 15:40:26 +08:00
@POST
@Path("/getDetailList")
@Produces(MediaType.APPLICATION_JSON)
public String getDetailList(@Context HttpServletRequest request, @Context HttpServletResponse response, @RequestBody AddUpDeductionQueryParam queryParam) {
User user = HrmUserVarify.getUser(request, response);
2022-05-25 16:51:43 +08:00
return new ResponseResult<AddUpDeductionQueryParam, PageInfo<AddUpDeductionRecordDTO>>(user).run(getAddUpDeductionWrapper(user)::getDetailList, queryParam);
2022-03-08 15:40:26 +08:00
}
2022-03-02 11:09:23 +08:00
}