|
|
|
|
package examtestpage
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"encoding/json"
|
|
|
|
|
"errors"
|
|
|
|
|
"fmt"
|
|
|
|
|
"strconv"
|
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
|
"github.com/flipped-aurora/gin-vue-admin/server/commonus"
|
|
|
|
|
"github.com/flipped-aurora/gin-vue-admin/server/global"
|
|
|
|
|
"github.com/flipped-aurora/gin-vue-admin/server/model/common/response"
|
|
|
|
|
"github.com/flipped-aurora/gin-vue-admin/server/model/testpage"
|
|
|
|
|
"github.com/flipped-aurora/gin-vue-admin/server/model/wechat"
|
|
|
|
|
"github.com/flipped-aurora/gin-vue-admin/server/utils/redishandel"
|
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
|
"gorm.io/gorm"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
//集团分厂管理模块
|
|
|
|
|
type GroupHandleApi struct{}
|
|
|
|
|
|
|
|
|
|
//集团栏目
|
|
|
|
|
type GroupMap struct {
|
|
|
|
|
Id int64 `json:"id" gorm:"column:g_id;type:bigint(20);;primaryKey;unique;not null;autoIncrement;index"`
|
|
|
|
|
Name string `json:"name" gorm:"column:g_name;type:varchar(255);not null;comment:组织名称"` //'组织名称',
|
|
|
|
|
Time int64 `json:"time" gorm:"column:g_time;type:bigint(20) unsigned;default:0;not null;comment:编辑时间"` //'编辑时间',
|
|
|
|
|
Parentid int64 `json:"parentid" gorm:"column:g_parentid;type:bigint(20) unsigned;default:0;not null;comment:父级栏目"`
|
|
|
|
|
Sate int8 `json:"state" gorm:"column:g_sate;type:tinyint(1) unsigned;default:1;not null;comment:状态"` //'状态',
|
|
|
|
|
JinDieId string `json:"jindieid" gorm:"column:g_jindie_id;type:bigint(20) unsigned;default:0;not null;comment:金蝶ID"` //金蝶ID
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type TableData struct {
|
|
|
|
|
ID int64 `json:"id"`
|
|
|
|
|
Name string `json:"name"`
|
|
|
|
|
Address bool `json:"address"`
|
|
|
|
|
WxId string `json:"wxId"`
|
|
|
|
|
JdId string `json:"jdId"`
|
|
|
|
|
Attributes int8 `json:"attributes"`
|
|
|
|
|
Sort int `json:"sort"`
|
|
|
|
|
Date string `json:"date"`
|
|
|
|
|
Children interface{} `json:"children"`
|
|
|
|
|
QueryId int `json:"queryid"`
|
|
|
|
|
SingId int `json:"singid"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//POST提交参数
|
|
|
|
|
type postGroupCanshu struct {
|
|
|
|
|
Id int64 `json:"id" from:"id"`
|
|
|
|
|
TypeId int `json:"typeid" from:"typeid"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//集团列表
|
|
|
|
|
func (g *GroupHandleApi) GroupList(c *gin.Context) {
|
|
|
|
|
var groupStruct []wechat.GroupForm //集团表结构
|
|
|
|
|
var groupMap []GroupMap //要获取的集团架构字段
|
|
|
|
|
var groupMapStruct []TableData
|
|
|
|
|
err := global.GVA_DB_WatchDate.Model(&groupStruct).Where("g_parentid = ?", 1).Find(&groupMap).Error //获取集团信息
|
|
|
|
|
if err != nil {
|
|
|
|
|
fmt.Println(err)
|
|
|
|
|
response.Result(100, groupMapStruct, "集团架构获取失败!", c)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
var departList []testpage.BranchFactoryHasMany
|
|
|
|
|
// err = global.GVA_DB_Master.Preload("WorkshopSectionStruct").Where("bf_group = ?", 3).Find(&departList)
|
|
|
|
|
// groupAry := map[int]interface{}{}
|
|
|
|
|
|
|
|
|
|
for i, v := range groupMap {
|
|
|
|
|
fmt.Printf("%v\n", v.Id)
|
|
|
|
|
err = global.GVA_DB_Master.Preload("WorkshopSectionStruct").Where("bf_group = ?", v.Id).Find(&departList).Error
|
|
|
|
|
if err == nil {
|
|
|
|
|
var groupTypeStruct TableData
|
|
|
|
|
groupTypeStruct.ID = v.Id
|
|
|
|
|
groupTypeStruct.Name = v.Name
|
|
|
|
|
groupTypeStruct.Address = true
|
|
|
|
|
groupTypeStruct.WxId = strconv.FormatInt(v.Id, 10)
|
|
|
|
|
groupTypeStruct.JdId = v.JinDieId
|
|
|
|
|
groupTypeStruct.Attributes = 1
|
|
|
|
|
groupTypeStruct.Sort = i + 1
|
|
|
|
|
groupTypeStruct.QueryId = 1
|
|
|
|
|
groupTypeStruct.Date = commonus.TimeStampToDate(v.Time, 6)
|
|
|
|
|
groupTypeStruct.Children = openGroupMap(i+1, departList)
|
|
|
|
|
groupTypeStruct.SingId = i + 1
|
|
|
|
|
// groupAry[i] = openGroupMap(departList)
|
|
|
|
|
groupMapStruct = append(groupMapStruct, groupTypeStruct)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
sendMap := commonus.MapOut()
|
|
|
|
|
sendMap["list"] = groupMapStruct
|
|
|
|
|
// fmt.Printf("%v\n", groupMap)
|
|
|
|
|
// response.Ok(c)
|
|
|
|
|
response.Result(0, sendMap, "获取成功", c)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// //展开集团列表
|
|
|
|
|
func openGroupMap(singid int, data []testpage.BranchFactoryHasMany) []TableData {
|
|
|
|
|
// openMapData := map[int]interface{}{}
|
|
|
|
|
var mapStruct []TableData
|
|
|
|
|
for i, v := range data {
|
|
|
|
|
var kk TableData
|
|
|
|
|
kk.ID = v.Id
|
|
|
|
|
kk.Name = v.Name
|
|
|
|
|
kk.Address = true
|
|
|
|
|
if v.Set != 1 {
|
|
|
|
|
kk.Address = false
|
|
|
|
|
}
|
|
|
|
|
kk.WxId = strconv.FormatInt(v.WechatId, 10)
|
|
|
|
|
kk.JdId = ""
|
|
|
|
|
kk.Attributes = v.Attribute
|
|
|
|
|
kk.Sort = i + 1
|
|
|
|
|
kk.QueryId = 2
|
|
|
|
|
kk.Date = commonus.TimeStampToDate(v.Time, 6)
|
|
|
|
|
var sunGroup []TableData
|
|
|
|
|
for ii, vv := range v.WorkshopSectionStruct {
|
|
|
|
|
var kk_i TableData
|
|
|
|
|
kk_i.ID = vv.Id
|
|
|
|
|
kk_i.Name = vv.Name
|
|
|
|
|
kk_i.Address = true
|
|
|
|
|
if vv.Set != 1 {
|
|
|
|
|
kk_i.Address = false
|
|
|
|
|
}
|
|
|
|
|
kk_i.WxId = ""
|
|
|
|
|
kk_i.JdId = ""
|
|
|
|
|
kk_i.Attributes = 0
|
|
|
|
|
kk_i.Sort = ii + 1
|
|
|
|
|
kk_i.QueryId = 3
|
|
|
|
|
kk_i.Date = commonus.TimeStampToDate(vv.Time, 6)
|
|
|
|
|
kk_i.SingId, _ = strconv.Atoi(strconv.Itoa(singid) + strconv.Itoa(i) + strconv.Itoa(ii))
|
|
|
|
|
// kk_i.Children = []map[string]interface{}{}
|
|
|
|
|
sunGroup = append(sunGroup, kk_i)
|
|
|
|
|
}
|
|
|
|
|
kk.Children = sunGroup
|
|
|
|
|
kk.SingId, _ = strconv.Atoi(strconv.Itoa(singid) + strconv.Itoa(i))
|
|
|
|
|
mapStruct = append(mapStruct, kk)
|
|
|
|
|
}
|
|
|
|
|
return mapStruct
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//获取集团信息
|
|
|
|
|
/*
|
|
|
|
|
@id 集团ID
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
func (g *GroupHandleApi) GetGroupInfo(c *gin.Context) {
|
|
|
|
|
var id postGroupCanshu
|
|
|
|
|
_ = c.ShouldBindJSON(&id) //获取提交的参数
|
|
|
|
|
if id.Id == 0 {
|
|
|
|
|
response.Result(101, id, "您的参数不正确!请检查您的提交!", c)
|
|
|
|
|
}
|
|
|
|
|
var groupStruct wechat.GroupForm //集团表结构
|
|
|
|
|
err := global.GVA_DB_WatchDate.Where("g_id = ?", id.Id).First(&groupStruct).Error //获取集团信息
|
|
|
|
|
if err != nil {
|
|
|
|
|
response.Result(100, groupStruct, "获取失败", c)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
sendMap := commonus.MapOut()
|
|
|
|
|
sendMap["list"] = groupStruct
|
|
|
|
|
// fmt.Printf("====>%v\n", id.Id)
|
|
|
|
|
response.Result(0, groupStruct, "获取成功", c)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*获取子公司信息
|
|
|
|
|
@id 子公司ID
|
|
|
|
|
*/
|
|
|
|
|
func (g *GroupHandleApi) GetSubsidiaryInfo(c *gin.Context) {
|
|
|
|
|
var id postGroupCanshu
|
|
|
|
|
_ = c.ShouldBindJSON(&id) //获取提交的参数
|
|
|
|
|
if id.Id == 0 {
|
|
|
|
|
response.Result(101, id, "您的参数不正确!请检查您的提交!", c)
|
|
|
|
|
}
|
|
|
|
|
var subsidiaryStruct testpage.BranchFactory //子公司表结构
|
|
|
|
|
err := global.GVA_DB_Master.Where("bf_id = ?", id.Id).First(&subsidiaryStruct).Error //获取子公司信息
|
|
|
|
|
if err != nil {
|
|
|
|
|
response.Result(100, subsidiaryStruct, "获取失败", c)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
sendMap := commonus.MapOut()
|
|
|
|
|
sendMap["list"] = subsidiaryStruct
|
|
|
|
|
response.Result(0, subsidiaryStruct, "获取成功", c)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*获取工段信息
|
|
|
|
|
@id 工段ID
|
|
|
|
|
*/
|
|
|
|
|
func (g *GroupHandleApi) GetGroupPositionInfo(c *gin.Context) {
|
|
|
|
|
var id postGroupCanshu
|
|
|
|
|
_ = c.ShouldBindJSON(&id) //获取提交的参数
|
|
|
|
|
if id.Id == 0 {
|
|
|
|
|
response.Result(101, id, "您的参数不正确!请检查您的提交!", c)
|
|
|
|
|
}
|
|
|
|
|
var workShopesStruct testpage.WorkShopsection //工段表结构
|
|
|
|
|
err := global.GVA_DB_Master.Where("ws_id = ?", id.Id).First(&workShopesStruct).Error //获取工段信息
|
|
|
|
|
if err != nil {
|
|
|
|
|
response.Result(100, workShopesStruct, "获取失败", c)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
sendMap := commonus.MapOut()
|
|
|
|
|
sendMap["list"] = workShopesStruct
|
|
|
|
|
response.Result(0, workShopesStruct, "获取成功", c)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
删除操作
|
|
|
|
|
@id 要删除的ID
|
|
|
|
|
@type 要删除的类型
|
|
|
|
|
*/
|
|
|
|
|
func (g *GroupHandleApi) DelGroupInfo(c *gin.Context) {
|
|
|
|
|
var postInfo postGroupCanshu
|
|
|
|
|
err := c.ShouldBindJSON(&postInfo)
|
|
|
|
|
if err != nil {
|
|
|
|
|
response.Result(100, err, "您的参数不正确!请检查您的提交!", c)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if postInfo.Id == 0 {
|
|
|
|
|
response.Result(101, postInfo.Id, "您的参数不正确!请检查您的提交!", c)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
var errSun error
|
|
|
|
|
switch postInfo.TypeId {
|
|
|
|
|
case 1:
|
|
|
|
|
// fmt.Println("A1")
|
|
|
|
|
errSun = DelDepartment(postInfo.Id)
|
|
|
|
|
case 2:
|
|
|
|
|
errSun = DelWorhPost(postInfo.Id)
|
|
|
|
|
default:
|
|
|
|
|
// fmt.Println("A2")
|
|
|
|
|
errSun = DelterGroup(postInfo.Id)
|
|
|
|
|
}
|
|
|
|
|
// fmt.Printf("%v===========>%T\n", postInfo.TypeId, postInfo.TypeId)
|
|
|
|
|
if errSun != nil {
|
|
|
|
|
msg := fmt.Sprintf("删除失败!%v", errSun)
|
|
|
|
|
response.Result(102, errSun, msg, c)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
sendMap := commonus.MapOut()
|
|
|
|
|
sendMap["list"] = errSun
|
|
|
|
|
response.Result(0, errSun, "获取成功", c)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
软删除集团信息
|
|
|
|
|
@id 集团ID
|
|
|
|
|
*/
|
|
|
|
|
func DelterGroup(id int64) error {
|
|
|
|
|
assignErr := global.GVA_DB_WatchDate.Model(&wechat.GroupForm{}).Where("g_parentid = ? and g_id = ?", 1, id).First(&GroupMap{}).Error //获取集团信息
|
|
|
|
|
if errors.Is(assignErr, gorm.ErrRecordNotFound) {
|
|
|
|
|
return errors.New("该集团不存在!")
|
|
|
|
|
}
|
|
|
|
|
err := global.GVA_DB_WatchDate.Where("g_id = ?", id).First(&wechat.GroupForm{}).Update("g_sate", 2).Error
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
软删除分厂信息
|
|
|
|
|
@id 分厂ID
|
|
|
|
|
*/
|
|
|
|
|
func DelDepartment(id int64) error {
|
|
|
|
|
assignErr := global.GVA_DB_Master.Where("bf_set = ? and bf_id = ?", 1, id).First(&testpage.BranchFactory{}).Error //获取分厂或部室信息
|
|
|
|
|
if errors.Is(assignErr, gorm.ErrRecordNotFound) {
|
|
|
|
|
return errors.New("该分厂或部室不存在!")
|
|
|
|
|
}
|
|
|
|
|
err := global.GVA_DB_Master.Where("bf_id = ?", id).First(&testpage.BranchFactory{}).Update("bf_set", 3).Error
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
软删除分厂信息
|
|
|
|
|
@id 分厂ID
|
|
|
|
|
*/
|
|
|
|
|
func DelWorhPost(id int64) error {
|
|
|
|
|
assignErr := global.GVA_DB_Master.Where("ws_set = ? and ws_id = ?", 1, id).First(&testpage.WorkShopsection{}).Error //获取分厂或部室信息
|
|
|
|
|
if errors.Is(assignErr, gorm.ErrRecordNotFound) {
|
|
|
|
|
return errors.New("该工段不存在!")
|
|
|
|
|
}
|
|
|
|
|
err := global.GVA_DB_Master.Where("ws_id = ?", id).First(&testpage.WorkShopsection{}).Update("ws_set", 3).Error
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//添加组织架构(集团信息)
|
|
|
|
|
/*
|
|
|
|
|
@id 部门ID
|
|
|
|
|
@name 部门名称
|
|
|
|
|
@parentid 上级部门ID。顶级部门的上级ID为1
|
|
|
|
|
@state 状态(1:启用;2:禁用)
|
|
|
|
|
@jindieid 金蝶ID
|
|
|
|
|
*/
|
|
|
|
|
func (g *GroupHandleApi) AddGroupInfo(c *gin.Context) {
|
|
|
|
|
var groupInfo GroupMap
|
|
|
|
|
_ = c.ShouldBindJSON(&groupInfo) //获取提交的参数
|
|
|
|
|
if groupInfo.Parentid == 0 {
|
|
|
|
|
response.Result(101, groupInfo, "您的参数不正确!请检查您的提交!", c)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if groupInfo.Name == "" {
|
|
|
|
|
response.Result(102, groupInfo, "您的参数不正确!请检查您的提交!", c)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
var groupStruct wechat.GroupForm //集团表结构
|
|
|
|
|
var groupMap GroupMap //要获取的集团架构字段
|
|
|
|
|
err := global.GVA_DB_WatchDate.Model(&groupStruct).Where("g_name = ?", groupInfo.Name).First(&groupMap).Error //获取集团信息
|
|
|
|
|
if err == nil {
|
|
|
|
|
response.Result(103, groupMap, "该集团名称已经存在!请更换!", c)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
var dep commonus.DePartMentInfo
|
|
|
|
|
addId, adderr := dep.AddDepartment(groupInfo.Parentid, groupInfo.Name)
|
|
|
|
|
if adderr != true {
|
|
|
|
|
response.Result(1003, groupInfo.Name, "该集团添加失败(企业微信通讯故障!)", c)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
groupStruct.Id = addId
|
|
|
|
|
groupStruct.Name = groupInfo.Name
|
|
|
|
|
groupStruct.Parentid = groupInfo.Parentid
|
|
|
|
|
groupStruct.Orderes = 1
|
|
|
|
|
groupStruct.Time = time.Now().Unix()
|
|
|
|
|
groupStruct.Sate = 1
|
|
|
|
|
groupStruct.Group = ""
|
|
|
|
|
groupStruct.GroupSun = ""
|
|
|
|
|
groupStruct.JinDieId = 0
|
|
|
|
|
result := global.GVA_DB_WatchDate.Create(&groupStruct).Error
|
|
|
|
|
if result != nil {
|
|
|
|
|
commonus.DelDepartment(addId)
|
|
|
|
|
response.Result(1004, groupStruct, "该集团添加失败(写入数据库错误!)", c)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
// redisClient := redishandel.RunRedis()
|
|
|
|
|
// redisClient.SetRedisTime(7200)
|
|
|
|
|
// redisClient.Set("kaifa", "1234565")
|
|
|
|
|
// jsh, _ := redisClient.Get("kaifa")
|
|
|
|
|
// fmt.Printf("%v ----------%v ********** %v\n", ton, add, id)
|
|
|
|
|
// fmt.Printf("%v ----------%v ********** %v\n", ton, err, jsh)
|
|
|
|
|
|
|
|
|
|
// jsonBytes, _ := json.Marshal(groupInfo)
|
|
|
|
|
// commonus.CurlPostJosn("111", jsonBytes)
|
|
|
|
|
// fmt.Printf("%v ----------%T ********** %v********** %v\n", jsonBytes, jsonBytes, addId, adderr)
|
|
|
|
|
sendMap := commonus.MapOut()
|
|
|
|
|
sendMap["list"] = groupStruct
|
|
|
|
|
response.Result(0, groupStruct, "添加成功", c)
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
修改组织架构(集团信息)
|
|
|
|
|
@id 部门ID
|
|
|
|
|
@name 部门名称
|
|
|
|
|
@parentid 上级部门ID。顶级部门的上级ID为1
|
|
|
|
|
@state 状态(1:启用;2:禁用)
|
|
|
|
|
@jindieid 金蝶ID
|
|
|
|
|
*/
|
|
|
|
|
func (g *GroupHandleApi) EiteGroupInfo(c *gin.Context) {
|
|
|
|
|
var groupInfo GroupMap
|
|
|
|
|
_ = c.ShouldBindJSON(&groupInfo) //获取提交的参数
|
|
|
|
|
if groupInfo.Id == 0 {
|
|
|
|
|
response.Result(101, groupInfo, "您的参数不正确!请检查您的提交!", c)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
var groupStruct wechat.GroupForm //集团表结构 //要获取的集团架构字段
|
|
|
|
|
judgeErr := global.GVA_DB_WatchDate.Where("g_id = ?", groupInfo.Id).First(&groupStruct).Error //获取集团信息
|
|
|
|
|
if judgeErr != nil {
|
|
|
|
|
response.Result(101, judgeErr, "该集团不存在!请检查你的数据!", c)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if groupInfo.Name == "" {
|
|
|
|
|
response.Result(102, groupInfo, "请提交修改后的集团名称!", c)
|
|
|
|
|
return
|
|
|
|
|
} else {
|
|
|
|
|
groupStruct.Name = groupInfo.Name
|
|
|
|
|
}
|
|
|
|
|
if groupInfo.Parentid != 0 {
|
|
|
|
|
groupStruct.Parentid = groupInfo.Parentid
|
|
|
|
|
}
|
|
|
|
|
if groupInfo.Sate != 0 {
|
|
|
|
|
groupStruct.Sate = groupInfo.Sate
|
|
|
|
|
}
|
|
|
|
|
if groupInfo.JinDieId != "" {
|
|
|
|
|
jinDieId, jinDeiErr := strconv.ParseInt(groupInfo.JinDieId, 10, 64)
|
|
|
|
|
|
|
|
|
|
if jinDeiErr != nil {
|
|
|
|
|
groupStruct.JinDieId = 0
|
|
|
|
|
} else {
|
|
|
|
|
groupStruct.JinDieId = jinDieId
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
groupStruct.Time = time.Now().Unix()
|
|
|
|
|
|
|
|
|
|
affairOperation := global.GVA_DB_WatchDate.Begin()
|
|
|
|
|
|
|
|
|
|
saveErr := affairOperation.Save(groupStruct).Error
|
|
|
|
|
if saveErr != nil {
|
|
|
|
|
affairOperation.Rollback()
|
|
|
|
|
response.Result(102, groupInfo, "数据写入失败!", c)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
var dep commonus.DePartMentInfo
|
|
|
|
|
_, saveErrwe := dep.SaveDepartment(groupStruct.Id, groupStruct.Orderes, groupStruct.Parentid, groupStruct.Name, "")
|
|
|
|
|
if saveErrwe != true {
|
|
|
|
|
affairOperation.Rollback()
|
|
|
|
|
response.Result(102, groupInfo, "与企业微信通讯失败", c)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
affairOperation.Commit()
|
|
|
|
|
sendMap := commonus.MapOut()
|
|
|
|
|
sendMap["list"] = groupStruct
|
|
|
|
|
response.Result(0, groupStruct, "修改成功", c)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//获取单个成员信息
|
|
|
|
|
type getOneUserSendDate struct {
|
|
|
|
|
UserId string `json:"userid" from:"userid"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//获取成员详细信息
|
|
|
|
|
func (g *GroupHandleApi) GetOneUserInfoAll(c *gin.Context) {
|
|
|
|
|
var groupInfo getOneUserSendDate
|
|
|
|
|
_ = c.ShouldBindJSON(&groupInfo) //获取提交的参数
|
|
|
|
|
if groupInfo.UserId == "" {
|
|
|
|
|
response.Result(101, groupInfo, "您的参数不正确!请检查您的提交!", c)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
redisClient := redishandel.RunRedis()
|
|
|
|
|
isTrue, tokenInfo := redisClient.HashGet("deUserAry:wechat_"+global.GVA_CONFIG.RedisPrefix.Alias, "userinfo_"+"_"+groupInfo.UserId)
|
|
|
|
|
if isTrue != true {
|
|
|
|
|
userInfo, msg, _ := commonus.GetOneAddressBookMember(groupInfo.UserId)
|
|
|
|
|
var callBackData commonus.WechatUserInfo
|
|
|
|
|
json.Unmarshal(userInfo, &callBackData)
|
|
|
|
|
|
|
|
|
|
var us commonus.UserListStruct
|
|
|
|
|
json.Unmarshal(userInfo, &us)
|
|
|
|
|
|
|
|
|
|
userMap := commonus.MapOut()
|
|
|
|
|
json.Unmarshal(userInfo, &userMap)
|
|
|
|
|
jsonUser, _ := json.Marshal(us)
|
|
|
|
|
redisClient.SetRedisTime(2678400)
|
|
|
|
|
redisClient.HashSet("deUserAry:wechat_"+global.GVA_CONFIG.RedisPrefix.Alias, "userinfo_"+"_"+groupInfo.UserId, string(jsonUser))
|
|
|
|
|
response.Result(0, us, msg, c)
|
|
|
|
|
} else {
|
|
|
|
|
var us commonus.UserListStruct
|
|
|
|
|
json.Unmarshal([]byte(tokenInfo), &us)
|
|
|
|
|
response.Result(0, us, "获取成功", c)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// fmt.Printf("%v=============>%v\n", kjs, userMap)
|
|
|
|
|
// var sendText commonus.SendText
|
|
|
|
|
// sendText.Touser = groupInfo.UserId
|
|
|
|
|
// sendText.MsgType = "text"
|
|
|
|
|
// appId, _ := strconv.ParseInt(global.GVA_CONFIG.WorkWechatSchool.AgentId, 10, 64)
|
|
|
|
|
// fmt.Printf("AppId===>%v\n", global.GVA_CONFIG.WorkWechatSchool.AgentId)
|
|
|
|
|
// sendText.AgentId = appId
|
|
|
|
|
// sendText.Text.Content = "异常规矩人员 \n人员列表\n" + callBackData.Name + " 打卡地址:" + callBackData.Address + " \n张义良 打卡地址:" + callBackData.Address + "\n<a href=\"https://www.hxgk.group\">查看详情</a>"
|
|
|
|
|
// sendText.DuplicateCheckInterval = 1800
|
|
|
|
|
// sendText.SendTextMessage()
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//获取单个成员信息
|
|
|
|
|
type getDeparMentUserSendDate struct {
|
|
|
|
|
Id int `json:"id" from:"id"`
|
|
|
|
|
FetchChild int `json:"fetch_child" from:"fetch_child"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//获取部门成员 GetDepartmentUserList
|
|
|
|
|
func (g *GroupHandleApi) GetDepartMentUserInfoAll(c *gin.Context) {
|
|
|
|
|
var groupInfo getDeparMentUserSendDate
|
|
|
|
|
_ = c.ShouldBindJSON(&groupInfo) //获取提交的参数
|
|
|
|
|
if groupInfo.Id == 0 {
|
|
|
|
|
response.Result(101, groupInfo, "您的参数不正确!请检查您的提交!", c)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
redisClient := redishandel.RunRedis()
|
|
|
|
|
redisClient.SetRedisTime(2678400)
|
|
|
|
|
isTrueStr, departmentUserList := redisClient.Get("deUserAry:wechat_user_list" + global.GVA_CONFIG.RedisPrefix.Alias + "_" + strconv.Itoa(groupInfo.Id))
|
|
|
|
|
|
|
|
|
|
if isTrueStr == false {
|
|
|
|
|
userInfo, msg, _ := commonus.GetDepartmentUserList(groupInfo.Id)
|
|
|
|
|
var callBackData commonus.WechatUserInfoDepartment
|
|
|
|
|
json.Unmarshal(userInfo, &callBackData)
|
|
|
|
|
for _, v := range callBackData.UserList {
|
|
|
|
|
isTrue, _ := redisClient.HashGet("deUserAry:wechat_"+global.GVA_CONFIG.RedisPrefix.Alias, "userinfo_"+"_"+v.UserId)
|
|
|
|
|
if isTrue != true {
|
|
|
|
|
// var us commonus.UserListStruct
|
|
|
|
|
jsonBytes, _ := json.Marshal(v)
|
|
|
|
|
// redisClient.SetRedisTime(7200)
|
|
|
|
|
redisClient.HashSet("deUserAry:wechat_"+global.GVA_CONFIG.RedisPrefix.Alias, "userinfo_"+"_"+v.UserId, string(jsonBytes))
|
|
|
|
|
}
|
|
|
|
|
userInset := commonus.MapOut()
|
|
|
|
|
userInset["userid"] = v.UserId
|
|
|
|
|
userInset["name"] = v.Name
|
|
|
|
|
|
|
|
|
|
jsonDepartment, _ := json.Marshal(v.Department)
|
|
|
|
|
|
|
|
|
|
userInset["department"] = string(jsonDepartment)
|
|
|
|
|
userInset["position"] = v.Position
|
|
|
|
|
userInset["mobile"] = v.Mobile
|
|
|
|
|
userInset["gender"] = v.Gender
|
|
|
|
|
userInset["email"] = v.Email
|
|
|
|
|
userInset["avatar"] = v.Avatar
|
|
|
|
|
userInset["status"] = v.Status
|
|
|
|
|
jsonExtattr, _ := json.Marshal(v.Extattr)
|
|
|
|
|
userInset["extattr"] = string(jsonExtattr)
|
|
|
|
|
userInset["main_department"] = v.MainDepartment
|
|
|
|
|
userInset["qr_code"] = v.QrCode
|
|
|
|
|
jsonIsLeaderInDept, _ := json.Marshal(v.IsLeaderInDept)
|
|
|
|
|
userInset["is_leader_in_dept"] = string(jsonIsLeaderInDept)
|
|
|
|
|
userInset["thumb_avatar"] = v.ThumbAvatar
|
|
|
|
|
userInset["time"] = time.Now().Unix()
|
|
|
|
|
|
|
|
|
|
var userInfoStruct wechat.WechatUsers
|
|
|
|
|
|
|
|
|
|
myErr := global.GVA_DB_WatchDate.Where("userid = ?", v.UserId).First(&userInfoStruct).Error
|
|
|
|
|
if myErr == nil {
|
|
|
|
|
saveErr := global.GVA_DB_WatchDate.Model(&userInfoStruct).Where("userid = ?", v.UserId).Save(userInset).Error
|
|
|
|
|
if saveErr != nil {
|
|
|
|
|
fmt.Printf("%v(%v) 信息更新失败\n", v.Name, v.UserId)
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
userInset["u_id"] = commonus.GetFileNumber()
|
|
|
|
|
createErr := global.GVA_DB_WatchDate.Model(&userInfoStruct).Create(userInset).Error
|
|
|
|
|
if createErr != nil {
|
|
|
|
|
fmt.Printf("%v(%v) 信息写入失败\n", v.Name, v.UserId)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// fmt.Printf("isTrue ====> %v\n", isTrue)
|
|
|
|
|
}
|
|
|
|
|
jsonUserStr, _ := json.Marshal(callBackData.UserList)
|
|
|
|
|
|
|
|
|
|
redisClient.Set("deUserAry:wechat_user_list"+global.GVA_CONFIG.RedisPrefix.Alias+"_"+strconv.Itoa(groupInfo.Id), string(jsonUserStr))
|
|
|
|
|
msg = "获取成功!"
|
|
|
|
|
response.Result(0, callBackData.UserList, msg, c)
|
|
|
|
|
} else {
|
|
|
|
|
var userAry []commonus.UserListStruct
|
|
|
|
|
jsonUserList := json.Unmarshal([]byte(departmentUserList), &userAry)
|
|
|
|
|
if jsonUserList != nil {
|
|
|
|
|
response.Result(102, jsonUserList, "部门人员列表获取错误!", c)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
msges := "获取成功!"
|
|
|
|
|
response.Result(203, userAry, msges, c)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|