Commit 170a8d1e authored by shyWang's avatar shyWang

Merge remote-tracking branch 'origin/master'

# Conflicts:
#	src/com/yonde/common/PartUtil.java
#	src/com/yonde/part/service/DxPartService.java
parents a6e42507 387d63d7
......@@ -14,17 +14,21 @@ import wt.inf.container.WTContainerRef;
import wt.log4j.LogR;
import wt.method.RemoteAccess;
import wt.method.RemoteMethodServer;
import wt.org.WTUser;
import wt.part.*;
import wt.pds.StatementSpec;
import wt.query.ArrayExpression;
import wt.query.ClassAttribute;
import wt.query.QuerySpec;
import wt.query.SearchCondition;
import wt.session.SessionHelper;
import wt.session.SessionServerHelper;
import wt.type.TypedUtility;
import wt.util.WTException;
import wt.vc.VersionControlHelper;
import wt.vc.config.ConfigSpec;
import wt.vc.config.IteratedOrderByPrimitive;
import wt.vc.config.LatestConfigSpec;
import wt.vc.config.VersionedOrderByPrimitive;
import wt.vc.views.View;
import wt.vc.views.ViewHelper;
......@@ -33,9 +37,7 @@ import wt.vc.views.ViewReference;
import java.lang.reflect.InvocationTargetException;
import java.rmi.RemoteException;
import java.text.DecimalFormat;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.List;
import java.util.*;
public class PartUtil implements RemoteAccess {
private static Logger logger = LogR.getLogger(PartUtil.class.getName());
......@@ -409,4 +411,138 @@ public class PartUtil implements RemoteAccess {
}
return latestPart;
}
/**
* @描述 获得所有的子件,不包括根节点
* @作者 Pengfei,Li
* @时间 2015-9-11上午11:13:19
*/
public static void getAllChildByView(WTPart parent, ConfigSpec configSpec, List<WTPart> childSet) throws Exception {
List<WTPart> childs = getChildByView(parent, configSpec);
childSet.addAll(childs);
for (WTPart wtPart : childs) {
getAllChildByView(wtPart, configSpec, childSet);
}
}
/**
* @描述 获取指定视图的子件,若子件无该视图则返回上游Design视图
* @作者 Pengfei,Li
* @时间 2015-9-11上午10:47:16
*/
@SuppressWarnings("unchecked")
public static List<WTPart> getChildByView(WTPart parent, String viewStr) throws WTException {
List<WTPart> childs = new ArrayList<WTPart>();
if (!RemoteMethodServer.ServerFlag) {
try {
childs = (List<WTPart>) RemoteMethodServer.getDefault().invoke("getChildByView", PartUtil.class.getName(), null,
new Class[] { WTPart.class, String.class }, new Object[] { parent, viewStr });
} catch (Exception e) {
throw new WTException(e);
}
} else {
SessionServerHelper.manager.setAccessEnforced(false);
try {
WTPartConfigSpec partConfigSpec = WTPartConfigSpec
.newWTPartConfigSpec(WTPartStandardConfigSpec.newWTPartStandardConfigSpec(ViewHelper.service.getView(viewStr), null));
for (QueryResult subNodes = WTPartHelper.service.getUsesWTParts(parent, partConfigSpec); subNodes.hasMoreElements();) {
wt.fc.Persistable aSubNodePair[] = (wt.fc.Persistable[]) subNodes.nextElement();
if (aSubNodePair[1] instanceof WTPart) {
WTPart tempPart = (WTPart) aSubNodePair[1];
if (tempPart != null) {
childs.add(tempPart);
}
} else if (aSubNodePair[1] instanceof WTPartMaster) {
String partNo = ((WTPartMaster) aSubNodePair[1]).getNumber();
WTPart tempPart = null;
try {
tempPart = getLatestViewPart(partNo, viewStr);
if (tempPart == null) {
tempPart = getLatestViewPart(partNo, "Design");
}
if (tempPart != null) {
childs.add(tempPart);
}
} catch (Exception e) {
throw new WTException(e);
}
}
}
} finally {
SessionServerHelper.manager.setAccessEnforced(true);
}
}
return childs;
}
/**
* @描述 获取指定视图的最新版
*/
public static WTPart getLatestViewPart(String number, String viewName) throws WTException {
try {
if (!RemoteMethodServer.ServerFlag) {
return (WTPart) RemoteMethodServer.getDefault().invoke("getLatestViewPart", PartUtil.class.getName(), null,
new Class[] { String.class, String.class }, new Object[] { number, viewName });
} else {
WTPart part = null;
if (!StringUtils.isEmpty(number) && !StringUtils.isEmpty(viewName)) {
QuerySpec qs = new QuerySpec(WTPart.class);
qs.setAdvancedQueryEnabled(true);
qs.appendWhere(new SearchCondition(WTPart.class, WTPart.LATEST_ITERATION, SearchCondition.IS_TRUE), new int[] { 0 });
number = number == null ? null : number.toUpperCase();
qs.appendAnd();
qs.appendWhere(new SearchCondition(WTPart.class, WTPart.NUMBER, SearchCondition.EQUAL, number), new int[] { 0 });
View view = ViewHelper.service.getView(viewName);
qs.appendAnd();
qs.appendWhere(new SearchCondition(WTPart.class, WTPart.VIEW + "." + ObjectReference.KEY, SearchCondition.EQUAL,
PersistenceHelper.getObjectIdentifier(view)), new int[] { 0 });
QueryResult queryResult = PersistenceHelper.manager.find((StatementSpec) qs);
queryResult = new LatestConfigSpec().process(queryResult);
if (queryResult.hasMoreElements()) {
part = (WTPart) queryResult.nextElement();
}
}
return part;
}
} catch (RemoteException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
return null;
}
/**
* @描述 返回指定配置的子件
*/
@SuppressWarnings("unchecked")
public static List<WTPart> getChildByView(WTPart parent, ConfigSpec configSpec) throws Exception {
List<WTPart> childs = new ArrayList<WTPart>();
if (!RemoteMethodServer.ServerFlag) {
childs = (List<WTPart>) RemoteMethodServer.getDefault().invoke("getChildByView", PartUtil.class.getName(), null,
new Class[] { WTPart.class, WTPartConfigSpec.class }, new Object[] { parent, configSpec });
} else {
WTUser currentUser = (WTUser) SessionHelper.manager.getPrincipal();
try {
SessionHelper.manager.setAdministrator();
for (QueryResult subNodes = WTPartHelper.service.getUsesWTParts(parent, configSpec); subNodes.hasMoreElements();) {
//for (QueryResult subNodes = StructHelper.service.navigateUsesToIteration(parent, false, configSpec); subNodes.hasMoreElements();) {
Object result = subNodes.nextElement();
if (!(result instanceof Persistable[]))
continue;
wt.fc.Persistable aSubNodePair[] = (wt.fc.Persistable[]) result;
if (aSubNodePair[1] instanceof WTPart) {
WTPartUsageLink link = (WTPartUsageLink) aSubNodePair[0];
WTPart tempPart = (WTPart) aSubNodePair[1];
if (tempPart != null) {
childs.add(tempPart);
}
}
}
} catch (Exception e) {
throw new WTException(e);
} finally {
SessionHelper.manager.setPrincipal(currentUser.getName());
}
}
return childs;
}
}
......@@ -92,6 +92,17 @@ public class DxPartController extends AbstractBaseController {
return dxPartVO;
}
@PostMapping({"/version/{id}/convertView"})
//@ApiOperation("转视图")
public ApiResult convertView(@PathVariable Long id) {
try {
DxPartService.convertViewAll(id);
} catch (Exception e) {
e.printStackTrace();
}
return ApiResult.ok("转视图成功");
}
//@ApiOperation("配置规范查询")
@PostMapping({"findBySpecPage"})
......
......@@ -22,6 +22,7 @@ import wt.session.SessionContext;
import wt.session.SessionHelper;
import wt.util.WTException;
import wt.vc.VersionControlHelper;
import wt.vc.views.ViewHelper;
import wt.vc.config.LatestConfigSpec;
import wt.vc.wip.WorkInProgressHelper;
......@@ -510,5 +511,78 @@ public class DxPartService implements RemoteAccess, Serializable {
}
return resultList;
}
/**
* 转视图
* @param id
* @return
* @throws Exception
*/
public static DxPartVO convertView(Long id) throws Exception {
if (!RemoteMethodServer.ServerFlag) {
return (DxPartVO) RemoteMethodServer.getDefault().invoke("convertView", DxPartService.class.getName(), null,
new Class[] { Long.class},
new Object[] { id});
}
WTPart partById = DxPartUtil.getPartById(id);
String viewName = partById.getViewName();
if(!viewName.equalsIgnoreCase("Planning")){
WTPart tmpPart = (WTPart) ViewHelper.service.newBranchForView(partById, "Planning");
tmpPart.setContainer(partById.getContainer());
CommonUtil.setFolder("/Default/PBOM/PBOM零部件", partById.getContainerReference(), tmpPart);
tmpPart = (WTPart) PersistenceHelper.manager.save(tmpPart);
return new DxPartVO(tmpPart);
}else{
return new DxPartVO(partById);
}
}
/**
* 批量转视图
* @param id
* @return
* @throws Exception
*/
public static void convertViewAll(Long id) throws Exception {
if (!RemoteMethodServer.ServerFlag) {
RemoteMethodServer.getDefault().invoke("convertViewAll", DxPartService.class.getName(), null,
new Class[] { Long.class},
new Object[] { id});
}
WTPart partById = DxPartUtil.getPartById(id);
String viewName = partById.getViewName();
if(!viewName.equalsIgnoreCase("Planning")){
WTPart ppart = PartUtil.getLatestViewPart(partById.getNumber(),"Planning");
ArrayList<WTPart> list = new ArrayList<WTPart>();
if(ppart==null){
WTPartConfigSpec partConfigSpec = WTPartConfigSpec
.newWTPartConfigSpec(WTPartStandardConfigSpec.newWTPartStandardConfigSpec(ViewHelper.service.getView("Design"), null));
PartUtil.getAllChildByView(partById,partConfigSpec,list);
ppart = (WTPart) ViewHelper.service.newBranchForView(partById, "Planning");
ppart.setContainer(partById.getContainer());
CommonUtil.setFolder("/Default/PBOM/PBOM零部件", partById.getContainerReference(), ppart);
PersistenceHelper.manager.save(ppart);
}
for(WTPart tempPart : list){
tempPart = (WTPart) ViewHelper.service.newBranchForView(partById, "Planning");
tempPart.setContainer(partById.getContainer());
CommonUtil.setFolder("/Default/PBOM/PBOM零部件", partById.getContainerReference(), tempPart);
PersistenceHelper.manager.save(tempPart);
}
}else{
throw new Exception("无需转视图");
}
}
}
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