Commit b9cc5ffb authored by 杜科's avatar 杜科

update

parent fc3b9416
package com.yonde.common;
import wt.fc.PersistenceHelper;
import wt.fc.QueryResult;
import wt.method.RemoteAccess;
import wt.method.RemoteMethodServer;
import wt.part.WTPart;
import wt.query.QuerySpec;
import wt.query.SearchCondition;
import wt.session.SessionServerHelper;
import wt.util.WTException;
import wt.vc.views.View;
import wt.vc.views.ViewHelper;
import wt.vc.views.ViewReference;
import java.lang.reflect.InvocationTargetException;
import java.rmi.RemoteException;
public class DemoUtil implements RemoteAccess {
public static WTPart getPartByNumberAndView(String number, String viewStr, boolean accessControlled) throws WTException {
WTPart part = null;
try {
number = number.toUpperCase();
if (!RemoteMethodServer.ServerFlag) {
return (WTPart) RemoteMethodServer.getDefault().invoke("getPartByNumberAndView", DemoUtil.class.getName(),
null, new Class[]{String.class, String.class, boolean.class}, new Object[]{number, viewStr, accessControlled});
} else {
boolean enforce = SessionServerHelper.manager.setAccessEnforced(accessControlled);
try {
QuerySpec querySpec = new QuerySpec(WTPart.class);
SearchCondition searchCondition = new SearchCondition(WTPart.class, WTPart.NUMBER, SearchCondition.LIKE, number.toUpperCase(), false);
querySpec.appendWhere(searchCondition, new int[]{0});
querySpec.appendAnd();
querySpec.appendWhere(new SearchCondition(WTPart.class, WTPart.LATEST_ITERATION, SearchCondition.IS_TRUE), new int[]{0});
querySpec.appendAnd();
querySpec.appendOpenParen();
View view = ViewHelper.service.getView(viewStr);
querySpec.appendWhere(new SearchCondition(WTPart.class, WTPart.VIEW + "."
+ ViewReference.KEY, SearchCondition.EQUAL, PersistenceHelper
.getObjectIdentifier(view)), new int[]{0});
querySpec.appendOr();
querySpec.appendWhere(new SearchCondition(WTPart.class, WTPart.VIEW, true), new int[]{0});
querySpec.appendCloseParen();
QueryResult queryResult = PersistenceHelper.manager.find(querySpec);
if (queryResult.hasMoreElements()) {
part = (WTPart) queryResult.nextElement();
}
if(part!=null){
System.out.println("--------Part info-----");
System.out.println("----partNumber-----"+part.getNumber());
System.out.println("----creatorName-----"+part.getCreatorName());
System.out.println("----------------------");
}
} finally {
SessionServerHelper.manager.setAccessEnforced(enforce);
}
}
} catch (RemoteException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
return part;
}
}
package com.yonde.part.controller;
import com.yonde.part.service.impl.DemoService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping(value = "/demo")
public class DemoController {
@GetMapping(value = "/part")
public void getPartByNumber(@RequestParam String number,@RequestParam String view) throws Exception {
DemoService.getPartByNumber(number,view);
}
}
package com.yonde.part.service.impl;
import com.yonde.common.DemoUtil;
import com.yonde.common.PartUtil;
import org.springframework.stereotype.Service;
import wt.method.RemoteAccess;
import wt.method.RemoteMethodServer;
import wt.part.WTPart;
import wt.util.WTException;
import java.lang.reflect.InvocationTargetException;
import java.rmi.RemoteException;
@Service
public class DemoService {
public static void getPartByNumber(String number,String view) throws InvocationTargetException, RemoteException, WTException {
boolean accessControlled = false;
WTPart part = DemoUtil.getPartByNumberAndView(number,view,accessControlled);
System.out.println("--------2Part info2-----");
System.out.println("----partNumber2-----"+part.getNumber());
System.out.println("----creatorName2-----"+part.getCreatorName());
System.out.println("-----------2-----------");
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment