yuedefeng 6 éve
szülő
commit
6c2c368f24

+ 114 - 5
src/dashoo.cn/backend/api/business/oilrtx/RtxService.go

@@ -1,13 +1,15 @@
 package oilrtx
 
 import (
+	"dashoo.cn/backend/api/business/organize"
+	. "dashoo.cn/utils/db"
 	"encoding/json"
+	"github.com/go-xorm/xorm"
+	"io/ioutil"
 	"log"
 	"net/http"
 	"strings"
-
-	. "dashoo.cn/utils/db"
-	"github.com/go-xorm/xorm"
+	"time"
 )
 
 type RtxService struct {
@@ -20,9 +22,29 @@ func GetRtxService(xormEngine *xorm.Engine) *RtxService {
 	return s
 }
 
-func (s *RtxService) CallRtx() *http.Response {
+//func (s *RtxService) RtxLogin(userName, password, userDomain string) *http.Response {
+func (s *RtxService) RtxLogin() *http.Response {
 	client := &http.Client{}
-	var rtx Rtx
+	var rtx RtxLogin
+	rtx.Username = "yuedefeng"
+	rtx.Password = "123456"
+	rtx.UserDomain = "LOCAL_IDENT"
+	json, err := json.Marshal(rtx)
+	params := string(json)
+	req, err := http.NewRequest("post", "http://api.uidp.dgyt.petrochina/ORG_Cloud_API/login/login", strings.NewReader(params))
+	req.Header.Add("Content-Type", "application/json")
+	resp, err := client.Do(req)
+	if err != nil {
+		log.Println("err= ", err)
+	}
+	log.Println("resp= ", resp)
+
+	return resp
+}
+
+func (s *RtxService) SendRtxMsg() *http.Response {
+	client := &http.Client{}
+	var rtx RtxMsg
 	rtx.Msg = "大港油田市场管理系统"
 	rtx.Receiver = "yuedefeng"
 	json, err := json.Marshal(rtx)
@@ -38,3 +60,90 @@ func (s *RtxService) CallRtx() *http.Response {
 
 	return resp
 }
+
+func (s *RtxService) GetOrgListByToken(token string) *http.Response {
+	client := &http.Client{}
+	req, err := http.NewRequest("get", "http://api.uidp.dgyt.petrochina/ORG_Cloud_API/org/fetchorglist", strings.NewReader(""))
+	req.Header.Add("Content-Type", "application/json")
+	req.Header.Add("X-Token", token)
+	resp, err := client.Do(req)
+	if err != nil {
+		log.Println("err= ", err)
+	}
+	log.Println("resp= ", resp)
+
+	return resp
+}
+
+func (s *RtxService) GetOrgList() RtxOrganizeItems {
+	var item RtxOrganizeItems
+
+	respToken := s.RtxLogin()
+	jsonBlob, _ := ioutil.ReadAll(respToken.Body)
+	var rtxRespToken RtxRespToken
+	json.Unmarshal(jsonBlob, &rtxRespToken)
+	if len(rtxRespToken.token) > 0 {
+		respOrgList := s.GetOrgListByToken(rtxRespToken.token)
+		jsonBlob2, _ := ioutil.ReadAll(respOrgList.Body)
+		json.Unmarshal(jsonBlob2, &item)
+	}
+	return item
+}
+
+
+func (s *RtxService) AutoSyncOrgList() bool {
+	organizeItem := s.GetOrgList()
+	return s.RecursionOrganize(organizeItem.Items)
+}
+
+//递归调用
+func (s *RtxService) RecursionOrganize(rtxOrganizes []RtxOrganize) bool {
+	orgSvc := organize.GetOrganizeService(s.DBE)
+	for _, rtxOrg := range rtxOrganizes {
+		var baseOrganize *organize.Base_Organize
+		where := "1=1 and Innerphone='" + rtxOrg.Id + "'"
+		orgSvc.GetEntity(&baseOrganize, where)
+		if baseOrganize == nil {
+			baseOrganize = new(organize.Base_Organize)
+		}
+
+		parentId := 0
+		if len(rtxOrg.ParentId) > 0 {
+			var baseParentOrganize organize.Base_Organize
+			where := "1=1 and Outerphone='" + rtxOrg.Id + "'"
+			orgSvc.GetEntity(&baseParentOrganize, where)
+			parentId = baseParentOrganize.Id
+		}
+
+		baseOrganize.Parentid = parentId
+		baseOrganize.Code = rtxOrg.OrgCode
+		baseOrganize.Fullname = rtxOrg.OrgShortName
+		baseOrganize.Description = rtxOrg.OrgName
+		baseOrganize.Innerphone = rtxOrg.Id
+		baseOrganize.Outerphone = rtxOrg.ParentId
+
+		if baseOrganize.Id <= 0 {
+			baseOrganize.Layer = 0
+			baseOrganize.Isinnerorganize = 1
+			baseOrganize.Sortcode = 0
+			baseOrganize.Deletionstatecode = 0
+			baseOrganize.Enabled = 1
+			baseOrganize.Createon = time.Now()
+			baseOrganize.Createby = "演示用户"
+			baseOrganize.Createuserid = 284
+			baseOrganize.Modifiedon = time.Now()
+			baseOrganize.Modifiedby = "演示用户"
+			baseOrganize.Modifieduserid = 284
+			orgSvc.InsertEntity(baseOrganize)
+		} else {
+			baseOrganize.Modifiedon = time.Now()
+			baseOrganize.Modifiedby = "演示用户"
+			baseOrganize.Modifieduserid = 284
+			orgSvc.UpdateEntityById(baseOrganize.Id, baseOrganize)
+		}
+		if rtxOrg.Children != nil || len(rtxOrg.Children) > 0 {
+			s.RecursionOrganize(rtxOrg.Children)
+		}
+	}
+	return true
+}

+ 29 - 1
src/dashoo.cn/backend/api/business/oilrtx/rtx.go

@@ -3,7 +3,35 @@ package oilrtx
 
 //"time"
 
-type Rtx struct {
+type RtxMsg struct {
 	Msg        string `json:"msg"`
 	Receiver   string `json:"receiver"`
 }
+
+type RtxLogin struct {
+	Username   string `json:"username"`
+	Password   string `json:"password"`
+	UserDomain string `json:"userDomain"`
+}
+
+type RtxRespToken struct {
+	code   		string `json:"code"`
+	message   	string `json:"message"`
+	token 		string `json:"token"`
+}
+
+type RtxOrganize struct {
+	Id   			string `json:"code"`
+	OrgCode   		string `json:"message"`
+	OrgName 		string `json:"token"`
+	OrgShortName 	string `json:"orgShortName"`
+	ParentId 		string `json:"parentId"`
+	IsInValid 		string `json:"ISINVALID"`
+	Remark 			string `json:"remark"`
+	Children 		[]RtxOrganize `json:"children"`
+}
+
+type RtxOrganizeItems struct {
+	Items	[]RtxOrganize	`json:"items"`
+
+}

+ 15 - 1
src/dashoo.cn/backend/api/controllers/rtx/rtx.go

@@ -18,7 +18,7 @@ type RtxController struct {
 func (this *RtxController) GetRtx() {
 
 	rtxSvc := oilrtx.GetRtxService(utils.DBE)
-	resp := rtxSvc.CallRtx()
+	resp := rtxSvc.SendRtxMsg()
 
 	var datainfo DataInfo
 	datainfo.Items = resp
@@ -26,3 +26,17 @@ func (this *RtxController) GetRtx() {
 	this.Data["json"] = &datainfo
 	this.ServeJSON()
 }
+
+// @Title get
+// @Description get workflow by token
+// @Success 200 {object} historicTasks
+// @router /syncOrganize [get]
+func (this *RtxController) SyncOrganizeList() {
+	rtxSvc := oilrtx.GetRtxService(utils.DBE)
+	resp := rtxSvc.AutoSyncOrgList()
+
+	var datainfo DataInfo
+	datainfo.Items = resp
+	this.Data["json"] = &datainfo
+	this.ServeJSON()
+}

+ 9 - 0
src/dashoo.cn/frontend_web/src/api/rtxservice/rtx.js

@@ -0,0 +1,9 @@
+export default {
+  syncOrganize (myAxios) {
+    return myAxios({
+      url: '/rtx/syncOrganize',
+      method: 'GET'
+    })
+  },
+
+}

+ 25 - 0
src/dashoo.cn/frontend_web/src/pages/system/organize.vue

@@ -11,6 +11,7 @@
         </el-breadcrumb>
         <span style="float: right;">
           <el-button size="mini" type="primary" style="margin-left:10px; margin-top: -4px;" @click="opendatadialog(1,null,-1);resetForm('organizeform')">新增组织</el-button>
+          <el-button size="mini" type="primary" style="margin-right:5px; margin-top: -4px;" @click="syncOrganize">同步RTX部门</el-button>
         </span>
         <el-form ref="form" :inline="true" style="float: right; margin-top: -10px">
           <el-form-item label="组织名称">
@@ -105,6 +106,8 @@
   import {
     mapGetters
   } from 'vuex'
+  import rtxApi from '@/api/rtxservice/rtx'
+
   export default {
     name: 'organize',
 
@@ -285,6 +288,28 @@
         this.currentPage = value
         this.initData()
       },
+      syncOrganize () {
+        rtxApi.syncOrganize(this.$axios).then(res => {
+          //response
+          if (res.data.Items) {
+            this.$message({
+              type: 'success',
+              message: '同步成功!'
+            })
+          } else {
+            this.$message({
+              type: 'error',
+              message: '同步失败!'
+            })
+          }
+          return res.data.Items
+
+        }).catch(err => {
+          // handle error
+          console.error(err)
+        })
+      },
+
       jstimehandle(val) {
         val = val.replace('T', ' ')
         return val.substring(0, 19)