Commit 83f34268 authored by hanson.yao's avatar hanson.yao

convert wtPart

parent 710712f8
This diff is collapsed.
package com.yonde.part.controller;
import com.yonde.part.service.PartService;
import org.springframework.beans.factory.annotation.Autowired;
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 = "/part")
public class DxPartController {
@Autowired
PartService partService;
@GetMapping(value = "/search")
public Object getPartByNumber(@RequestParam String number) throws Exception {
return partService.getPartByNumber(number);
}
}
package com.yonde.part.controller;
public class PartController {
}
package com.yonde.part.convert;
import wt.fc.Persistable;
import wt.util.WTException;
/**
* Created on 2022/12/14
*
* @author
*/
public interface ConvertStrategy {
Object convert(Persistable persistable) throws WTException;
}
package com.yonde.part.convert;
import org.apache.log4j.Logger;
import wt.fc.Persistable;
import wt.log4j.LogR;
/**
* Created on 2022/12/14
*
* @author
*/
public class DxConvertFactory {
private static Logger logger = LogR.getLogger(DxConvertFactory.class.getName());
public static Object convertFactory(DxTypeEnum dxTypeEnum, Persistable persistable) throws Exception {
ConvertStrategy strategy = (ConvertStrategy) Class.forName(dxTypeEnum.getClassName()).newInstance();
return strategy.convert(persistable);
}
}
package com.yonde.part.convert;
import wt.fc.Persistable;
/**
* Created on 2022/12/15
*
* @author
*/
public class DxDocumentConvert implements ConvertStrategy {
@Override
public Object convert(Persistable persistable) {
System.out.println("DxDocumentConvert start ....");
return null;
}
}
package com.yonde.part.convert;
import com.ptc.core.meta.common.TypeIdentifier;
import com.yonde.common.PartUtil;
import com.yonde.part.vo.DxPart;
import wt.fc.ObjectReference;
import wt.fc.Persistable;
import wt.fc.ReferenceFactory;
import wt.part.WTPart;
import wt.util.WTException;
import java.util.Locale;
/**
* Created on 2022/12/14
*
* @author
*/
public class DxPartConvert implements ConvertStrategy {
@Override
public Object convert(Persistable persistable) throws WTException {
System.out.println("DxPartConvert start ....");
DxPart dxPart = null;
if (persistable instanceof WTPart) {
dxPart = new DxPart();
WTPart wtPart = (WTPart) persistable;
dxPart.setAuthKeys("");
dxPart.setId(PartUtil.getWTObjectOid(wtPart));
TypeIdentifier typeIdentifier = PartUtil.getWTObjectSubType(wtPart);
dxPart.setSubTypeName(typeIdentifier.getTypename());
dxPart.setOperator("");
dxPart.setDefaultUnit(wtPart.getDefaultUnit().getDisplay(Locale.CHINESE));
dxPart.setName(wtPart.getName());
dxPart.setNumber(wtPart.getNumber());
dxPart.setMasterId(new ReferenceFactory().getReferenceString(ObjectReference.newObjectReference((wtPart.getMaster().getPersistInfo().getObjectIdentifier()))));
//dxPart.setSubTypeDisplayName(wtPart.getDisplayIdentity().getDisplayType().getLocalizedMessage(Locale.CHINESE));
dxPart.setState(wtPart.getState().getState().getDisplay(Locale.CHINA));
//WTUser create = (WTUser)(wtPart.getCreator().getObject());
//String creator = String.format("%s(%s)", create.getFullName(), create.getName());
//WTUser modify = (WTUser)(wtPart.getModifier().getObject());
//String modifier = String.format("%s(%s)", modify.getFullName(), modify.getName());
//dxPart.setCreator(creator);
//dxPart.setModifier(modifier);
}
return dxPart;
}
}
package com.yonde.part.convert;
/**
* Created on 2022/12/14
*
* @author
*/
public enum DxTypeEnum {
WTDOCUMENT("com.yonde.part.convert.DxDocConvert"),
WTPART("com.yonde.part.convert.DxPartConvert");
DxTypeEnum(String className) {
this.setClassName(className);
}
private String className;
public String getClassName() {
return className;
}
public void setClassName(String className) {
this.className = className;
}
}
package com.yonde.part.service;
public class PartService {
public interface PartService {
Object getPartByNumber(String number) throws Exception;
}
package com.yonde.part.service.impl;
import com.yonde.common.PartUtil;
import com.yonde.part.convert.DxConvertFactory;
import com.yonde.part.convert.DxTypeEnum;
import com.yonde.part.service.PartService;
import org.springframework.stereotype.Service;
/**
* Created on 2022/12/15
*
* @author
*/
@Service
public class PartServiceImpl implements PartService {
@Override
public Object getPartByNumber(String number) throws Exception {
return DxConvertFactory.convertFactory(DxTypeEnum.WTPART,PartUtil.getPartByNumber(number, false));
}
}
This diff is collapsed.
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