提交 65e95160 编写于 作者: MoneyQ's avatar MoneyQ

增加新文件

上级 6fe4bd4c
package com.ibiz.core.ht.service.impl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.ibiz.core.ht.domain.IM;
import com.ibiz.core.ht.filter.IMSearchContext;
import com.ibiz.core.ht.service.IIMService;
import com.ibiz.core.r7rt_org.domain.OrgDeptUser;
import com.ibiz.core.r7rt_org.filter.OrgDeptUserSearchContext;
import com.ibiz.core.r7rt_org.filter.OrgUserSearchContext;
import com.ibiz.core.r7rt_org.service.IOrgDeptUserService;
import com.ibiz.core.r7rt_org.service.IOrgUserService;
import com.ibiz.util.config.UniWFClientProperties;
import com.ibiz.util.feign.FeignRequestInterceptor;
import com.ibiz.util.feign.UniWFFeignClient;
import com.ibiz.util.feign.suport.SearchContextFeignEncode;
import com.ibiz.util.helper.SpringContextHolder;
import com.ibiz.util.security.userdetail.LoginUser;
import feign.Client;
import feign.Contract;
import feign.Feign;
import feign.codec.Decoder;
import feign.codec.Encoder;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.openfeign.ribbon.LoadBalancerFeignClient;
import org.springframework.context.annotation.Primary;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
* 实体[重要事项] 服务对象接口实现
*/
@Service
@Primary
@Slf4j
public class UsrIMServiceImpl extends IMServiceImpl {
@Autowired
IOrgUserService iOrgUserService;
@Autowired
IOrgDeptUserService iOrgDeptUserService;
UniWFClientProperties uniWFClientProperties;
UniWFFeignClient uniWFFeignClient;
@Autowired
public UsrIMServiceImpl(Decoder decoder, Encoder encoder, Client client, Contract contract, FeignRequestInterceptor feignRequestInterceptor,
UniWFClientProperties uniWFClientProperties) {
this.uniWFClientProperties = uniWFClientProperties;
if (uniWFClientProperties.getServiceId()!=null) {
Feign.Builder nameBuilder = Feign.builder()
.client(client)
.encoder(encoder)
.decoder(decoder)
.contract(contract)
.requestInterceptor(feignRequestInterceptor)
;
this.uniWFFeignClient = nameBuilder.target(UniWFFeignClient.class,"http://" + uniWFClientProperties.getServiceId() + "/") ;
} else if (uniWFClientProperties.getServiceUrl()!=null) {
if (client instanceof LoadBalancerFeignClient) {
client = ((LoadBalancerFeignClient) client).getDelegate();
}
Feign.Builder nameBuilder = Feign.builder()
.client(client)
.encoder(encoder)
.decoder(decoder)
.contract(contract)
.requestInterceptor(feignRequestInterceptor)
;
this.uniWFFeignClient = nameBuilder.target(UniWFFeignClient.class, "http://" + uniWFClientProperties.getServiceUrl() + "/") ;
}
}
@Override
@Transactional
public IM getMP(IM im) {
if (im == null) {
return im;
}
// 部门领导
im.setBmldids(analysisPickupData3(im.getBmld()));
// 领导
im.setLdids(analysisPickupData3(im.getLd()));
// 跨公司部门领导
im.setKgsldids(analysisPickupData3(im.getKgsld()));
// 内部审核
im.setNgshids(analysisPickupData3(im.getNgsh()));
// 会签部门
im.setHqbmids(getOrgUserByDept2(analysisPickupData2(im.getHqbm())));
// 跨公司部门
im.setKgsbmids(getOrgUserByDept2(analysisPickupData2(im.getKgsbm())));
return im;
}
@Override
public IM createAndStart(IM im) {
if (im == null) {
return null;
}
// 创建im数据
this.create(im);
String orgUserId = im.getCreateMan();
JSONObject loginUser = new JSONObject();
loginUser.put("personId", "062a3530-ea68-b7b8-6781-c977cd295995");
loginUser.put("orgUserName", "MoneyQ");
loginUser.put("orgId", "7feb41d6ba62a0a2a816cd5c76ce18e7");
loginUser.put("orgName", "华泰证券股份有限公司");
loginUser.put("orgDeptId", "857e21e5-6df8-f12f-d07b-f1ce95573c4d");
loginUser.put("orgDeptName", "综合管理部");
// 流程启动
JSONObject data = new JSONObject();
data.put("proxymoduleid", "IM");
data.put("proxydataid", im.getIMId());
data.put("loginuser", loginUser);
StartWFThread startWFThread = new StartWFThread("e3300d30bd7a736b2df727f2c5945348", data);
startWFThread.start();
return im;
}
/**
* 根据部门标识获取人员清单(String) 方法1<br>
* 目标数据格式<br>
* key1,key2,key3,key4
*
* @param deptids 部门标识列表
* @return 人员清单(String);没有数据则返回null
*/
private String getOrgUserByDept1(List<String> deptids) {
if (deptids == null) {
return null;
}
List<String> rstList = new ArrayList<>();
for (String deptid : deptids) {
OrgDeptUserSearchContext hqbmCond = new OrgDeptUserSearchContext();
hqbmCond.setN_orgdeptid_eq(deptid);
hqbmCond.setPageable(PageRequest.of(0, 1000));
Page<OrgDeptUser> users = iOrgDeptUserService.searchDefault(hqbmCond);
if (users == null || users.getContent().size() == 0) {
return null;
}
for (OrgDeptUser user : users) {
rstList.add(user.getOrgUserId());
}
}
return String.join(",", rstList);
}
/**
* 根据部门标识获取人员清单(String) 方法2<br>
* 目标数据格式<br>
* [{"srfmajortext":"majortext1","srfkey":"key1"},{"srfmajortext":"majortext2","srfkey":"key2"},{"srfmajortext":"majortext3","srfkey":"key3"},{"srfmajortext":"majortext4","srfkey":"key4"}]
*
* @param deptids 部门标识列表
* @return 人员清单(String);没有数据则返回null
*/
private String getOrgUserByDept2(List<String> deptids) {
if (deptids == null) {
return null;
}
List<PickupData> rstList = new ArrayList<>();
for (String deptid : deptids) {
OrgDeptUserSearchContext hqbmCond = new OrgDeptUserSearchContext();
hqbmCond.setN_orgdeptid_eq(deptid);
hqbmCond.setPageable(PageRequest.of(0, 1000));
Page<OrgDeptUser> users = iOrgDeptUserService.searchDefault(hqbmCond);
if (users == null || users.getContent().size() == 0) {
return null;
}
for (OrgDeptUser user : users) {
PickupData pickupData = new PickupData();
pickupData.setSrfkey(user.getOrgUserId());
pickupData.setSrfmajortext(user.getOrgUserName());
rstList.add(pickupData);
}
}
return JSONArray.toJSONString(rstList);
}
/**
* 解析地址选择栏数据 方法1<br>
* 源数据<br>
* [{"srfmajortext":"majortext1","srfkey":"key1"},{"srfmajortext":"majortext2","srfkey":"key2"},{"srfmajortext":"majortext3","srfkey":"key3"},{"srfmajortext":"majortext4","srfkey":"key4"}]<br>
* 目标数据(String)<br>
* key1,key2,key3,key4
*
* @param oriStr 带解析数据
* @return 解析之后的数据;不符合规则的则返回null
*/
private String analysisPickupData1(String oriStr) {
List<String> rstList = analysisPickupData2(oriStr);
if (rstList == null) {
return null;
}
return String.join(",", rstList);
}
/**
* 解析地址选择栏数据 方法2<br>
* 源数据<br>
* [{"srfmajortext":"majortext1","srfkey":"key1"},{"srfmajortext":"majortext2","srfkey":"key2"},{"srfmajortext":"majortext3","srfkey":"key3"},{"srfmajortext":"majortext4","srfkey":"key4"}]<br>
* 目标数据(List)<br>
* [key1,key2,key3,key4]
*
* @param oriStr 带解析数据
* @return 解析之后的数据;不符合规则的则返回null
*/
private List<String> analysisPickupData2(String oriStr) {
if (oriStr == null || oriStr.isEmpty()) {
return null;
}
log.debug("analysisPickupData2 (" + oriStr + ")");
JSONArray array = JSONArray.parseArray(oriStr);
if (array == null || array.size() == 0) {
return null;
}
List<String> rstList = new ArrayList<>();
for (int i = 0; i < array.size(); i++) {
JSONObject jo = array.getJSONObject(i);
rstList.add(jo.getString("srfkey"));
}
return rstList;
}
/**
* 解析地址选择栏数据 方法3(无变动)<br>
* 源数据<br>
* [{"srfmajortext":"majortext1","srfkey":"key1"},{"srfmajortext":"majortext2","srfkey":"key2"},{"srfmajortext":"majortext3","srfkey":"key3"},{"srfmajortext":"majortext4","srfkey":"key4"}]<br>
* 目标数据(String)<br>
* [{"srfmajortext":"majortext1","srfkey":"key1"},{"srfmajortext":"majortext2","srfkey":"key2"},{"srfmajortext":"majortext3","srfkey":"key3"},{"srfmajortext":"majortext4","srfkey":"key4"}]
*
* @param oriStr 带解析数据
* @return 解析之后的数据;不符合规则的则返回null
*/
private String analysisPickupData3(String oriStr) {
return oriStr;
}
@Data
private class PickupData {
private String srfmajortext;
private String srfkey;
}
private class StartWFThread extends Thread{
private String pswfversion_id;
private JSONObject data;
StartWFThread(String pswfversion_id, JSONObject data) {
this.pswfversion_id = pswfversion_id;
this.data = data;
}
@Override
public void run(){
uniWFFeignClient.apiWfStart(pswfversion_id, data);
}
}
}
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册