DrawServiceImpl.java
3.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package com.huaheng.pc.draw.service.impl;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.huaheng.common.exception.service.ServiceException;
import com.huaheng.common.utils.StringUtils;
import com.huaheng.common.utils.http.HttpUtils;
import com.huaheng.framework.datasource.DynamicDataSource;
import com.huaheng.pc.draw.domain.Draw;
import com.huaheng.pc.draw.mapper.DrawMapper;
import com.huaheng.pc.draw.service.IDrawService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
/**
* @author xcq
*/
@Service
public class DrawServiceImpl implements IDrawService {
@Resource
private DrawMapper drawMapper;
@Override
public Draw queryDraw(String no) {
// 切换至oracle数据库
// DynamicDataSource.slave();
if (StringUtils.isEmpty(no)){
return null;
}
return drawMapper.selectDraw(no);
}
@Override
public String getRid() throws Exception {
String url="http://172.16.0.137:8087/sipmweb/api/oauth?uname=cshuaheng&passwd=545b1973279637b638cf8b0326cac72c&f=true";
String res = HttpUtils.sendGet(url);
if (StringUtils.isNotEmpty(res)){
JSONObject obj = JSONObject.parseObject(res);
return obj.getString("errmsg");
}else {
throw new ServiceException("获取鉴权码rid失败!");
}
}
@Override
public Draw getDrawPartsList(String rid, String no) throws Exception {
if (StringUtils.isEmpty(rid) || StringUtils.isEmpty(no)){
throw new ServiceException("rid或物料编码不能为空值!");
}
String url = "http://172.16.0.137:8087/sipmweb/api/"+rid+"/search/MPART?key="+no+"&start=0&size=1&extra=DWGSW";
String res= HttpUtils.sendGet(url);
if (StringUtils.isEmpty(res)){
throw new ServiceException("查询PLM图纸失败!");
}
JSONObject obj = JSONObject.parseObject(res);
List<Draw> drawList = JSONArray.parseArray(obj.getString("list"), Draw.class);
if (drawList == null){
throw new ServiceException("获取图纸零部件列表失败!");
}
Draw draw = drawList.get(0);
if (draw != null){
draw.setRid(rid);
}
return draw;
}
@Override
public Draw getDraw2DList(Draw draw) {
if (draw == null){
throw new ServiceException("请勿提交空数据!");
}
String url = "http://172.16.0.137:8087/sipmweb/api/"+draw.getRid()+"/relation/MPART/"+draw.getObjId()+"/data?re=MPART_DWGSW&extra=&item=DWGSW";
String res = HttpUtils.sendGet(url);
if (StringUtils.isEmpty(res)){
throw new ServiceException("查询PLM图纸失败!");
}
JSONObject obj = JSONObject.parseObject(res);
List<Draw> drawList = JSONArray.parseArray(obj.getString("list"), Draw.class);
if (drawList == null){
throw new ServiceException("按零件ID获取二维图档列表失败!");
}
Draw data = drawList.get(0);
if (data != null){
data.setRid(draw.getRid());
}
return data;
}
}