OA请购单流程结束传NCC
This commit is contained in:
parent
3a03ccbce0
commit
a619f68db7
|
@ -0,0 +1,12 @@
|
|||
package com.hzya.frame.plugin.oa.praybill.dao;
|
||||
|
||||
import com.hzya.frame.basedao.dao.IBaseDao;
|
||||
import com.hzya.frame.plugin.oa.praybill.entity.RequisitionOrderEntity;
|
||||
|
||||
/**
|
||||
* @Description OA请购单
|
||||
* @Author xiangerlin
|
||||
* @Date 2025/6/8 17:06
|
||||
**/
|
||||
public interface IRequisitionOrderDao extends IBaseDao<RequisitionOrderEntity,String> {
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
package com.hzya.frame.plugin.oa.praybill.dao.impl;
|
||||
|
||||
import com.hzya.frame.basedao.dao.MybatisGenericDao;
|
||||
import com.hzya.frame.plugin.oa.praybill.dao.IRequisitionOrderDao;
|
||||
import com.hzya.frame.plugin.oa.praybill.entity.RequisitionOrderEntity;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
/**
|
||||
* @Description OA请购单
|
||||
* @Author xiangerlin
|
||||
* @Date 2025/6/8 17:08
|
||||
**/
|
||||
@Repository("requisitionOrderDaoImpl")
|
||||
public class RequisitionOrderDaoImpl extends MybatisGenericDao<RequisitionOrderEntity,String> implements IRequisitionOrderDao {
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
package com.hzya.frame.plugin.oa.praybill.entity;
|
||||
|
||||
import com.hzya.frame.web.entity.BaseEntity;
|
||||
|
||||
/**
|
||||
* @Description OA请购单
|
||||
*
|
||||
* @Author xiangerlin
|
||||
* @Date 2025/6/8 17:04
|
||||
**/
|
||||
public class RequisitionOrderEntity extends BaseEntity {
|
||||
|
||||
private String field0001;//单据号
|
||||
private String field0059;//NCC
|
||||
|
||||
public String getField0001() {
|
||||
return field0001;
|
||||
}
|
||||
|
||||
public void setField0001(String field0001) {
|
||||
this.field0001 = field0001;
|
||||
}
|
||||
|
||||
public String getField0059() {
|
||||
return field0059;
|
||||
}
|
||||
|
||||
public void setField0059(String field0059) {
|
||||
this.field0059 = field0059;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.hzya.frame.plugin.oa.praybill.dao.impl.RequisitionOrderDaoImpl">
|
||||
|
||||
<update id="entity_update" parameterType="com.hzya.frame.plugin.oa.praybill.entity.RequisitionOrderEntity">
|
||||
update formmain_0254 set field0059 = #{field0059} where id = #{id}
|
||||
</update>
|
||||
</mapper>
|
|
@ -2,10 +2,12 @@ package com.hzya.frame.plugin.oa.praybill.plugin;
|
|||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.hzya.frame.base.PluginBaseEntity;
|
||||
import com.hzya.frame.plugin.oa.praybill.service.IRequisitionOrderPluginService;
|
||||
import com.hzya.frame.web.entity.BaseResult;
|
||||
import com.hzya.frame.web.entity.JsonResultEntity;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
/**
|
||||
* @Description 请购单传NCC
|
||||
|
@ -14,6 +16,8 @@ import org.slf4j.LoggerFactory;
|
|||
**/
|
||||
public class RequisitionOrderPluginInitializer extends PluginBaseEntity {
|
||||
Logger logger = LoggerFactory.getLogger(RequisitionOrderPluginInitializer.class);
|
||||
@Autowired
|
||||
private IRequisitionOrderPluginService requisitionOrderPluginService;
|
||||
/***
|
||||
* 插件初始化方法
|
||||
* @Author 👻👻👻👻👻👻👻👻 gjh
|
||||
|
@ -92,8 +96,10 @@ public class RequisitionOrderPluginInitializer extends PluginBaseEntity {
|
|||
@Override
|
||||
public JsonResultEntity executeBusiness(JSONObject requestJson) throws Exception {
|
||||
try {
|
||||
logger.info("======开始执行请购单传NCC插件======");
|
||||
logger.info("======开始执行请购单传NCC插件======{}",JSONObject.toJSONString(requestJson));
|
||||
requisitionOrderPluginService.sync2ncc(requestJson);
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
logger.info("======执行请购单传NCC插件出错======{}",e.getMessage());
|
||||
return BaseResult.getFailureMessageEntity("请购单传NCC插件执行失败",e.getMessage());
|
||||
}
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
package com.hzya.frame.plugin.oa.praybill.service;
|
||||
|
||||
import com.hzya.frame.basedao.service.IBaseService;
|
||||
import com.hzya.frame.plugin.oa.praybill.entity.RequisitionOrderEntity;
|
||||
|
||||
/**
|
||||
* @Description OA 请购单
|
||||
* @Author xiangerlin
|
||||
* @Date 2025/6/8 17:10
|
||||
**/
|
||||
public interface IRequisitionOrderService extends IBaseService<RequisitionOrderEntity,String> {
|
||||
|
||||
/**
|
||||
* 更新OA单据
|
||||
* @param entity
|
||||
* @return
|
||||
*/
|
||||
int updateOrder(RequisitionOrderEntity entity);
|
||||
}
|
|
@ -1,15 +1,25 @@
|
|||
package com.hzya.frame.plugin.oa.praybill.service.impl;
|
||||
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.http.HttpRequest;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.hzya.frame.plugin.oa.praybill.entity.RequisitionOrderEntity;
|
||||
import com.hzya.frame.plugin.oa.praybill.service.IRequisitionOrderPluginService;
|
||||
import com.hzya.frame.plugin.oa.praybill.service.IRequisitionOrderService;
|
||||
import com.hzya.frame.seeyon.enums.ColEventTypeEnum;
|
||||
import com.hzya.frame.sysnew.integtationTaskLivingDetails.entity.IntegrationTaskLivingDetailsEntity;
|
||||
import com.hzya.frame.sysnew.integtationTaskLivingDetails.service.IIntegrationTaskLivingDetailsService;
|
||||
import com.hzya.frame.uuid.UUIDUtils;
|
||||
import com.hzya.frame.web.entity.BaseResult;
|
||||
import com.hzya.frame.web.entity.JsonResultEntity;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -19,6 +29,12 @@ import java.util.List;
|
|||
* @Date 2025/5/21 17:44
|
||||
**/
|
||||
public class RequisitionOrderPluginServiceImpl implements IRequisitionOrderPluginService {
|
||||
@Value("${zt.url}")
|
||||
private String baseUrl;
|
||||
@Autowired
|
||||
private IIntegrationTaskLivingDetailsService taskLivingDetailsService;
|
||||
@Autowired
|
||||
private IRequisitionOrderService requisitionOrderService;
|
||||
Logger logger = LoggerFactory.getLogger(IRequisitionOrderPluginService.class);
|
||||
/**
|
||||
* 请购单同步到ncc
|
||||
|
@ -30,32 +46,179 @@ public class RequisitionOrderPluginServiceImpl implements IRequisitionOrderPlugi
|
|||
public JsonResultEntity sync2ncc(JSONObject requestJson) {
|
||||
//数据源编码
|
||||
String datasourceCode = requestJson.getString("sourceCode");
|
||||
String task_living_details_id = requestJson.getString("integration_task_living_details_id");
|
||||
String headersStr = requestJson.getString("headers");//请求头
|
||||
String formAppId = requestJson.getString("formApp");
|
||||
//String formAppId = requestJson.getString("formApp");
|
||||
String eventType = requestJson.getString("eventType");
|
||||
JSONObject formmainData = requestJson.getJSONObject("formmainTableName");
|
||||
JSONArray forsonData = requestJson.getJSONArray("forsonTableName");
|
||||
Assert.notEmpty(formAppId,"formAppId不能为空");
|
||||
JSONObject headers = requestJson.getJSONObject("headers");
|
||||
// Assert.notEmpty(formAppId,"formAppId不能为空");
|
||||
Assert.notEmpty(eventType,"eventType不能为空");
|
||||
Assert.notEmpty(headersStr,"headers不能为空");
|
||||
String formmainTableName = headers.getString("formmainTableName");
|
||||
String forsonTableName = headers.getString("forsonTableName");
|
||||
JSONObject jsonStrObj = requestJson.getJSONObject("jsonStr");
|
||||
JSONObject businessData = jsonStrObj.getJSONObject("businessDataStr");
|
||||
JSONObject formmainData = businessData.getJSONObject(formmainTableName);
|
||||
JSONArray forsonData = businessData.getJSONArray(forsonTableName);
|
||||
//流程结束
|
||||
if (ColEventTypeEnum.ONPROCESSFINISHED.getType().equals(eventType)){
|
||||
JSONObject paramObj = new JSONObject();
|
||||
JSONObject praybill = new JSONObject();
|
||||
praybill.put("pk_org",formmainData.getString("field0005"));//库存组织
|
||||
praybill.put("vbillcode",formmainData.getString("field0001"));//请购单号
|
||||
paramObj.put("head", praybill);
|
||||
praybill.put("pk_group",formmainData.getString("field0058"));//集团
|
||||
praybill.put("pk_org",formmainData.getString("field0027"));//库存组织
|
||||
praybill.put("pk_org_v",formmainData.getString("field0051"));//库存组织v
|
||||
//praybill.put("vbillcode",formmainData.getString("field0001"));//请购单号
|
||||
praybill.put("dbilldate",formmainData.getString("field0004"));//请购日期
|
||||
praybill.put("bsctype",formmainData.getString("field0009"));//委外
|
||||
praybill.put("pk_planpsn",formmainData.getString("field0010"));//计划员
|
||||
praybill.put("pk_plandept_v",formmainData.getString("field0011"));//计划部门
|
||||
boolean bsctype = false;
|
||||
if ("1".equals(formmainData.getString("field0009"))){
|
||||
bsctype = true;
|
||||
}
|
||||
praybill.put("bsctype",bsctype);//委外
|
||||
praybill.put("pk_planpsn",formmainData.getString("field0030"));//计划员
|
||||
praybill.put("pk_plandept",formmainData.getString("field0052"));//计划部门
|
||||
praybill.put("pk_plandept_v",formmainData.getString("field0053"));//计划部门v
|
||||
praybill.put("vmemo",formmainData.getString("field0013"));//备注
|
||||
praybill.put("fbillstatus",formmainData.getString("field0012"));//单据状态
|
||||
praybill.put("billmaker", formmainData.getString("field0002"));//制单人
|
||||
praybill.put("dmakedate", formmainData.getString(""));//制单日期
|
||||
praybill.put("ctrantypeid", formmainData.getString("field0006"));//请购类型
|
||||
praybill.put("fbillstatus",headers.getString("fbillstatus"));//单据状态
|
||||
praybill.put("bdirecttransit",false);//zhiyun
|
||||
praybill.put("billmaker", headers.getString("billmaker"));//制单人 yonyou99
|
||||
praybill.put("dmakedate", formmainData.getString("field0004"));//制单日期
|
||||
praybill.put("ctrantypeid", formmainData.getString("field0039"));//请购类型
|
||||
praybill.put("bislatest", true);//最新版本
|
||||
praybill.put("vdef1",formmainData.getString("field0002"));
|
||||
praybill.put("creator",headers.getString("creator"));//
|
||||
praybill.put("fpraysource",headers.getString("fpraysource"));//
|
||||
praybill.put("ccurrencyid",headers.getString("ccurrencyid"));//
|
||||
praybill.put("nversion",headers.getString("nversion"));//
|
||||
praybill.put("nversion",headers.getString("nversion"));//
|
||||
List<JSONObject> parybillList = new LinkedList<>();
|
||||
praybill.put("pk_praybill_b",parybillList);
|
||||
|
||||
paramObj.put("body",parybillList);
|
||||
String pk_org = formmainData.getString("field0027");
|
||||
String pk_org_v = formmainData.getString("field0051");
|
||||
for(int i=0; i<forsonData.size(); i++){
|
||||
JSONObject forson = forsonData.getJSONObject(i);
|
||||
JSONObject praybillB = new JSONObject();
|
||||
praybillB.put("crowno",forson.getString("field0014"));
|
||||
praybillB.put("nnum",forson.getString("field0020"));
|
||||
praybillB.put("pk_org",pk_org);
|
||||
praybillB.put("pk_org_v",pk_org_v);
|
||||
praybillB.put("vchangerate","1");
|
||||
praybillB.put("pk_srcmaterial",forson.getString("field0054"));//物料pk带版本的那个
|
||||
praybillB.put("pk_material",forson.getString("field0031"));//物料pk
|
||||
praybillB.put("castunitid",forson.getString("field0055"));//计量单位pk
|
||||
praybillB.put("cunitid",forson.getString("field0055"));//计量单位pk
|
||||
praybillB.put("nastnum",forson.getString("field0020"));//数量
|
||||
praybillB.put("dreqdate",forson.getString("field0021"));//需求日期
|
||||
praybillB.put("dsuggestdate",forson.getString("field0022"));//建议订货日期
|
||||
praybillB.put("pk_purchaseorg",pk_org);//采购组织
|
||||
praybillB.put("pk_purchaseorg_v",pk_org_v);//采购组织 带版本的那个
|
||||
praybillB.put("pk_suggestsupplier",forson.getString("field0056"));//建议供应商
|
||||
praybillB.put("pk_suggestsupplier_v",forson.getString("field0056"));//建议供应商
|
||||
praybillB.put("pk_reqstoorg",pk_org);
|
||||
praybillB.put("pk_reqstoorg_v",pk_org_v);
|
||||
praybillB.put("pk_group",formmainData.getString("field0058"));
|
||||
praybillB.put("browclose","N");//行关闭
|
||||
praybillB.put("vbdef1",forson.getString("field0032"));//现存量
|
||||
praybillB.put("vbdef2",forson.getString("field0033"));//在途量
|
||||
praybillB.put("vbdef3",forson.getString("field0035"));//月度消耗
|
||||
praybillB.put("vbdef4",forson.getString("field0034"));//安全库存
|
||||
parybillList.add(praybillB);
|
||||
}
|
||||
//调用NCC接口
|
||||
JSONArray reqParams = new JSONArray();
|
||||
reqParams.add(paramObj);
|
||||
String req = JSONObject.toJSONString(reqParams);
|
||||
logger.info("======OA请购单传NCC请求参数:{}======",req);
|
||||
String result = HttpRequest.post(baseUrl)
|
||||
.header("appId", "800065")//NCC请购单接口
|
||||
.header("apiCode", "8000650000")//NCC应用
|
||||
.header("publicKey", "ZJYAbkr9+XjnDrlfQCRKXtpVvg/BjxqtxzcLgg5TIGagEKJCe7eDIk+3zDUT+v578prj")//OA公钥
|
||||
.header("secretKey", "2GR4+yrcx+Ev+pN0Q6V6wxCdvisPX7wzNKBgc5SsIYGxYI5GTISXT6GvTPfp1u2Rj3JzOP8MtA1LSGvL+2BWG8c/o7DKi92S4mr3zcGearA=")//OA密钥
|
||||
.body(req)//表单内容
|
||||
.timeout(30000)//超时,毫秒
|
||||
.execute().body();
|
||||
logger.info("======OA请购单传NCC响应参数:{}======",result);
|
||||
if (StrUtil.isNotEmpty(result)){
|
||||
JSONObject resultJson = JSONObject.parseObject(result);
|
||||
Boolean flag = resultJson.getBoolean("flag");
|
||||
//保存日志
|
||||
IntegrationTaskLivingDetailsEntity taskLivingDetail = new IntegrationTaskLivingDetailsEntity();
|
||||
Date now = new Date();
|
||||
taskLivingDetail.setCreate_time(now);
|
||||
taskLivingDetail.setModify_time(now);
|
||||
taskLivingDetail.setRootAppPk(formmainData.getString("id"));
|
||||
taskLivingDetail.setRootAppBill(formmainData.getString("field0001"));
|
||||
taskLivingDetail.setPluginId("RequisitionOrderPlugin");
|
||||
taskLivingDetail.setRootAppNewData(req);
|
||||
taskLivingDetail.setNewTransmitInfo(result);
|
||||
taskLivingDetail.setNewPushDate(now);
|
||||
saveLog(task_living_details_id,flag,taskLivingDetail);
|
||||
//回写NCC单号到OA单据
|
||||
JSONObject attribute = resultJson.getJSONObject("attribute");
|
||||
if (null != attribute){
|
||||
String code = attribute.getString("code");
|
||||
if ("success".equals(code)){
|
||||
JSONObject data = attribute.getJSONObject("data");
|
||||
if (null != data){
|
||||
JSONObject headVO = data.getJSONObject("headVO");
|
||||
if (null != headVO){
|
||||
String vbillcode = headVO.getString("code");
|
||||
logger.info("======vbillcode======:{}",vbillcode);
|
||||
RequisitionOrderEntity requisitionOrderEntity = new RequisitionOrderEntity();
|
||||
requisitionOrderEntity.setField0059(vbillcode);
|
||||
requisitionOrderEntity.setDataSourceCode(datasourceCode);
|
||||
requisitionOrderEntity.setId(formmainData.getString("id"));
|
||||
requisitionOrderService.updateOrder(requisitionOrderEntity);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return BaseResult.getSuccessMessageEntity("请购单推NCC成功");
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
String result = "{\"msg\":\"转发失败\",\"type\":null,\"flag\":false,\"status\":\"500\",\"attribute\":{\"code\":\"success\",\"data\":{\"bodyVOList\":[{\"rowno\":\"1\",\"pk_material\":\"1001P1100000000IT34Q\",\"id\":\"1001A3100000001B2UOG\"}],\"headVO\":{\"code\":\"QG2025060800000182\",\"id\":\"1001A3100000001B2UOF\",\"vtrantypeid\":\"1001P1100000000IR21W\"}},\"message\":\"提示:========NCC-请购单保存提交《成功》!!!========。单据信息:《id》 = 1001A3100000001B2UOF ,《code》 = QG2025060800000182\"}}";
|
||||
JSONObject resultJson = JSONObject.parseObject(result);
|
||||
JSONObject attribute = resultJson.getJSONObject("attribute");
|
||||
if (null != attribute){
|
||||
String code = attribute.getString("code");
|
||||
if ("success".equals(code)){
|
||||
JSONObject data = attribute.getJSONObject("data");
|
||||
if (null != data){
|
||||
JSONObject headVO = data.getJSONObject("headVO");
|
||||
if (null != headVO){
|
||||
String vbillcode = headVO.getString("code");
|
||||
System.out.println(vbillcode);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//保存日志
|
||||
public void saveLog(String integration_task_living_details_id, Boolean flag, IntegrationTaskLivingDetailsEntity taskLivingDetail){
|
||||
try {
|
||||
//判断,成功调用这个方法
|
||||
if (StrUtil.isEmpty(integration_task_living_details_id)){
|
||||
if (flag){
|
||||
taskLivingDetailsService.saveLogToSuccess(taskLivingDetail);
|
||||
}else {
|
||||
//失败 调用这个方法
|
||||
taskLivingDetailsService.saveLogToFail(taskLivingDetail);
|
||||
}
|
||||
}else {
|
||||
taskLivingDetail.setId(integration_task_living_details_id);
|
||||
if (flag){
|
||||
//如果是重试 成功调这个方法
|
||||
taskLivingDetailsService.saveLogFailToSuccess(taskLivingDetail);
|
||||
}else {
|
||||
//如果是重试 失败调这个方法
|
||||
taskLivingDetailsService.updateLogFailToSuccess(taskLivingDetail);
|
||||
}
|
||||
}
|
||||
}catch (Exception e){
|
||||
logger.error("保存日志出错:{}",e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
package com.hzya.frame.plugin.oa.praybill.service.impl;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.dynamic.datasource.annotation.DS;
|
||||
import com.hzya.frame.basedao.service.impl.BaseService;
|
||||
import com.hzya.frame.plugin.oa.praybill.dao.IRequisitionOrderDao;
|
||||
import com.hzya.frame.plugin.oa.praybill.entity.RequisitionOrderEntity;
|
||||
import com.hzya.frame.plugin.oa.praybill.service.IRequisitionOrderService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* @Description OA请购单
|
||||
* @Author xiangerlin
|
||||
* @Date 2025/6/8 17:11
|
||||
**/
|
||||
@Service(value = "requisitionOrderServiceImpl")
|
||||
public class RequisitionOrderServiceImpl extends BaseService<RequisitionOrderEntity,String> implements IRequisitionOrderService {
|
||||
|
||||
private IRequisitionOrderDao requisitionOrderDao;
|
||||
|
||||
@Autowired
|
||||
public void setRequisitionOrderDao(IRequisitionOrderDao dao) {
|
||||
this.requisitionOrderDao = dao;
|
||||
this.dao = dao;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新OA单据
|
||||
*
|
||||
* @param entity
|
||||
* @return
|
||||
*/
|
||||
@DS(value = "#entity.dataSourceCode")
|
||||
@Override
|
||||
public int updateOrder(RequisitionOrderEntity entity) {
|
||||
if (null != entity && StrUtil.isNotEmpty(entity.getId())){
|
||||
requisitionOrderDao.update(entity);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue