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; } }