package com.product.data.center.controller;
|
|
import com.product.core.entity.FieldSetEntity;
|
import com.product.core.exception.BaseException;
|
import com.product.core.spring.context.SpringMVCContextHolder;
|
import com.product.data.center.config.CmnConst;
|
import com.product.data.center.config.ErrorCode;
|
import com.product.data.center.service.JournalManagerService;
|
import com.product.data.center.service.MesExternalService;
|
import com.product.data.center.service.ide.IMesExternalService;
|
import com.product.module.sys.version.ApiVersion;
|
import com.product.util.BaseUtil;
|
import com.product.util.support.AbstractBaseController;
|
import org.apache.commons.lang3.StringUtils;
|
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RestController;
|
|
import javax.annotation.Resource;
|
import javax.servlet.http.HttpServletRequest;
|
|
/**
|
* Controller 中所有的接口已配置不需要token认证
|
*
|
* @Author cheng
|
* @Date 2022/12/16 13:20
|
* @Desc MES外部接口
|
*/
|
@RestController
|
@RequestMapping("/api/open-mes/")
|
public class MesExternalController extends AbstractBaseController {
|
|
@Resource
|
private MesExternalService mesExternalService;
|
|
@Resource
|
private JournalManagerService journalManagerService;
|
|
|
@PostMapping("get-collect-log/{version}")
|
@ApiVersion(1)
|
public String getCollectLog() {
|
try {
|
return BaseUtil.success(mesExternalService.getCollectLog());
|
} catch (BaseException e) {
|
e.printStackTrace();
|
return error(e);
|
} catch (Exception e) {
|
e.printStackTrace();
|
return error(ErrorCode.OPEN_API_REQUEST_FAIL, e);
|
}
|
}
|
|
/**
|
* 获取历史数据
|
*
|
* @param request
|
* @return
|
*/
|
@PostMapping("get-history-data/{version}")
|
@ApiVersion(1)
|
public String getHistory(HttpServletRequest request) {
|
SpringMVCContextHolder.getSystemLogger().info("get-history-data");
|
try {
|
FieldSetEntity fse = BaseUtil.getFieldSetEntity(request);
|
mesExternalService.getHistoryData(fse);
|
return OK();
|
} catch (BaseException e) {
|
e.printStackTrace();
|
SpringMVCContextHolder.getSystemLogger().error(e);
|
return error(e);
|
} catch (Exception e) {
|
e.printStackTrace();
|
SpringMVCContextHolder.getSystemLogger().error(e);
|
return error(ErrorCode.REQUEST_HISTORY_FAIL, e);
|
}
|
}
|
|
@PostMapping("/split-table-data/{version}")
|
@ApiVersion(1)
|
public String splitTableData(HttpServletRequest request) {
|
mesExternalService.splitTableData();
|
return OK();
|
}
|
|
@PostMapping("rehandle-error/{version}")
|
@ApiVersion(1)
|
public String rehandleError(HttpServletRequest request) {
|
try {
|
FieldSetEntity fse = BaseUtil.getFieldSetEntity(request);
|
journalManagerService.secondOperation(fse.getUUID());
|
return OK();
|
} catch (BaseException e) {
|
e.printStackTrace();
|
return error(e);
|
} catch (Exception e) {
|
e.printStackTrace();
|
return error(ErrorCode.OPEN_API_REQUEST_FAIL, e);
|
}
|
}
|
|
/**
|
* 创建或更新制令单
|
* 不要token、签名认证
|
*
|
* @param request
|
* @return
|
*/
|
@PostMapping("update-mo-base/{version}")
|
@ApiVersion(1)
|
public String updateMoBase(HttpServletRequest request) {
|
try {
|
FieldSetEntity fse = BaseUtil.getFieldSetEntity(request);
|
//制令单号
|
String moNumber = fse.getString("MO_NUMBER");
|
//操作类型 1 创建 2 更新
|
String type = fse.getString("TYPE");
|
if (StringUtils.isEmpty(moNumber)) {
|
throw new BaseException(ErrorCode.MO_NUMBER_CON_NOT_EMPTY);
|
}
|
if (!"1".equals(type) && !"2".equals(type)) {
|
throw new BaseException(ErrorCode.MO_NUMBER_OPERATION_TYPE_ERROR);
|
}
|
this.mesExternalService.updateMoBase(moNumber.split(","), Integer.parseInt(type));
|
return OK();
|
} catch (BaseException e) {
|
e.printStackTrace();
|
return error(e);
|
} catch (Exception e) {
|
e.printStackTrace();
|
return error(ErrorCode.OPEN_API_REQUEST_FAIL, e);
|
}
|
}
|
|
/**
|
* 初始化制令单
|
* 不要token、签名认证
|
*
|
* @param request
|
* @return
|
*/
|
@PostMapping("init-mo-base/{version}")
|
@ApiVersion(1)
|
public String initMoBase(HttpServletRequest request) {
|
try {
|
FieldSetEntity fse = BaseUtil.getFieldSetEntity(request);
|
//制令单号
|
String moNumber = fse.getString("MO_NUMBER");
|
if (StringUtils.isEmpty(moNumber)) {
|
throw new BaseException(ErrorCode.MO_NUMBER_CON_NOT_EMPTY);
|
}
|
this.mesExternalService.initMoBase(moNumber.split(","));
|
return OK();
|
} catch (BaseException e) {
|
e.printStackTrace();
|
return error(e);
|
} catch (Exception e) {
|
e.printStackTrace();
|
return error(ErrorCode.OPEN_API_REQUEST_FAIL, e);
|
}
|
}
|
|
/**
|
* 采集配置保存,子服务调用
|
* 不要token认证
|
*
|
* @param request
|
* @return
|
*/
|
@PostMapping("/save-collect-config/{version}")
|
@ApiVersion(1)
|
public String saveCollectConfig(HttpServletRequest request) {
|
try {
|
IMesExternalService mesExternalService = (IMesExternalService) this.getProxyInstance(this.mesExternalService);
|
mesExternalService.saveCollectConfig(request);
|
return OK();
|
} catch (BaseException e) {
|
e.printStackTrace();
|
return this.error(e);
|
} catch (Exception e) {
|
return this.error(new BaseException(e));
|
}
|
}
|
|
/**
|
* 提取配置保存,主服务调用
|
* 不要token认证
|
*
|
* @param request
|
* @return
|
*/
|
@PostMapping("/save-extract-config/{version}")
|
@ApiVersion(1)
|
public String saveExtractConfig(HttpServletRequest request) {
|
try {
|
FieldSetEntity fse = BaseUtil.getFieldSetEntity(request, CmnConst.DATA_EXTRACT_TABLE);
|
IMesExternalService mesExternalService = (IMesExternalService) this.getProxyInstance(this.mesExternalService);
|
mesExternalService.saveExtractConfig(fse);
|
return OK();
|
} catch (BaseException e) {
|
e.printStackTrace();
|
return this.error(e);
|
} catch (Exception e) {
|
return this.error(new BaseException(e));
|
}
|
}
|
|
/**
|
* 归档保存,主服务调用
|
* 不要token认证
|
*
|
* @param request
|
* @return
|
*/
|
@PostMapping("/save-archive-config/{version}")
|
@ApiVersion(1)
|
public String saveArchiveConfig(HttpServletRequest request) {
|
try {
|
FieldSetEntity fse = BaseUtil.getFieldSetEntity(request, CmnConst.DATA_ARCHIVING_TABLE);
|
IMesExternalService mesExternalService = (IMesExternalService) this.getProxyInstance(this.mesExternalService);
|
mesExternalService.saveArchiveConfig(fse);
|
return OK();
|
} catch (BaseException e) {
|
e.printStackTrace();
|
return this.error(e);
|
} catch (Exception e) {
|
return this.error(new BaseException(e));
|
}
|
}
|
|
/**
|
* 采集日志保存 子服务调用该接口
|
* 不要token认证
|
*
|
* @param request
|
* @return
|
*/
|
@PostMapping("save-collect-log/{version}")
|
@ApiVersion(1)
|
public String saveCollectLog(HttpServletRequest request) {
|
try {
|
FieldSetEntity fse = BaseUtil.getFieldSetEntity(request, CmnConst.PRODUCT_SYS_DATA_CENTER_LOG);
|
IMesExternalService mesExternalService = (IMesExternalService) this.getProxyInstance(this.mesExternalService);
|
mesExternalService.saveCollectLog(fse);
|
return OK();
|
} catch (BaseException e) {
|
e.printStackTrace();
|
return this.error(e);
|
} catch (Exception e) {
|
return this.error(new BaseException(e));
|
}
|
}
|
|
/**
|
* 提取日志保存主服务调用该接口
|
* 不要token认证
|
*
|
* @param request
|
* @return
|
*/
|
@PostMapping("save-extract-log/{version}")
|
@ApiVersion(1)
|
public String saveExtractLog(HttpServletRequest request) {
|
try {
|
FieldSetEntity fse = BaseUtil.getFieldSetEntity(request, CmnConst.PRODUCT_SYS_DATA_CENTER_LOG);
|
IMesExternalService mesExternalService = (IMesExternalService) this.getProxyInstance(this.mesExternalService);
|
mesExternalService.saveExtractLog(fse);
|
return OK();
|
} catch (BaseException e) {
|
e.printStackTrace();
|
return this.error(e);
|
} catch (Exception e) {
|
return this.error(new BaseException(e));
|
}
|
}
|
|
/**
|
* 定时任务日志保存,子服务调用
|
* 不要token认证
|
*
|
* @param request
|
* @return
|
*/
|
@PostMapping("/save-timed-log/{version}")
|
@ApiVersion(1)
|
public String saveTimedLog(HttpServletRequest request) {
|
try {
|
FieldSetEntity fse = BaseUtil.getFieldSetEntity(request, CmnConst.DATA_ARCHIVING_TABLE);
|
MesExternalService mesExternalService = (MesExternalService) this.getProxyInstance(this.mesExternalService);
|
mesExternalService.remoteSaveArchiveConfig(fse);
|
return OK();
|
} catch (BaseException e) {
|
e.printStackTrace();
|
return this.error(e);
|
} catch (Exception e) {
|
return this.error(new BaseException(e));
|
}
|
}
|
}
|