2023-09-26 15:21:22 +08:00
package weaver.formmode.recruit.modeexpand.util ;
2023-11-09 14:34:44 +08:00
import com.api.mobilemode.util.FieldHandler ;
2023-09-26 15:21:22 +08:00
import com.cloudstore.dev.api.bean.MessageBean ;
import com.cloudstore.dev.api.bean.MessageType ;
import com.cloudstore.dev.api.util.Util_Message ;
2023-11-09 14:34:44 +08:00
import com.engine.recruit.conn.ApplicantCommonInfo ;
import com.weaver.formmodel.data.manager.FormInfoManager ;
import com.weaver.formmodel.data.model.Formfield ;
import org.apache.commons.collections.CollectionUtils ;
2023-09-26 18:50:30 +08:00
import org.apache.commons.lang3.StringUtils ;
2023-10-17 15:18:53 +08:00
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 ;
2023-09-26 15:21:22 +08:00
import weaver.general.BaseBean ;
2023-10-17 15:18:53 +08:00
import weaver.general.TimeUtil ;
2023-11-09 14:34:44 +08:00
import weaver.general.Util ;
2023-10-17 15:18:53 +08:00
import weaver.hrm.User ;
2023-09-26 15:21:22 +08:00
import weaver.hrm.resource.ResourceComInfo ;
import java.io.IOException ;
2023-11-13 09:42:14 +08:00
import java.io.InputStream ;
2023-09-27 13:35:02 +08:00
import java.nio.charset.StandardCharsets ;
2023-10-27 16:50:24 +08:00
import java.util.* ;
2023-11-09 14:34:44 +08:00
import java.util.regex.Matcher ;
import java.util.regex.Pattern ;
2023-10-27 16:50:24 +08:00
import java.util.stream.Collectors ;
2023-09-26 15:21:22 +08:00
/ * *
* @author : dxfeng
* @createTime : 2023 / 09 / 26
* @version : 1 . 0
* /
public class RecruitModeUtil {
2023-11-09 14:34:44 +08:00
private static final Pattern MSG_PATTERN = Pattern . compile ( Pattern . quote ( " { " ) + " (.*?) " + Pattern . quote ( " } " ) ) ;
2023-09-26 15:21:22 +08:00
/ * *
* 消息推送
*
* @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 ) {
2023-10-20 15:52:26 +08:00
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 ) {
2023-09-26 15:21:22 +08:00
MessageType message = MessageType . newInstance ( Integer . parseInt ( messageType ) ) ;
try {
2023-10-20 15:52:26 +08:00
MessageBean messageBean = Util_Message . createMessage ( message , userIdList , title , context , linkUrl , linkMobileUrl ) ;
2023-09-26 15:21:22 +08:00
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 ) ;
}
}
/ * *
* 获取聚才林招聘相关配置文件
*
2023-09-27 13:35:02 +08:00
* @param key key
* @return value
2023-09-26 15:21:22 +08:00
* /
public static String getRecruitPropValue ( String key ) {
String value = new BaseBean ( ) . getPropValue ( " jclRecruit " , key ) ;
2023-09-27 13:35:02 +08:00
value = new String ( value . getBytes ( StandardCharsets . ISO_8859_1 ) , StandardCharsets . UTF_8 ) ;
2023-09-26 15:21:22 +08:00
return value ;
}
2023-09-26 18:50:30 +08:00
/ * *
* 转换空字符串为null
*
* @param str 字符串
* @return 转换后的字符串
* /
public static Object parseBlankToNull ( String str ) {
return StringUtils . isBlank ( str ) ? null : str ;
}
2023-10-17 15:18:53 +08:00
/ * *
* 转换空字符串为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
* /
2023-11-13 09:42:14 +08:00
public static int generateImageFileId ( InputStream inputStream , String filename ) {
2023-10-17 15:18:53 +08:00
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 ;
}
2023-11-09 14:34:44 +08:00
public static List < Formfield > getFieldList ( String tableName ) {
int formId = ApplicantCommonInfo . getFormIdByTableName ( tableName ) ;
return FormInfoManager . getInstance ( ) . getAllField ( formId ) ;
}
public static String getFieldShowName ( Formfield formfield , String fieldName ) {
User user = new User ( 1 ) ;
return FieldHandler . getFieldValue ( fieldName , formfield , true , user ) ;
}
public static String getReplaceContent ( String content , Map < String , List < Formfield > > fieldMapList , Map < String , Object > paramsData ) {
Matcher matcher = MSG_PATTERN . matcher ( content ) ;
// 指定要匹配的字符串
StringBuffer sb = new StringBuffer ( ) ;
while ( matcher . find ( ) ) {
String replace = matcher . group ( 1 ) ;
List < Formfield > formFieldList = fieldMapList . get ( replace ) ;
if ( CollectionUtils . isEmpty ( formFieldList ) ) {
continue ;
}
// 多个相同名称的字段,只取第一个
Formfield formfield = formFieldList . get ( 0 ) ;
String replaceValue = Util . null2String ( paramsData . get ( formfield . getFieldname ( ) . toLowerCase ( ) ) ) ;
String fieldShowName = RecruitModeUtil . getFieldShowName ( formfield , replaceValue ) . replaceAll ( " <[^>]*> " , " " ) ;
matcher . appendReplacement ( sb , Util . null2String ( fieldShowName ) ) ;
}
matcher . appendTail ( sb ) ;
return sb . toString ( ) ;
}
2023-10-17 15:18:53 +08:00
/ * *
* 附件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 ;
}
2023-11-08 09:37:13 +08:00
public static String getImageFileIdsByDocIds ( String docId ) {
if ( StringUtils . isBlank ( docId ) ) {
return " " ;
}
List < String > imageFileIds = new ArrayList < > ( ) ;
String [ ] split = docId . split ( " , " ) ;
try {
for ( String s : split ) {
if ( StringUtils . isBlank ( s ) ) {
continue ;
}
DocImageManager imgManger = new DocImageManager ( ) ;
imgManger . setDocid ( Integer . parseInt ( s ) ) ;
imgManger . selectDocImageInfo ( ) ;
imgManger . next ( ) ;
imageFileIds . add ( imgManger . getImagefileid ( ) ) ;
}
} catch ( Exception e ) {
throw new RuntimeException ( e ) ;
}
return StringUtils . join ( imageFileIds , " , " ) ;
}
2023-10-27 16:50:24 +08:00
/ * *
* @Author ml
* @Date 2023 / 10 / 23 18 : 21
* @Description 根据建模表名称获取列名称
* @Param [ tableName ]
2023-11-08 09:37:13 +08:00
* @Return Map < Object , List < Map < String , Object > > >
2023-10-27 16:50:24 +08:00
* /
2023-11-08 09:37:13 +08:00
public static Map < String , Object > getModeColumns ( String tableName ) {
2023-10-27 16:50:24 +08:00
RecordSet rs = new RecordSet ( ) ;
2023-11-08 09:37:13 +08:00
List < Map < String , String > > mapList = new ArrayList < > ( ) ;
2023-10-27 16:50:24 +08:00
Map < String , String > tmpMap = new HashMap < > ( 16 ) ;
2023-11-08 09:37:13 +08:00
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 ) ;
2023-10-27 16:50:24 +08:00
while ( rs . next ( ) ) {
2023-11-08 09:37:13 +08:00
tmpMap . put ( " fieldname " , rs . getString ( " FIELDNAME " ) ) ;
tmpMap . put ( " viewtype " , rs . getString ( " VIEWTYPE " ) ) ;
2023-10-27 16:50:24 +08:00
mapList . add ( tmpMap ) ;
}
2023-11-08 09:37:13 +08:00
Map < String , List < Map < String , String > > > dataMap = mapList . stream ( ) . collect ( Collectors . groupingBy ( item - > item . get ( " viewtype " ) ) ) ;
Map < String , Object > resMap = new HashMap < > ( ) ;
2023-10-27 16:50:24 +08:00
for ( String key : dataMap . keySet ( ) ) {
2023-11-08 09:37:13 +08:00
resMap . put ( key , dataMap . get ( key ) . stream ( ) . map ( Map - > Map . get ( " fieldname " ) ) . collect ( Collectors . toList ( ) ) ) ;
2023-10-27 16:50:24 +08:00
}
return resMap ;
}
public static String getQuerySql ( String tableName ) {
2023-11-08 09:37:13 +08:00
Map < String , Object > params = getModeColumns ( tableName ) ;
2023-10-27 16:50:24 +08:00
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 < > ( ) ;
2023-11-08 09:37:13 +08:00
oldlist . forEach ( field - > list . add ( " t " + key + " . " + field ) ) ;
fieldSql = StringUtils . join ( list , " , " ) ;
2023-10-27 16:50:24 +08:00
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 " ) ;
}
2023-11-08 09:37:13 +08:00
return " select " + fieldSql + " from " + whereSql + " where t0.id=? " ;
2023-10-27 16:50:24 +08:00
}
/ * *
* 获取邮件模板主题
2023-11-08 09:37:13 +08:00
*
2023-10-27 16:50:24 +08:00
* @param id
* /
2023-11-08 09:37:13 +08:00
public static String getEmailTitle ( String id ) {
2023-10-27 16:50:24 +08:00
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 ;
}
2023-09-26 15:21:22 +08:00
}