go_dreamfactory/modules/sys/api_funcgetList.go
2023-09-19 16:41:41 +08:00

105 lines
2.6 KiB
Go

package sys
import (
"go_dreamfactory/comm"
"go_dreamfactory/lego/core"
"go_dreamfactory/pb"
)
func (this *apiComp) FuncGetListCheck(session comm.IUserSession, req *pb.SysFuncGetListReq) (errdata *pb.ErrorData) {
return
}
func (this *apiComp) FuncGetList(session comm.IUserSession, req *pb.SysFuncGetListReq) (errdata *pb.ErrorData) {
var (
bChange bool
change []string = make([]string, 0)
list *pb.DBOpenCond
)
rsp := &pb.SysFuncGetListResp{}
rsp.Cond = make(map[string]int32, 0)
opencfg, err := this.module.configure.getOpencondCfg()
if err != nil {
errdata = &pb.ErrorData{
Code: pb.ErrorCode_ConfigNoFound,
Message: err.Error(),
}
return
}
if list, err = this.module.modelSys.GetOpenCondList(session.GetUserId()); err != nil {
errdata = &pb.ErrorData{
Code: pb.ErrorCode_DBError,
Title: pb.ErrorCode_DBError.ToString(),
Message: err.Error(),
}
return
}
if len(req.Keys) == 0 {
for _, v := range opencfg.GetDataList() {
if list.Cond[v.Id] == 0 {
id := this.module.modelSys.CheckValidCond(session.GetUserId(), v, list)
if id != "" {
if v.ActivateType == 1 { // 需要手动激活的
list.Cond[id] = 1 //设置激活
} else {
list.Cond[id] = 2 //自动激活
change = append(change, id)
}
bChange = true
}
}
rsp.Cond[v.Id] = list.Cond[v.Id]
}
} else {
for _, key := range req.Keys {
if list.Cond[key] == 0 {
if conf, ok := opencfg.GetDataMap()[key]; ok {
id := this.module.modelSys.CheckValidCond(session.GetUserId(), conf, list)
if id != "" {
if conf.ActivateType == 1 { // 需要手动激活的
list.Cond[id] = 1 //设置激活
} else {
list.Cond[id] = 2 //自动激活
change = append(change, id)
}
bChange = true
}
}
}
rsp.Cond[key] = list.Cond[key]
}
}
if bChange {
this.module.modelSys.ChangeOpenCondData(session.GetUserId(), map[string]interface{}{
"cond": list.Cond,
})
}
session.SendMsg(string(this.module.GetType()), "funcgetlist", rsp)
if len(change) > 0 {
go this.module.AsynHandleSession(session.Clone(), func(session comm.IUserSession) {
this.module.wtask.OpenCmdNotice(session, change...)
//手动激活通知模块
for _, m := range change {
opencfg, _ := this.module.configure.GetOpenCondCfgById(m)
for _, v := range opencfg.Notify {
i, err := this.service.GetModule(core.M_Modules(v))
if err != nil {
this.module.Errorln(err)
continue
}
if ic, ok := i.(comm.IOpenCmdNotice); ok {
ic.OpenCmdNotice(session, m)
}
}
}
})
}
return
}