Browse Source

2023-12-25 修改

master
fengyuan_yang 2 years ago
parent
commit
97b4162b42
  1. 78
      src/main/java/com/spring/modules/base/utils/HttpClientUtil.java
  2. 2
      src/main/java/com/spring/modules/part/mapper/PartInformationMapper.java
  3. 100
      src/main/java/com/spring/modules/part/service/impl/PartInformationServiceImpl.java
  4. 8
      src/main/resources/mapper/part/PartInformationMapper.xml

78
src/main/java/com/spring/modules/base/utils/HttpClientUtil.java

@ -1,6 +1,7 @@
package com.spring.modules.base.utils;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.parser.Feature;
import com.spring.common.utils.R;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringEscapeUtils;
@ -14,8 +15,13 @@ import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@ -31,6 +37,9 @@ import java.util.Map;
@Slf4j
public class HttpClientUtil {
//记录日志使用
private static final Logger logger = LoggerFactory.getLogger(HttpClientUtil.class);
/**
*
* @Title: doGet
@ -247,4 +256,73 @@ public class HttpClientUtil {
}
return responseData;
}
/**
*
* @Title: doPostByRawWithMlin
* @Description: 多条专用方法 调用设备的接口
* @param url
* @param inData
* @return
* @author: LR
* @return: ResponseData
* @throws
*/
public static ResponseData doPostByRawWithPLM(String url, Object inData){
ResponseData responseData = new ResponseData();
try {
HttpClient httpClient = HttpClients.createDefault();
HttpPost httpPost = new HttpPost(url);
String jsonStr = JSON.toJSONString(inData);
StringEntity requestEntity = new StringEntity(jsonStr, "UTF-8");
requestEntity.setContentEncoding("UTF-8");
httpPost.setHeader("Content-type", "application/json");
httpPost.setEntity(requestEntity);
//设置请求的配置数据
RequestConfig config = RequestConfig.custom()
.setConnectTimeout(180000)
.setSocketTimeout(180000)
.setConnectionRequestTimeout(120000).build();
httpPost.setConfig(config);
HttpResponse response = httpClient.execute(httpPost);
logger.info(inData+"PLM调用接口同步远程数据返回信息"+JSON.toJSONString(response));
//获取请求的状态码
InputStream is = null;
String tempStr = "";
StringBuilder resultBody = new StringBuilder();
int statusCode = response.getStatusLine().getStatusCode();
if(statusCode== HttpStatus.SC_OK){
responseData.setSuccess(true);
responseData.setCode(statusCode+"");
HttpEntity entity = response.getEntity();
//String result = StringEscapeUtils.unescapeHtml4(EntityUtils.toString(entity, Consts.UTF_8));
//responseData.setMsg(result);
//换方式读取内容 2022-05-24
if(entity != null) {
is = entity.getContent();
BufferedReader br = new BufferedReader(new InputStreamReader(is, "UTF-8"));
//循环读取
while((tempStr = br.readLine()) != null) {
resultBody.append(tempStr);
}
}
//读取内容转Map对象
Map<String, Object> resultMap = JSON.parseObject(resultBody.toString(), Map.class, Feature.InitStringFieldAsEmpty);
//获取代码
int code = (int) resultMap.get("code");
String strData = String.valueOf(resultMap.get("msg"));
responseData.setCode(code+"");
responseData.setMsg(strData);
responseData.setObj(strData);
}else{
responseData.setCode(statusCode+"");
responseData.setMsg("错误码:"+statusCode);
}
} catch (ParseException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return responseData;
}
}

2
src/main/java/com/spring/modules/part/mapper/PartInformationMapper.java

@ -19,8 +19,6 @@ import java.util.List;
public interface PartInformationMapper extends BaseMapper<PartInformationEntity> {
IPage<PartInformationVo> partInformationSearch(Page<PartInformationVo> partInformationVoPage, @Param("query") PartInformationVo data);
String getPartNo(PartInformationEntity data);
List<PartSubPropertiesValueHeaderData> checkValueHeaderData(PartSubPropertiesValueData data);
void deletePartSubPropertiesValueHeader(PartSubPropertiesValueData data);

100
src/main/java/com/spring/modules/part/service/impl/PartInformationServiceImpl.java

@ -10,6 +10,7 @@ import com.spring.common.utils.PageUtils;
import com.spring.modules.base.data.PartSubPropertiesValueData;
import com.spring.modules.base.data.PartSubPropertiesValueHeaderData;
import com.spring.modules.base.data.PlmPropertiesItemAvailableData;
import com.spring.modules.base.utils.HttpClientUtil;
import com.spring.modules.oss.dao.SysOssDao;
import com.spring.modules.oss.service.SysOssService;
import com.spring.modules.part.entity.AgentInformationEntity;
@ -21,18 +22,24 @@ import com.spring.modules.part.vo.PartInformationVo;
import com.spring.modules.project.data.PlmProjectPartData;
import com.spring.modules.quotation.entity.QuotationInformationEntity;
import com.spring.modules.quotation.vo.QuotationInformationVo;
import com.spring.modules.report.dao.ProcedureDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service
public class PartInformationServiceImpl extends ServiceImpl<PartInformationMapper, PartInformationEntity> implements PartInformationService {
@Autowired
private ProcedureDao procedureDao;
@Autowired
private PartInformationMapper partInformationMapper;
@ -66,11 +73,54 @@ public class PartInformationServiceImpl extends ServiceImpl<PartInformationMappe
* @return: void
**/
@Override
@Transactional
public void partInformationSave(PartInformationEntity data) {
// 获取材料编码
// String partNo = partInformationMapper.getPartNo(data);
// data.setPartNo("P" + partNo);
// 调用存储过程校验参数
Map<String, Object> resultMap = this.checkSavePart(data);
// 判断是否检验成功
String code = String.valueOf(resultMap.get("resultCode"));
if ("600".equalsIgnoreCase(code)) {
String msg = String.valueOf(resultMap.get("resultMsg"));
throw new XJException(msg, Integer.parseInt(code));
}
partInformationMapper.insert(data);
// 同步
//HttpClientUtil.doPostByRawWithPLM();
}
/**
* 物料新增校验参数
* @param inData
* @return
*/
public Map<String, Object> checkSavePart(PartInformationEntity inData){
// 公共参数
String site = inData.getSite();
String partNo = inData.getPartNo();
String codeNo = inData.getCodeNo();
String functionType = "B";
String umId = inData.getUmId();
String familyId = inData.getFamilyId();
String groupId = inData.getGroupId();
String productGroupId1 = inData.getProductGroupId1() == null ? "" : inData.getProductGroupId1();
String productGroupId2 = inData.getProductGroupId2() == null ? "" : inData.getProductGroupId2();
String productGroupId3 = inData.getProductGroupId3();
String productGroupId4 = inData.getProductGroupId4();
List<Object> params = new ArrayList<>();
params.add(site);
params.add(partNo);
params.add(codeNo);
params.add(functionType);
params.add(umId);
params.add(familyId);
params.add(groupId);
params.add(productGroupId1);
params.add(productGroupId2);
params.add(productGroupId3);
params.add(productGroupId4);
// 执行方法
List<Map<String, Object>> resultList = procedureDao.getProcedureData("checkSavePart", params);
return resultList.get(0);
}
/**
@ -81,7 +131,16 @@ public class PartInformationServiceImpl extends ServiceImpl<PartInformationMappe
* @return: void
**/
@Override
@Transactional
public void partInformationEdit(PartInformationEntity data) {
// 调用存储过程校验参数
Map<String, Object> resultMap = this.checkUpdatePart(data);
// 判断是否检验成功
String code = String.valueOf(resultMap.get("resultCode"));
if ("600".equalsIgnoreCase(code)) {
String msg = String.valueOf(resultMap.get("resultMsg"));
throw new XJException(msg, Integer.parseInt(code));
}
// 编辑材料信息
UpdateWrapper<PartInformationEntity> updateInformationWrapper = new UpdateWrapper<>();
updateInformationWrapper.eq("site", data.getSite());
@ -89,6 +148,41 @@ public class PartInformationServiceImpl extends ServiceImpl<PartInformationMappe
partInformationMapper.update(data, updateInformationWrapper);
}
/**
* 物料编辑校验参数
* @param inData
* @return
*/
public Map<String, Object> checkUpdatePart(PartInformationEntity inData){
// 公共参数
String site = inData.getSite();
String partNo = inData.getPartNo();
String codeNo = inData.getCodeNo();
String functionType = "B";
String umId = inData.getUmId();
String familyId = inData.getFamilyId();
String groupId = inData.getGroupId();
String productGroupId1 = inData.getProductGroupId1() == null ? "" : inData.getProductGroupId1();
String productGroupId2 = inData.getProductGroupId2() == null ? "" : inData.getProductGroupId2();
String productGroupId3 = inData.getProductGroupId3();
String productGroupId4 = inData.getProductGroupId4();
List<Object> params = new ArrayList<>();
params.add(site);
params.add(partNo);
params.add(codeNo);
params.add(functionType);
params.add(umId);
params.add(familyId);
params.add(groupId);
params.add(productGroupId1);
params.add(productGroupId2);
params.add(productGroupId3);
params.add(productGroupId4);
// 执行方法
List<Map<String, Object>> resultList = procedureDao.getProcedureData("checkUpdatePart", params);
return resultList.get(0);
}
/**
* @description: 材料信息删除
* @author: fengyuan_yang

8
src/main/resources/mapper/part/PartInformationMapper.xml

@ -61,14 +61,6 @@
</where>
</select>
<!-- 获取材料编码 -->
<select id="getPartNo" resultType="string" parameterType="PartInformationEntity">
SELECT
Right('0000000000' + convert(VARCHAR(10), isnull(max(convert(INT, SUBSTRING(part_no, 3, 10))), 0) + 1), 8)
FROM part
WHERE site = #{site}
</select>
<!-- 检查材料属性 -->
<select id="checkValueHeaderData" resultType="PartSubPropertiesValueHeaderData">
SELECT

Loading…
Cancel
Save