数智-编制定时服务,花名册附件导出

shuzhi
dxfeng 2 years ago
parent efbedd5d7a
commit dc31a6d9a8

@ -0,0 +1,12 @@
package com.api.shuzhi.web;
import javax.ws.rs.Path;
/**
* @author:dxfeng
* @createTime: 2023/06/02
* @version: 1.0
*/
@Path("/shuzhi/mode")
public class SzBatchExportController extends com.engine.shuzhi.web.SzBatchExportController{
}

@ -0,0 +1,80 @@
package com.engine.shuzhi.entity.po;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.StringUtils;
/**
* @author:dxfeng
* @createTime: 2023/06/02
* @version: 1.0
*/
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class ModeStaffPO {
/**
*
*/
private String num;
/**
* ID
*/
private String departmentid;
/**
* ID
*/
private String jobtitle;
///**
// * 编制台账ID
// */
//private String staffId;
/**
*
*/
private String staffNum;
/**
*
*/
private Integer lackNum;
/**
*
*
* @return
*/
public Integer getLackNum() {
return parseInt(staffNum) - parseInt(num);
}
/**
*
*
* @return
*/
public Integer getNum() {
return parseInt(num);
}
/**
* String Integer
*
* @param str String
* @return Integer
*/
private Integer parseInt(String str) {
if (StringUtils.isBlank(str)) {
return 0;
}
return Integer.parseInt(str);
}
}

@ -0,0 +1,14 @@
package com.engine.shuzhi.service;
import java.util.List;
import java.util.Map;
/**
* @author:dxfeng
* @createTime: 2023/06/02
* @version: 1.0
*/
public interface SzBatchExportService {
Map<String,Object> downloadResourceFile(List<Long> idList);
}

@ -0,0 +1,103 @@
package com.engine.shuzhi.service.impl;
import com.engine.core.impl.Service;
import com.engine.shuzhi.exception.CustomizeRunTimeException;
import com.engine.shuzhi.service.SzBatchExportService;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import weaver.conn.RecordSet;
import weaver.file.ImageFileManager;
import weaver.general.BaseBean;
import weaver.general.GCONST;
import weaver.general.Util;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.time.LocalDate;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
/**
* @author:dxfeng
* @createTime: 2023/06/02
* @version: 1.0
*/
public class SzBatchExportServiceImpl extends Service implements SzBatchExportService {
@Override
public Map<String, Object> downloadResourceFile(List<Long> idList) {
Map<String, Object> returnMap = new HashMap<>(2);
if (CollectionUtils.isEmpty(idList)) {
throw new CustomizeRunTimeException("未选择需要下载的人员信息");
}
String zipFilename = "身份证复印件" + LocalDate.now() + ".zip";
String outPutPath = GCONST.getRootPath() + "filesystem" + File.separator + "downloadBatchTemp";
File outPut = new File(outPutPath);
if (!outPut.exists() && !outPut.isDirectory()) {
outPut.mkdir();
}
outPutPath += File.separator + zipFilename;
try {
RecordSet rs = new RecordSet();
String sql = "select a.lastname ,a.workcode ,b.field0 as fileId from HrmResource a inner join cus_fielddata b on a.id =b.id and b.scopeid =3 and a.id = ? ";
ZipOutputStream zipOutputStream = new ZipOutputStream(new FileOutputStream(outPutPath));
byte[] buffer = new byte[1024];
for (Long userId : idList) {
String fileId = "";
String lastname = "";
String workcode = "";
rs.executeQuery(sql, userId);
if (rs.next()) {
fileId = rs.getString("fileId");
lastname = rs.getString("lastname");
workcode = rs.getString("workcode");
}
if (StringUtils.isNotBlank(fileId)) {
for (String file : fileId.split(",")) {
ImageFileManager manager = new ImageFileManager();
manager.getImageFileInfoById(Util.getIntValue(file));
manager.getImageFileType();
InputStream inputStream = manager.getInputStream();
zipOutputStream.putNextEntry(new ZipEntry(lastname + "-" + workcode + "(身份证)" + getFileSuffix(manager.getImageFileName())));
int length;
while ((length = inputStream.read(buffer)) > 0) {
zipOutputStream.write(buffer, 0, length);
}
inputStream.close();
zipOutputStream.closeEntry();
}
}
}
zipOutputStream.close();
returnMap.put("zipFilename", zipFilename);
returnMap.put("outPutPath", outPutPath);
} catch (IOException e) {
new BaseBean().writeLog(e);
throw new CustomizeRunTimeException(e);
}
return returnMap;
}
/**
*
*
* @param sourceName
* @return
*/
private String getFileSuffix(String sourceName) {
if (StringUtils.isBlank(sourceName) || !sourceName.contains(".")) {
return "";
}
return sourceName.substring(sourceName.lastIndexOf('.'));
}
}

@ -0,0 +1,73 @@
package com.engine.shuzhi.web;
import com.alipay.oceanbase.jdbc.StringUtils;
import com.engine.common.util.ServiceUtil;
import com.engine.shuzhi.service.SzBatchExportService;
import com.engine.shuzhi.service.impl.SzBatchExportServiceImpl;
import weaver.general.Util;
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.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
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.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* @author:dxfeng
* @createTime: 2023/06/02
* @version: 1.0
*/
public class SzBatchExportController {
public SzBatchExportService getService(User user) {
return ServiceUtil.getService(SzBatchExportServiceImpl.class, user);
}
@GET
@Path("/resource/export")
@Produces(MediaType.APPLICATION_OCTET_STREAM)
public Response resourceExport(@Context HttpServletRequest request, @Context HttpServletResponse response,
@QueryParam("ids") String ids) {
List<Long> idList = new ArrayList<>();
if (StringUtils.isNotBlank(ids)) {
idList = Arrays.stream(ids.split(",")).map(Long::parseLong).collect(Collectors.toList());
}
User user = HrmUserVarify.getUser(request, response);
Map<String, Object> map = getService(user).downloadResourceFile(idList);
String zipFilename = Util.null2String(map.get("zipFilename"));
String outPutPath = Util.null2String(map.get("outPutPath"));
try {
zipFilename = URLEncoder.encode(zipFilename, "UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
java.nio.file.Path path = Paths.get(outPutPath);
StreamingOutput output = outputStream -> {
byte[] data = Files.readAllBytes(path);
outputStream.write(data);
outputStream.flush();
};
response.setContentType("application/octet-stream");
return Response.ok(output).header("Content-disposition", "attachment;filename=" + zipFilename).header("Cache-Control", "no-cache").build();
}
}

@ -0,0 +1,55 @@
package weaver.interfaces.shuzhi.cronjob;
import com.engine.shuzhi.entity.po.ModeStaffPO;
import weaver.conn.RecordSet;
import weaver.interfaces.schedule.BaseCronJob;
import java.util.*;
/**
* @author:dxfeng
* @createTime: 2023/06/01
* @version: 1.0
*/
public class SyncModeStaffJob extends BaseCronJob {
private static String SPECIAL_JOB_NAME = "培训生";
@Override
public void execute() {
RecordSet rs = new RecordSet();
String sql;
// 查询培训生的岗位ID
sql = "select id from hrmjobtitles where jobtitlename = ? ";
Set<String> specialJobIds = new HashSet<>();
rs.executeQuery(sql, SPECIAL_JOB_NAME);
while (rs.next()) {
specialJobIds.add(rs.getString("id"));
}
// 查询各个岗位下对应的人员
sql = "select count(id) as num, departmentid, jobtitle from hrmresource where status < 4 group by departmentid, jobtitle";
rs.executeQuery(sql);
List<ModeStaffPO> modeStaffList = new ArrayList<>();
while (rs.next()) {
modeStaffList.add(ModeStaffPO.builder().num(rs.getString("num")).departmentid(rs.getString("departmentid")).jobtitle(rs.getString("jobtitle")).build());
}
// 根据部门+岗位查询最新一个月的记录
if ("sqlserver".equals(rs.getDBType())) {
sql = "select top 1 id, zgrs, bzrs from uf_bzxxbd where bm = ? and gw = ? order by yf desc";
}else if("oracle".equals(rs.getDBType())){
sql = "select id, zgrs, bzrs from uf_bzxxbd where bm = ? and gw = ? and rownum = 1 order by yf desc";
}else{
sql = "select id, zgrs,bzrs from uf_bzxxbd where bm = ? and gw = ? order by yf desc limit 1";
}
for (ModeStaffPO modeStaff : modeStaffList) {
rs.executeQuery(sql, modeStaff.getDepartmentid(), modeStaff.getJobtitle());
if (rs.next()) {
String staffId = rs.getString("id");
String staffNum = rs.getString("bzrs");
// 岗位为培训生编制人数等于在岗人数
modeStaff.setStaffNum(specialJobIds.contains(modeStaff.getJobtitle())?modeStaff.getNum().toString():staffNum);
rs.executeUpdate("update uf_bzxxbd set zgrs = ? ,bzrs = ? ,kbrs = ? where id = ?", modeStaff.getNum(), modeStaff.getStaffNum(), modeStaff.getLackNum(), staffId);
}
}
}
}
Loading…
Cancel
Save