@ -31,6 +31,7 @@ import com.op.system.api.domain.quality.*;
import com.op.system.api.domain.sap.SapCloseOrderQuery ;
import com.op.system.api.domain.sap.SapRFW ;
import org.apache.commons.lang.StringUtils ;
import org.apache.http.HttpResponse ;
import org.slf4j.Logger ;
import org.slf4j.LoggerFactory ;
import org.springframework.beans.factory.annotation.Autowired ;
@ -41,8 +42,15 @@ import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes ;
import javax.servlet.http.HttpServletRequest ;
import java.io.BufferedReader ;
import java.io.IOException ;
import java.io.InputStreamReader ;
import java.io.OutputStream ;
import java.math.BigDecimal ;
import java.net.HttpURLConnection ;
import java.net.URL ;
import java.net.URLEncoder ;
import java.nio.charset.StandardCharsets ;
import java.time.LocalDate ;
import java.time.format.DateTimeFormatter ;
import java.time.temporal.ChronoUnit ;
@ -64,45 +72,50 @@ public class OpenServiceImpl implements OpenService {
@Value ( "${OA.url}" )
private String oa_url ;
@Value ( "${OA.getnodeInfo}" )
private String getnodeInfo ;
@Autowired
private OpenMapper openMapper ;
// @Autowired
// private RemoteSapService remoteSapService;
/ * * 下 一 工 序 机 台 集 合 获 取
/ * *
* 下 一 工 序 机 台 集 合 获 取
* JSON
* {
* "reqCode" : "eb7f8e9f-d1e8-499e-9bcb-e72d3ac195b0" , //请求ID
* "reqTime" : "2023-06-30 21:24:04" , //请求时间,
* "rfidNo" : "r12345" //rfid编号
* "factory"
* "reqCode" : "eb7f8e9f-d1e8-499e-9bcb-e72d3ac195b0" , //请求ID
* "reqTime" : "2023-06-30 21:24:04" , //请求时间,
* "rfidNo" : "r12345" //rfid编号
* "factory"
* }
*
* < p >
* JSON
* {
* "reqCode" : "eb7f8e9f-d1e8-499e-9bcb-e72d3ac195b0" , //请求ID
* "code" : 0 , //返回代码
* "message" : "OK" , //返回信息
* "stationType" : "2" , //目的机台类型 2烘房 3收坯机
* "sku" : "sku01" , //物料编码
* "spec" : "150" , //规格
* "productionState" : "K01" , //当前工艺状态
* "stationNos" : [
* {
* "stationNo" : "F1" , //目的站台编号
* "qty" : 2 //针对于烘房前面的当前筛盘车的数量, 如果数量大于2就不会往改烘房分配
* } ,
* {
* "stationNo" : "F3" , //目的站台编号
* "qty" : 2 //针对于烘房前面的当前筛盘车的数量, 如果数量大于2就不会往改烘房分配
* } ,
* {
* "stationNo" : "F3" , //目的站台编号
* "qty" : 2 //针对于烘房前面的当前筛盘车的数量, 如果数量大于2就不会往改烘房分配
* }
* ] ,
* "reqCode" : "eb7f8e9f-d1e8-499e-9bcb-e72d3ac195b0" , //请求ID
* "code" : 0 , //返回代码
* "message" : "OK" , //返回信息
* "stationType" : "2" , //目的机台类型 2烘房 3收坯机
* "sku" : "sku01" , //物料编码
* "spec" : "150" , //规格
* "productionState" : "K01" , //当前工艺状态
* "stationNos" : [
* {
* "stationNo" : "F1" , //目的站台编号
* "qty" : 2 //针对于烘房前面的当前筛盘车的数量, 如果数量大于2就不会往改烘房分配
* } ,
* {
* "stationNo" : "F3" , //目的站台编号
* "qty" : 2 //针对于烘房前面的当前筛盘车的数量, 如果数量大于2就不会往改烘房分配
* } ,
* {
* "stationNo" : "F3" , //目的站台编号
* "qty" : 2 //针对于烘房前面的当前筛盘车的数量, 如果数量大于2就不会往改烘房分配
* }
* ] ,
* }
*
* @param wcsdto
* @return
* /
@ -148,7 +161,7 @@ public class OpenServiceImpl implements OpenService {
if ( StringUtils . isNotBlank ( machineCode ) ) {
//设备是否正常
String status = openMapper . getEquipStatus ( machineCode ) ;
if ( StringUtils . isNotBlank ( status ) & & "1" . equals ( status ) ) { //正常设备且没被删除
if ( StringUtils . isNotBlank ( status ) & & "1" . equals ( status ) ) { //正常设备且没被删除
wCSDataDTO . setStationNo ( machineCode ) ;
if ( "2" . equals ( stationType ) ) {
Integer qty = openMapper . getEquipNum ( machineCode ) ;
@ -162,11 +175,11 @@ public class OpenServiceImpl implements OpenService {
}
dto . setStationNos ( stationNos ) ;
dto . setCode ( "0" ) ;
} else {
} else {
dto . setCode ( "1" ) ;
dto . setMessage ( "MES管理系统接口调用异常:数据缺失" ) ;
}
} catch ( Exception e ) {
} catch ( Exception e ) {
dto . setCode ( "1" ) ;
dto . setMessage ( "MES管理系统接口调用失败" ) ;
}
@ -256,20 +269,20 @@ public class OpenServiceImpl implements OpenService {
@Override
public List < WCSDTO > getLGInfo ( WCSDTO wcsDTO ) {
DynamicDataSourceContextHolder . push ( "ds_" + wcsDTO . getFactory ( ) ) ; // 这是数据源的key
DynamicDataSourceContextHolder . push ( "ds_" + wcsDTO . getFactory ( ) ) ; // 这是数据源的key
return openMapper . getLGInfo ( wcsDTO ) ;
}
@Override
public AjaxResult machineRepair ( EquRepairOrderDTO equRepairOrderDTO ) {
DynamicDataSourceContextHolder . push ( "ds_" + equRepairOrderDTO . getFactory ( ) ) ; // 这是数据源的key
DynamicDataSourceContextHolder . push ( "ds_" + equRepairOrderDTO . getFactory ( ) ) ; // 这是数据源的key
// 创建报修单
DeviceRepairOrder equRepairOrder = new DeviceRepairOrder ( ) ;
// 获取故障报修流水号
String serialNum = String . format ( "%03d" , openMapper . selectOrderCodeSerialNumber ( ) ) ;
equRepairOrder . setOrderCode ( "BX" + DateUtils . dateTimeNow ( DateUtils . YYYYMMDD ) + equRepairOrderDTO . getEquipmentCode ( ) + serialNum ) ; // 报修单号
equRepairOrder . setOrderCode ( "BX" + DateUtils . dateTimeNow ( DateUtils . YYYYMMDD ) + equRepairOrderDTO . getEquipmentCode ( ) + serialNum ) ; // 报修单号
equRepairOrder . setOrderId ( IdUtils . fastSimpleUUID ( ) ) ; // id
equRepairOrder . setEquipmentCode ( equRepairOrderDTO . getEquipmentCode ( ) ) ;
equRepairOrder . setOrderSource ( "上位机" ) ; // 故障来源
@ -290,7 +303,7 @@ public class OpenServiceImpl implements OpenService {
@Override
public int insertQcCheckTaskProduce ( QcCheckTaskProduceDTO qcCheckTaskProduce ) {
DynamicDataSourceContextHolder . push ( "ds_" + qcCheckTaskProduce . getFactoryCode ( ) ) ;
DynamicDataSourceContextHolder . push ( "ds_" + qcCheckTaskProduce . getFactoryCode ( ) ) ;
qcCheckTaskProduce . setCreateTime ( DateUtils . getNowDate ( ) ) ;
@ -299,20 +312,20 @@ public class OpenServiceImpl implements OpenService {
String liushuiStr = String . format ( "%04d" , liushuiNum ) ;
String createBy = SecurityUtils . getUsername ( ) ;
Date nowDate = DateUtils . getNowDate ( ) ;
Date nowDate = DateUtils . getNowDate ( ) ;
//获取当前所选工厂
String factoryCode = qcCheckTaskProduce . getFactoryCode ( ) ;
String beLongId = IdUtils . fastSimpleUUID ( ) ;
qcCheckTaskProduce . setCheckNo ( bpDD + liushuiStr ) ;
qcCheckTaskProduce . setCheckNo ( bpDD + liushuiStr ) ;
/**取检测项**/
QcCheckTypeProjectDTO qctp = new QcCheckTypeProjectDTO ( ) ;
QcCheckTypeProjectDTO qctp = new QcCheckTypeProjectDTO ( ) ;
qctp . setTypeId ( qcCheckTaskProduce . getCheckType ( ) ) ; //生产过程检验
qctp . setMaterialCode ( qcCheckTaskProduce . getMaterialCode ( ) ) ; //特性
/**qc_user_material取默认检查人**/
List < QcUserMaterialDTO > users = openMapper . getUserByMaterial ( qcCheckTaskProduce . getMaterialCode ( ) ) ;
if ( CollectionUtils . isEmpty ( users ) ) {
if ( CollectionUtils . isEmpty ( users ) ) {
QcUserMaterialDTO dto0 = new QcUserMaterialDTO ( ) ;
dto0 . setId ( IdUtils . fastSimpleUUID ( ) ) ;
dto0 . setBelongTo ( beLongId ) ;
@ -323,8 +336,8 @@ public class OpenServiceImpl implements OpenService {
dto0 . setUserCode ( "mobile" ) ;
dto0 . setUserName ( "手持测试用户" ) ;
users . add ( dto0 ) ;
} else {
for ( QcUserMaterialDTO user : users ) {
} else {
for ( QcUserMaterialDTO user : users ) {
user . setId ( IdUtils . fastSimpleUUID ( ) ) ;
user . setBelongTo ( beLongId ) ;
user . setCheckNo ( qcCheckTaskProduce . getCheckNo ( ) ) ;
@ -333,15 +346,15 @@ public class OpenServiceImpl implements OpenService {
user . setCreateTime ( nowDate ) ;
}
}
int m = openMapper . addCheckUsers ( users ) ;
logger . info ( "检查人新增" + m + "成功" ) ;
int m = openMapper . addCheckUsers ( users ) ;
logger . info ( "检查人新增" + m + "成功" ) ;
/**qc_check_type_project**/
List < QcCheckTaskDetailDTO > items = openMapper . getTPByTypeMaterial ( qctp ) ;
if ( CollectionUtils . isEmpty ( items ) ) {
if ( CollectionUtils . isEmpty ( items ) ) {
/**qc_material_group_detail**/
QcMaterialGroupDetailDTO group = openMapper . getGroupByMaterial ( qcCheckTaskProduce . getMaterialCode ( ) ) ;
if ( group = = null ) {
if ( group = = null ) {
return 0 ; //没有找到检测项目
}
qctp . setGroupId ( group . getGroupId ( ) ) ; //共性
@ -349,7 +362,7 @@ public class OpenServiceImpl implements OpenService {
}
/**qc_check_task_detail**/
if ( CollectionUtils . isEmpty ( items ) ) {
if ( CollectionUtils . isEmpty ( items ) ) {
return 0 ; //没有找到检测项目
}
@ -364,7 +377,7 @@ public class OpenServiceImpl implements OpenService {
qcCheckTaskProduce . setSupplierName ( qcCheckTaskProduce . getCarName ( ) ) ;
openMapper . insertQcCheckTaskProduce ( qcCheckTaskProduce ) ;
/**qc_check_task_detail**/
for ( QcCheckTaskDetailDTO item : items ) {
for ( QcCheckTaskDetailDTO item : items ) {
item . setRecordId ( IdUtils . fastSimpleUUID ( ) ) ;
item . setBelongTo ( beLongId ) ;
item . setCreateTime ( nowDate ) ;
@ -377,10 +390,26 @@ public class OpenServiceImpl implements OpenService {
@Override
public AjaxResult OAInspection ( Map < String , Object > paramMap ) {
try {
String result = HttpUtils . sendPostOA ( oa_url , convertJsonToUrlParams ( JSONObject . toJSONString ( paramMap ) ) ) ;
// 从paramMap中提取需要的参数
String user = paramMap . get ( "user" ) . toString ( ) ;
String requestLevel = paramMap . get ( "requestLevel" ) . toString ( ) ;
String requestName = paramMap . get ( "requestName" ) . toString ( ) ;
String workflowId = paramMap . get ( "workflowId" ) . toString ( ) ;
String mainObject = paramMap . get ( "mainObject" ) . toString ( ) ;
// Building the postData string using StringBuilder
StringBuilder postDataBuilder = new StringBuilder ( ) ;
postDataBuilder . append ( "user=" ) . append ( user )
. append ( "&requestLevel=" ) . append ( requestLevel )
. append ( "&requestName=" ) . append ( URLEncoder . encode ( requestName , StandardCharsets . UTF_8 . toString ( ) ) )
. append ( "&workflowId=" ) . append ( workflowId )
. append ( "&mainObject=" ) . append ( URLEncoder . encode ( mainObject , StandardCharsets . UTF_8 . toString ( ) ) ) ;
if ( Constants . WORKFLOWID_ZL0020 . equals ( workflowId ) ) {
postDataBuilder . append ( "&details=" ) . append ( URLEncoder . encode ( mainObject , StandardCharsets . UTF_8 . toString ( ) ) ) ;
}
String postData = postDataBuilder . toString ( ) ;
String result = HttpUtils . sendPostOA ( oa_url , postData ) ;
System . out . println ( result ) ;
//返回示例{"result":"0","info":"成功","requestid":"2193799"}
Map resultMap = JSONObject . parseObject ( result ) ;
@ -389,62 +418,25 @@ public class OpenServiceImpl implements OpenService {
} else {
return error ( resultMap . get ( "info" ) . toString ( ) ) ;
}
} catch ( Exception e ) {
e . printStackTrace ( ) ;
return error ( e . getMessage ( ) ) ;
}
}
}
@Override
public AjaxResult OAProcessInspection ( Map < String , Object > paramMap ) {
try {
String result = HttpUtils . sendPostOA ( oa_url , convertJsonToUrlParams ( JSONObject . toJSONString ( paramMap ) ) ) ;
System . out . println ( result ) ;
//返回示例{"result":"0","info":"成功","requestid":"2193799"}
Map resultMap = JSONObject . parseObject ( result ) ;
if ( resultMap . get ( "result" ) . equals ( Constants . LOGIN_SUCCESS_STATUS ) ) {
return success ( resultMap . get ( "info" ) . toString ( ) , resultMap . get ( "requestid" ) . toString ( ) ) ;
} else {
return error ( resultMap . get ( "info" ) . toString ( ) ) ;
}
public AjaxResult GetOaNodeInfo ( String requestId ) {
try {
String result = HttpUtils . sendGet ( getnodeInfo , "requestId=" + requestId ) ;
return success ( result ) ;
} catch ( Exception e ) {
e . printStackTrace ( ) ;
return error ( e . getMessage ( ) ) ;
}
}
public static String convertJsonToUrlParams ( String json ) throws IOException {
ObjectMapper objectMapper = new ObjectMapper ( ) ;
JsonNode jsonNode = objectMapper . readTree ( json ) ;
StringBuilder urlParams = new StringBuilder ( ) ;
Iterator < String > fieldNames = jsonNode . fieldNames ( ) ;
while ( fieldNames . hasNext ( ) ) {
String fieldName = fieldNames . next ( ) ;
JsonNode fieldValue = jsonNode . get ( fieldName ) ;
if ( urlParams . length ( ) > 0 ) {
urlParams . append ( "&" ) ;
}
urlParams . append ( fieldName ) . append ( "=" ) . append ( fieldValue ) ;
}
return urlParams . toString ( ) ;
}
public static void main ( String args [ ] ) {
Map < String , Object > paramMap = new HashMap < > ( ) ;
paramMap . put ( "A" , "B" ) ;
paramMap . put ( "C" , "D" ) ;
paramMap . put ( "E" , "F" ) ;
System . out . println ( JSONObject . toJSONString ( paramMap ) ) ;
// DateTimeFormatter ymdhms = DateTimeFormatter.ofPattern("yyyy-MM-dd");
// LocalDate today = LocalDate.now();
// LocalDate lastMonth3 = today.plus(-3, ChronoUnit.MONTHS);
//
// System.out.println("7天之前的日期为:"+lastMonth3.getYear());
}
}