|
|
package com.weaver.seconddev.tjzs.cronjob.job.annexSync;
|
|
|
|
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
|
import com.weaver.common.escheduler.handler.annotation.ESchedulerHandler;
|
|
|
import com.weaver.common.hrm.util.HrmCommonUtil;
|
|
|
import com.weaver.eteams.file.client.file.FileObj;
|
|
|
import com.weaver.eteams.file.client.file.StoreResults;
|
|
|
import com.weaver.eteams.file.client.param.RemoteUploadParam;
|
|
|
import com.weaver.eteams.file.client.remote.UploadClientService;
|
|
|
import com.weaver.file.ud.rpc.storage.match.FileStoRuleMatchClient;
|
|
|
import com.weaver.file.ud.storage.match.StoRuleMatchDto;
|
|
|
import com.weaver.file.ud.storage.match.StoRuleMatchParam;
|
|
|
import com.weaver.framework.rpc.annotation.RpcReference;
|
|
|
import com.weaver.seconddev.tjzs.tb.config.EbDbDataSourceConfig;
|
|
|
import com.weaver.teams.domain.EntityType;
|
|
|
import com.weaver.teams.domain.user.SimpleEmployee;
|
|
|
import com.weaver.teams.storage.constant.FileStorage;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.activation.MimetypesFileTypeMap;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.Optional;
|
|
|
|
|
|
/**
|
|
|
* 工资官网历史附件表uf_oldoafile取物理地址,创建附件id
|
|
|
* 根据附件id,关联到官网内容详情表:uf_hornor
|
|
|
*/
|
|
|
@Slf4j
|
|
|
@Service
|
|
|
@Component
|
|
|
public class CompanyAnnexSyncJob {
|
|
|
@Autowired
|
|
|
private JdbcTemplate jdbcTemplate = new JdbcTemplate(EbDbDataSourceConfig.dbDataSource());
|
|
|
/**
|
|
|
* 生产环境系统管理员ID
|
|
|
*/
|
|
|
private final static Long employeeId = 881987666380087298L;//张彦斌
|
|
|
|
|
|
private final static Long folderId = 1450581256459833792L; //公共知识库-公司外网
|
|
|
|
|
|
private final static String tenantKey = "tj02iu5kla";//生产租户key
|
|
|
@RpcReference
|
|
|
private UploadClientService uploadClientService;
|
|
|
|
|
|
@Autowired
|
|
|
private HrmCommonUtil hrmCommonUtil;
|
|
|
|
|
|
@RpcReference
|
|
|
private FileStoRuleMatchClient fileStoRuleMatchClient;
|
|
|
//每天中午12点触发
|
|
|
@ESchedulerHandler(value = "syncCompanyAnnexJob",cron = "0 0 12 * * ?")
|
|
|
public void syncCompanyAnnexJob() {
|
|
|
log.error("附件同步开始howec......");
|
|
|
//获取未同步附件id的所有数据
|
|
|
String sql = "select id,oldoaid,filename,ossid,filesize from uf_oldoafile where fjsfytb <> '1' or fjsfytb is NULL";
|
|
|
List<Map<String, Object>> historylist = jdbcTemplate.queryForList(sql);
|
|
|
if(CollectionUtil.isNotEmpty(historylist)) {
|
|
|
log.error("未同步的uf_oldoafile数据size:"+historylist.size());
|
|
|
for(Map<String, Object> singlemap : historylist) {
|
|
|
String oldid = String.valueOf(singlemap.get("id"));//数据ID
|
|
|
String oldoaid = String.valueOf(singlemap.get("oldoaid"));//关联id
|
|
|
String filename = String.valueOf(singlemap.get("filename"));//文件名称
|
|
|
String ossid = String.valueOf(singlemap.get("ossid")); //附件物理地址路径
|
|
|
String filesize1 = String.valueOf(singlemap.get("filesize")); //文件大小
|
|
|
BigDecimal dw = new BigDecimal("1024");
|
|
|
BigDecimal filesize2 = new BigDecimal(filesize1);
|
|
|
filesize2 = filesize2.multiply(dw).multiply(dw);
|
|
|
Long filesize = filesize2.toBigInteger().longValue();
|
|
|
log.error("oldid:{},oldoaid:{},filename:{},ossid:{},filesize:{}",oldid,oldoaid,filename,ossid,filesize);
|
|
|
//判断关联id在主表uf_hornor中是否存在,存在则上传附件,建立连接
|
|
|
sql = "select count(id) as nums from uf_hornor where IS_DELETE = '0' and oldoa_id = "+oldoaid;
|
|
|
log.error("sql1:::::"+sql);
|
|
|
Map<String,Object> dataExistmap = jdbcTemplate.queryForMap(sql);
|
|
|
long sums = (long)dataExistmap.get("nums");
|
|
|
if(sums == 1l) {
|
|
|
//获取行信息id进行关联
|
|
|
sql = "select id,file_name2 from uf_hornor where IS_DELETE = '0' and oldoa_id = "+oldoaid;
|
|
|
log.error("sql2:::::"+sql);
|
|
|
Map<String, Object> idmap = jdbcTemplate.queryForMap(sql);
|
|
|
//业务id。用于关联某个业务。如:在邮件A上上传几个附件,refId 可以传邮件A的id,
|
|
|
String refId1 = String.valueOf(idmap.get("id"));
|
|
|
Long refId = Long.parseLong(refId1);
|
|
|
String file_name2 = idmap.get("file_name2") == null ? "" : String.valueOf(idmap.get("file_name2"));
|
|
|
//上传附件
|
|
|
SimpleEmployee simpleEmployee = hrmCommonUtil.getSimpleEmployee(employeeId);
|
|
|
//获取文件类型
|
|
|
String contentType = new MimetypesFileTypeMap().getContentType(filename);
|
|
|
//上传时间
|
|
|
String lastModified = String.valueOf(System.currentTimeMillis());
|
|
|
//附近的模块标识,标识为EB表单的模块
|
|
|
String module = EntityType.ebuilderform.name();
|
|
|
//上传的文件是否生成文档,true 生成,false 不生成
|
|
|
boolean createDoc = true;
|
|
|
//标识附件来源,操作来源(用于标识,文件是从哪里操作上传,便于特殊业务逻辑处理)目前取值:
|
|
|
// 1. comment :来源于评论的附件;2. form 来源表单自定义附件字段;3.relation 来源关联附件字段 4.richText 来源富文本 5. fileAuth 主要用于记录鉴权参数
|
|
|
String source = "form";
|
|
|
String s1[] = ossid.split("/");
|
|
|
String url =s1[s1.length-1] ;
|
|
|
String s12 = "/"+s1[s1.length-1];
|
|
|
String filePath = ossid.replace(s12,"");
|
|
|
log.error("howec::::1:::url:{},filePath{}",url,filePath);
|
|
|
//设置物理文件信息
|
|
|
StoreResults storeResults = new StoreResults();
|
|
|
//设置租户key
|
|
|
storeResults.setCurrentTenantKey(tenantKey);
|
|
|
//设置物理关联信息
|
|
|
storeResults.setFileUrl(url);
|
|
|
//设置存储路径
|
|
|
storeResults.setFilePath(filePath);
|
|
|
//设置MD5是否变化,默认false
|
|
|
storeResults.setMd5Change(false);
|
|
|
//设置文件名
|
|
|
storeResults.setFileName(filename);
|
|
|
//设置文件大小
|
|
|
storeResults.setFileRealSize(filesize);
|
|
|
//设置存储规则id
|
|
|
StoRuleMatchParam stoRuleMatchParam = new StoRuleMatchParam.MatchBuilder()
|
|
|
.setEmployeeId(employeeId).extModule(module).setTenantKey(tenantKey).build();
|
|
|
StoRuleMatchDto stoRuleMatchDto = fileStoRuleMatchClient.match(stoRuleMatchParam);
|
|
|
storeResults.setRuleVersionId(stoRuleMatchDto.getRuleVersionId());
|
|
|
//设置存储类型
|
|
|
FileStorage fileStorage = Optional.ofNullable(stoRuleMatchDto.getFileStorage()).orElse(FileStorage.NONE);
|
|
|
storeResults.setStorageType(fileStorage.getStorageKey());
|
|
|
//存储物理文件信息
|
|
|
uploadClientService.saveStorageInfo(storeResults);
|
|
|
//构建请求数据
|
|
|
RemoteUploadParam remoteUploadParam = new RemoteUploadParam(filename,lastModified,module);
|
|
|
remoteUploadParam.setSize(filesize);
|
|
|
remoteUploadParam.setCreateDoc(createDoc);
|
|
|
remoteUploadParam.setFolderId(folderId);
|
|
|
remoteUploadParam.setSource(source);
|
|
|
remoteUploadParam.setUrl(url);
|
|
|
remoteUploadParam.setRefId(refId);
|
|
|
remoteUploadParam.setStoreResults(storeResults);
|
|
|
FileObj fileObj = uploadClientService.remoteUploadSaveData(simpleEmployee,contentType,remoteUploadParam);
|
|
|
Long fjid = fileObj.getId();
|
|
|
if(file_name2.length()>0) {
|
|
|
file_name2 = file_name2+","+fjid;
|
|
|
}else {
|
|
|
file_name2 = fjid.toString();
|
|
|
}
|
|
|
//上传成功,更新同步状态,更新附件
|
|
|
sql = "update uf_hornor set file_name2 = '"+file_name2+"' where id = "+refId;
|
|
|
log.error("sql3:::::"+sql);
|
|
|
jdbcTemplate.execute(sql);
|
|
|
//将历史数据表中的是否已同步更新
|
|
|
sql = "update uf_oldoafile set fjsfytb = '1' where id = "+oldid;
|
|
|
log.error("sql4:::::"+sql);
|
|
|
jdbcTemplate.execute(sql);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|