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;
|
|
|
|
|
import com.engine.salary.entity.datacollection.param.AddUpDeductionQueryParam;
|
|
|
|
|
import com.engine.salary.service.AddUpDeductionService;
|
|
|
|
|
import com.engine.salary.service.impl.AddUpDeductionServiceImpl;
|
|
|
|
|
import com.engine.salary.util.ResponseResult;
|
|
|
|
|
import io.swagger.v3.oas.annotations.parameters.RequestBody;
|
2022-03-04 10:10:38 +08:00
|
|
|
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
2022-03-03 14:52:50 +08:00
|
|
|
import weaver.general.GCONST;
|
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-03 14:52:50 +08:00
|
|
|
import javax.ws.rs.*;
|
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.File;
|
2022-03-04 10:10:38 +08:00
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.io.OutputStream;
|
2022-03-03 14:52:50 +08:00
|
|
|
import java.io.UnsupportedEncodingException;
|
|
|
|
|
import java.net.URLEncoder;
|
2022-03-03 13:50:03 +08:00
|
|
|
import java.util.Map;
|
|
|
|
|
|
2022-03-02 11:09:23 +08:00
|
|
|
public class AddUpDeductionController {
|
2022-03-03 13:50:03 +08:00
|
|
|
|
|
|
|
|
private AddUpDeductionService getService(User user) {
|
|
|
|
|
return (AddUpDeductionService) ServiceUtil.getService(AddUpDeductionServiceImpl.class, user);
|
|
|
|
|
}
|
|
|
|
|
|
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);
|
|
|
|
|
return ResponseResult.run(getService(user)::getSearchCondition, ParamUtil.request2Map(request));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
Map<String, Object> map = ParamUtil.request2Map(request);
|
|
|
|
|
map.put("queryParam", queryParam);
|
|
|
|
|
return ResponseResult.run(getService(user)::list, map);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
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) {
|
|
|
|
|
User user = HrmUserVarify.getUser(request, response);
|
2022-03-03 14:52:50 +08:00
|
|
|
//模板文件路径
|
2022-03-04 10:10:38 +08:00
|
|
|
String templateFilePath = GCONST.getRootPath() + "salary/addUpDeduction/addUpDeductionTemplate.xlsx";
|
2022-03-03 14:52:50 +08:00
|
|
|
|
|
|
|
|
File file = new File(templateFilePath);
|
|
|
|
|
|
|
|
|
|
if (!file.exists()) {
|
|
|
|
|
return Response.status(Response.Status.NOT_FOUND).build();
|
|
|
|
|
}
|
|
|
|
|
String fileName = null;
|
|
|
|
|
try {
|
|
|
|
|
fileName = URLEncoder.encode("累计专项附加扣除导入模板.xlsx", "UTF-8");
|
|
|
|
|
} catch (UnsupportedEncodingException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
return Response
|
|
|
|
|
.ok(file)
|
|
|
|
|
.header("Content-disposition", "attachment;filename=" + fileName)
|
|
|
|
|
.header("Cache-Control", "no-cache").build();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
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) {
|
|
|
|
|
User user = HrmUserVarify.getUser(request, response);
|
2022-03-03 14:52:50 +08:00
|
|
|
|
2022-03-04 10:10:38 +08:00
|
|
|
Map<String, Object> map = ParamUtil.request2Map(request);
|
|
|
|
|
map.put("addUpDeductionQueryParam", new AddUpDeductionQueryParam());
|
2022-03-03 14:52:50 +08:00
|
|
|
|
2022-03-04 10:10:38 +08:00
|
|
|
HSSFWorkbook workbook = getService(user).export(map);
|
|
|
|
|
|
|
|
|
|
String fileName = null;
|
|
|
|
|
try {
|
|
|
|
|
fileName = URLEncoder.encode("累计专项附加扣除导入模板.xlsx", "UTF-8");
|
|
|
|
|
} catch (UnsupportedEncodingException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
StreamingOutput output = new StreamingOutput() {
|
|
|
|
|
@Override
|
|
|
|
|
public void write(OutputStream outputStream) throws IOException, WebApplicationException {
|
|
|
|
|
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();
|
|
|
|
|
}
|
2022-03-03 13:50:03 +08:00
|
|
|
|
2022-03-02 11:09:23 +08:00
|
|
|
}
|