场景
SpringBoot项目中实现开放一个接口,接受上位机传递的tryCode(托盘编号),进而在关联的两个表中插入数据。
效果
接口传递参数
接口返回数据
实现
在SpringBoot项目中的Controller
@Description("扫码生成单件质检单")
@RequestMapping(value="/generatingSingleJianQualityTestOrder",method =RequestMethod.POST)
@ResponseBody
@ApiOperation(value="生成单件质检单", notes="上位机扫码,生成单件质检单")
@ApiImplicitParam(name = "trayCode", value = "托盘编码", required = true, dataType = "String")
public Json generatingSingleJianQualityTestOrder(String trayCode) {
return this.wmsMasterCleanFinishService.generatingSingleJianQualityTestOrder(trayCode);
}
注:
@ApiOperation(value=”生成单件质检单”, notes=”上位机扫码,生成单件质检单”)
@ApiImplicitParam(name = “trayCode”, value = “托盘编码”, required = true, dataType = “String”)
这两个注解是swagger接口说明的注解,如果没有使用则直接忽略。
接受传递过来的trayCode参数,传递到service层。
其中Json是封装的Json数据类。
Json代码
package com.ws.api.sys.vo;
import lombok.Data;
import java.io.Serializable;
@Data
public class Json implements Serializable {
//默认未失败状态
private static Json instance;
private String msg = "接口访问失败";
private String title = "失败提示";
private boolean status = false;
private int code = 300;
private Object data = null;
public synchronized static Json getInst() {
if(instance==null){
instance = new Json();
}
return instance;
}
public Json() {
super();
}
public Json success(Object data){
this.title = "成功提示";
this.msg = "接口访问成功";
this.status = true;
this.code = 200;
this.data = data;
return this;
}
public Json success(){
this.title = "成功提示";
this.msg = "接口访问成功";
this.status = true;
this.code = 200;
this.data = null;
return this;
}
public Json fail(Object data){
this.title = "失败提示";
this.msg = "接口访问失败";
this.status = false;
this.code = 300;
this.data = data;
return this;
}
public Json fail(){
this.title = "失败提示";
this.msg = "接口访问失败";
this.status = false;
this.code = 300;
this.data = null;
return this;
}
}
Service层代码
public Json generatingSingleJianQualityTestOrder(String trayCode);
ServiceImpl代码
@Transactional
@Override
public Json generatingSingleJianQualityTestOrder(String trayCode)
{
Json json=Json.getInst();
try{
WmsQualitytesOrder wmsQualitytesOrder = new WmsQualitytesOrder();
//质检单号
String orderCode = this.iWmsQualitytesOrderService.generatePickNo(new Date());
wmsQualitytesOrder.setOrderCode(orderCode);
//创建时间
wmsQualitytesOrder.setGmtCreat(new Date());
//状态为 未质检
wmsQualitytesOrder.setStatus(0);
//发起机台固定为清洁车间机台cj002
wmsQualitytesOrder.setInitiaWorkshop("cj002");
//质检类型为单件质检
wmsQualitytesOrder.setQualifiedType("1");
int result = this.wmsQualitytesOrderMapper.insert(wmsQualitytesOrder);
if (result > 0){
WmsQualitytestListOrder wmsQualitytestListOrder = new WmsQualitytestListOrder();
//设置主表ID
wmsQualitytestListOrder.setQualitytestId(wmsQualitytesOrder.getId());
//设置物料名称
BusTrayMateriel busTrayMateriel = new BusTrayMateriel();
QueryWrapperbusTrayMaterielQueryWrapper = new QueryWrapper();
busTrayMaterielQueryWrapper.eq("tray_number", trayCode);
ListbusTrayMaterielList = new ArrayList ();
busTrayMaterielList = busTrayMaterielMapper.selectList(busTrayMaterielQueryWrapper);
busTrayMateriel=busTrayMaterielList.get(0);
wmsQualitytestListOrder.setMaterielName(busTrayMateriel.getMaterielName());
//设置物料ID
wmsQualitytestListOrder.setMaterielId(busTrayMateriel.getId());
//设置物料编号
wmsQualitytestListOrder.setMaterielNumber(busTrayMateriel.getMaterielNumber());
//设置物料类别名称
BusMaterielInfo busMaterielInfo = new BusMaterielInfo();
QueryWrapperbusTrayMaterielInfoQueryWrapper = new QueryWrapper();
busTrayMaterielInfoQueryWrapper.eq("materiel_number", busTrayMateriel.getMaterielNumber());
busMaterielInfo = busMaterielInfoMapper.selectOne(busTrayMaterielInfoQueryWrapper);
Long materialType = busMaterielInfo.getMaterielType();
//码表
SysCode sysCode = new SysCode();
QueryWrappersysCodeQueryWrapper = new QueryWrapper();
sysCodeQueryWrapper.eq("code_type", "materiel_type");
sysCodeQueryWrapper.eq("code_value", materialType);
sysCode = codeMapper.selectOne(sysCodeQueryWrapper);
wmsQualitytestListOrder.setMaterielTypeName(sysCode.getCodeName());
//设置物料类别
wmsQualitytestListOrder.setMaterielType(materialType.intValue());
//设置数量
wmsQualitytestListOrder.setNum(busTrayMaterielList.size());
//设置物料规格
wmsQualitytestListOrder.setMaterielSpec(busMaterielInfo.getMaterielSpec());
//设置单位
wmsQualitytestListOrder.setUntiy(busMaterielInfo.getUntiy());
//设置批次?单件质检是否应该有批次号
//设置供应商批次
wmsQualitytestListOrder.setSupplierBatch(busTrayMateriel.getSupplierBatch());
//设置质检类型
wmsQualitytestListOrder.setQualifiedType("1");
//设置质检名字
wmsQualitytestListOrder.setQualifiedName("单件质检");
//设置是否有批次
wmsQualitytestListOrder.setBatchFlag(0);
//设置发起机台
wmsQualitytestListOrder.setInitiaWorkshop("清洁车间机台");
//设置是否完成质检
wmsQualitytestListOrder.setQualifiedFlag(0);
//保存
this.iWmsQualitytestListOrderService.save(wmsQualitytestListOrder);
json.success();
json.setMsg("生成质检单成功");
}else{
json.fail();
json.setMsg("生成质检单主表异常,请联系管理员");
}
}catch (Exception e){
json.fail();
json.setMsg("生成质检单异常:"+e.toString());
}
return json;
}
服务器托管,北京服务器托管,服务器租用 http://www.fwqtg.net
机房租用,北京机房租用,IDC机房托管, http://www.e1idc.net