You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
138 lines
5.1 KiB
Java
138 lines
5.1 KiB
Java
package com.docus.webservice.service;
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
import com.docus.webservice.dto.CollectList;
|
|
import com.docus.webservice.entity.AfInterfaceCollect;
|
|
import com.docus.webservice.entity.AfInterfaceCollectSub;
|
|
import com.docus.webservice.entity.Pcmachine;
|
|
import com.docus.webservice.entity.TBasic;
|
|
import com.docus.webservice.enums.Codes;
|
|
import com.docus.webservice.mapper.AfInterfaceCollectMapper;
|
|
import com.docus.webservice.mapper.PcmachineMapper;
|
|
import com.docus.webservice.utils.HttpUtils;
|
|
import com.docus.webservice.utils.JsonUtils;
|
|
import com.docus.webservice.utils.SnowflakeIdWorker;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.logging.log4j.LogManager;
|
|
import org.apache.logging.log4j.Logger;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.scheduling.annotation.Async;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
import java.io.File;
|
|
import java.io.IOException;
|
|
import java.net.URISyntaxException;
|
|
import java.util.*;
|
|
|
|
@Service
|
|
public class PcmachineServiceImpl implements IPcmachineService {
|
|
|
|
private Logger log= LogManager.getLogger();
|
|
|
|
@Autowired
|
|
PcmachineMapper pcmachineMapper;
|
|
|
|
@Autowired
|
|
private AfInterfaceCollectMapper afInterfaceCollectMapper;
|
|
|
|
|
|
@Override
|
|
public void beat(String code, String ip) {
|
|
String name=pcmachineMapper.getNameByCode(code);
|
|
String id= pcmachineMapper.getIdByName(name);
|
|
Pcmachine pcmachine=new Pcmachine();
|
|
pcmachine.setId(Long.parseLong(id));
|
|
pcmachine.setIpaddress(ip);
|
|
pcmachine.setLastonline(new Date());
|
|
pcmachine.setPcstatus(1);
|
|
pcmachineMapper.update(pcmachine);
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
public void isBeat() {
|
|
pcmachineMapper.isBeat();
|
|
}
|
|
|
|
@Override
|
|
public Integer count() {
|
|
return pcmachineMapper.count();
|
|
}
|
|
|
|
/**
|
|
* 获取jar包所在位置
|
|
*
|
|
* @return
|
|
*/
|
|
private String CurrentPath() {
|
|
File dir = new File(".");
|
|
String currentpath = "";
|
|
try {
|
|
currentpath = dir.getCanonicalPath();
|
|
} catch (IOException e) {
|
|
e.printStackTrace();
|
|
}
|
|
return currentpath;
|
|
}
|
|
|
|
@Async("execCollector")
|
|
@Override
|
|
public void saveAndCall(TBasic tBasic) throws URISyntaxException {
|
|
log.info("--------------异步调用此方法---------------");
|
|
log.info("病案对象" + tBasic.toString());
|
|
//解析json映射文件
|
|
String json = JsonUtils.readJsonFile(CurrentPath() + Codes.JSON_COLLECTLIST.getMessage());
|
|
if (StringUtils.isNotBlank(json)) {
|
|
Map jsonMap = JSON.parseObject(json, Map.class);
|
|
//任务数
|
|
Integer task_count = JSON.parseObject(String.valueOf(jsonMap.get(Codes.JSON_TASK_COUNT.getMessage())), Integer.class);
|
|
|
|
List<CollectList> collectLists = JSON.parseArray(String.valueOf(jsonMap.get(Codes.JSON_COLLECTLIST_ROOT.getMessage())), CollectList.class);
|
|
|
|
//添加省中医病案采集
|
|
SnowflakeIdWorker idWorker = new SnowflakeIdWorker(0, 0);
|
|
AfInterfaceCollect afc = new AfInterfaceCollect();
|
|
Long afcId = idWorker.nextId();
|
|
afc.setId(afcId);
|
|
afc.setJzh(tBasic.getJzh());
|
|
afc.setTaskCount(task_count);
|
|
afc.setCreateTime(new Date());
|
|
int i = afInterfaceCollectMapper.addAfInterfaceCollect(afc);
|
|
if (i < 0) {
|
|
log.info("省中医病案采集表添加信息失败!");
|
|
}
|
|
//添加省中医病案采集-子任务
|
|
List<AfInterfaceCollectSub> list = new ArrayList<>();
|
|
for (CollectList collectList : collectLists) {
|
|
AfInterfaceCollectSub afInterfaceCollectSub = new AfInterfaceCollectSub();
|
|
Long afcsId = idWorker.nextId();
|
|
afInterfaceCollectSub.setId(afcsId);
|
|
afInterfaceCollectSub.setAfInterfaceCollectId(afcId);
|
|
afInterfaceCollectSub.setCollectsysCode(collectList.getCollectsys_code());
|
|
afInterfaceCollectSub.setJzh(tBasic.getJzh());
|
|
collectList.setId(afcsId);
|
|
list.add(afInterfaceCollectSub);
|
|
}
|
|
int i1 = afInterfaceCollectMapper.addAfInterfaceCollectSub(list);
|
|
if (i1 < 0) {
|
|
log.info("省中医病案采集-子任务失败!");
|
|
}
|
|
for (CollectList collectList : collectLists) {
|
|
//调用http发送请求
|
|
this.sendHttp(collectList, tBasic.getJzh());
|
|
}
|
|
|
|
}
|
|
log.info("----------异步结束---------------");
|
|
}
|
|
|
|
private String sendHttp(CollectList collectList, String jzh) throws URISyntaxException {
|
|
Map<String, String> params = new HashMap<>();
|
|
params.put("empId", jzh);
|
|
params.put("collectSubId", String.valueOf(collectList.getId()));
|
|
return HttpUtils.get(collectList.getRequestUrl(), params);
|
|
}
|
|
}
|