weaver-hrm-recruit/src/weaver/formmode/recruit/modeexpand/util/RecruitModeUtil.java

262 lines
8.9 KiB
Java

package weaver.formmode.recruit.modeexpand.util;
import com.cloudstore.dev.api.bean.MessageBean;
import com.cloudstore.dev.api.bean.MessageType;
import com.cloudstore.dev.api.util.Util_Message;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.util.IOUtils;
import weaver.conn.RecordSet;
import weaver.docs.docs.DocCoder;
import weaver.docs.docs.DocComInfo;
import weaver.docs.docs.DocImageManager;
import weaver.docs.docs.DocManager;
import weaver.file.ImageFileManager;
import weaver.general.BaseBean;
import weaver.general.TimeUtil;
import weaver.hrm.User;
import weaver.hrm.resource.ResourceComInfo;
import java.io.BufferedInputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.stream.Collectors;
/**
* @author:dxfeng
* @createTime: 2023/09/26
* @version: 1.0
*/
public class RecruitModeUtil {
/**
* 消息推送
*
* @param messageType 消息来源
* @param title 消息标题
* @param context 消息内容
* @param userIdList 接收人ID集合
* @param creater 消息创建者
*/
public static void messagePush(String messageType, String title, String context, Set<String> userIdList, Integer creater) {
messagePush(messageType, title, context, userIdList, creater, "", "");
}
/**
* @param messageType 消息来源
* @param title 消息标题
* @param context 消息内容
* @param userIdList 接收人ID集合
* @param creater 消息创建者
* @param linkUrl 待办跳转地址
* @param linkMobileUrl 移动端跳转地址
*/
public static void messagePush(String messageType, String title, String context, Set<String> userIdList, Integer creater, String linkUrl, String linkMobileUrl) {
MessageType message = MessageType.newInstance(Integer.parseInt(messageType));
try {
MessageBean messageBean = Util_Message.createMessage(message, userIdList, title, context, linkUrl, linkMobileUrl);
messageBean.setCreater(creater);
Util_Message.store(messageBean);
} catch (IOException e) {
new BaseBean().writeLog(e);
e.printStackTrace();
}
}
/**
* 获取人员姓名
*
* @param ids 人员ID
* @return 人员姓名
*/
public static String getResourceNames(String ids) {
try {
return new ResourceComInfo().getLastnames(ids);
} catch (Exception e) {
new BaseBean().writeLog(e);
throw new RuntimeException(e);
}
}
/**
* 获取聚才林招聘相关配置文件
*
* @param key key
* @return value
*/
public static String getRecruitPropValue(String key) {
String value = new BaseBean().getPropValue("jclRecruit", key);
value = new String(value.getBytes(StandardCharsets.ISO_8859_1), StandardCharsets.UTF_8);
return value;
}
/**
* 转换空字符串为null
*
* @param str 字符串
* @return 转换后的字符串
*/
public static Object parseBlankToNull(String str) {
return StringUtils.isBlank(str) ? null : str;
}
/**
* 转换空字符串为null
*
* @param obj 对象
* @return 转换后的字符串
*/
public static String parseBlankToNull(Object obj) {
return Objects.isNull(obj) ? null : StringUtils.isBlank(obj.toString()) ? null : obj.toString();
}
/**
* 生成附件ID
*
* @param inputStream
* @param filename
* @return
*/
public static int generateImageFileId(BufferedInputStream inputStream, String filename) {
int imageFileId;
try {
byte[] bytes = IOUtils.toByteArray(inputStream);
ImageFileManager ifm = new ImageFileManager();
ifm.setData(bytes);
ifm.setImagFileName(filename);
imageFileId = ifm.saveImageFile();
} catch (IOException e) {
throw new RuntimeException(e);
}
return imageFileId;
}
/**
* 附件imageFieldId生成docId
*
* @param secCategory
* @param imageFieldId
* @param user
* @return
* @throws Exception
*/
public static int createDocId(int secCategory, int imageFieldId, User user) throws Exception {
ImageFileManager manager = new ImageFileManager();
manager.getImageFileInfoById(imageFieldId);
String filenameqc = manager.getImageFileName();
String filenamebc = filenameqc.substring(0, filenameqc.lastIndexOf("."));
RecordSet rs = new RecordSet();
DocManager dm = new DocManager();
DocImageManager imgManger = new DocImageManager();
imgManger.setDocfiletype("2");
int docId = dm.getNextDocId(rs);
imgManger.setDocid(docId);
imgManger.setImagefileid(imageFieldId);
imgManger.setImagefilename(filenameqc);
imgManger.setIsextfile("1");
imgManger.AddDocImageInfo();
String date = TimeUtil.getCurrentDateString();
String time = TimeUtil.getOnlyCurrentTimeString();
dm.setId(docId);
dm.setMaincategory(0);
dm.setSubcategory(0);
dm.setSeccategory(secCategory);
dm.setLanguageid(user.getLanguage());
dm.setDocstatus("1");
dm.setDocsubject(filenamebc);
dm.setDoccreaterid(user.getUID());
dm.setDocCreaterType(user.getLogintype());
dm.setUsertype(user.getLogintype());
dm.setOwnerid(user.getUID());
dm.setOwnerType(user.getLogintype());
dm.setDoclastmoduserid(user.getUID());
dm.setDocLastModUserType(user.getLogintype());
dm.setDoccreatedate(date);
dm.setDoclastmoddate(date);
dm.setDoccreatetime(time);
dm.setDoclastmodtime(time);
dm.setDoclangurage(user.getLanguage());
dm.setKeyword(filenameqc);
dm.setIsapprover("0");
dm.setIsreply("");
dm.setDocdepartmentid(user.getUserDepartment());
dm.setDocreplyable("1");
dm.setAccessorycount(1);
dm.setParentids("" + docId);
dm.setUserid(user.getUID());
DocCoder docCoder = new DocCoder();
dm.setDocCode(docCoder.getDocCoder("" + secCategory));
dm.setDocEditionId(dm.getNextEditionId(rs));
dm.setDocEdition(1);
dm.AddDocInfo();
dm.AddShareInfo();
DocComInfo dc = new DocComInfo();
dc.addDocInfoCache("" + docId);
return docId;
}
/**
* @Author ml
* @Date 2023/10/23 18:21
* @Description 根据建模表名称获取列名称
* @Param [tableName]
* @Return Map<Object,List<Map<String,Object>>>
*/
public static Map<String,Object> getModeColumns(String tableName) {
RecordSet rs = new RecordSet();
List<Map<String,String>> mapList = new ArrayList<>();
Map<String, String> tmpMap = new HashMap<>(16);
rs.executeQuery("select b.FIELDNAME,b.VIEWTYPE from workflow_bill a left join workflow_billfield b on a.id = b.BILLID where a.TABLENAME = ?",tableName);
while (rs.next()) {
tmpMap.put("fieldname",rs.getString("FIELDNAME"));
tmpMap.put("viewtype",rs.getString("VIEWTYPE"));
mapList.add(tmpMap);
}
Map<String,List<Map<String,String>>> dataMap = mapList.stream().collect(Collectors.groupingBy(item -> item.get("viewtype")));
Map<String,Object> resMap = new HashMap<>();
for (String key : dataMap.keySet()) {
resMap.put(key,dataMap.get(key).stream().map(Map -> Map.get("fieldname")).collect(Collectors.toList()));
}
return resMap;
}
public static String getQuerySql(String tableName) {
Map<String,Object> params = getModeColumns(tableName);
String fieldSql = "";
StringBuilder whereSql = new StringBuilder();
whereSql.append(tableName).append(" t0");
for (String key : params.keySet()) {
List<String> oldlist = (List<String>) params.get(key);
List<String> list = new ArrayList<>();
oldlist.forEach(field -> list.add("t"+key+"."+field));
fieldSql = StringUtils.join(list,",");
if ("0".equals(key)) {
continue;
}
whereSql.append(" left join ").append(tableName).append("_dt").append(key).append(" ").append("t").append(key).append(" on t0.id=").append("t").append(key).append(".mainid");
}
return "select "+fieldSql+" from " + whereSql + " where t0.id=?";
}
/**
* 获取邮件模板主题
* @param id
*/
public static String getEmailTitle (String id) {
RecordSet recordSet = new RecordSet();
String emailTitle = "";
recordSet.executeQuery("select yjzt from uf_jcl_yjtzmb where id = ?", id);
if (recordSet.next()) {
emailTitle = recordSet.getString("yjzt");
}
return emailTitle;
}
}