1 Star 0 Fork 0

tomatomeatman/GolangRepository

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
ControllerUtil.go 44.64 KB
一键复制 编辑 原始数据 按行查看 历史
tomatomeatman 提交于 2025-03-25 18:23 +08:00 . 2
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775
package app
import (
"bytes"
"encoding/json"
"fmt"
"io"
uu "net/url"
"reflect"
"strings"
"time"
"gitee.com/tomatomeatman/golang-repository/bricks2/function/data/timeutil"
"gitee.com/tomatomeatman/golang-repository/bricks2/function/urlutil"
"gitee.com/tomatomeatman/golang-repository/bricks2/model/dbinfo"
"gitee.com/tomatomeatman/golang-repository/bricks2/model/msgentity"
"gitee.com/tomatomeatman/golang-repository/bricks2/model/set"
"gitee.com/tomatomeatman/golang-repository/bricks2/utils/ginutil"
Log "github.com/cihub/seelog"
)
type ControllerUtil struct{}
/**
* 新增
* @param ctx GinHttp上下文对象
* @param control 控制层接口
* @return *msgentity.MsgEntity 返回验证结果
*/
func (controlUtil ControllerUtil) Add(ctx ginutil.Context, control Controller) *msgentity.MsgEntity {
entity, err := control.GetModuleEntity(control) //按模块数据实体创建新实例,并实例化
if err != nil {
return msgentity.Err(9011, err)
}
bl, msg, data := urlutil.GetParams(ctx.Request, entity)
if !bl {
return msgentity.Err(data.(int), msg)
}
ctx.Set("ControllerSimplName", control.SimplName(control))
ctx.Set("Controller", control)
params := data.(map[string]interface{})
service, err := control.GetModuleService(control)
if err != nil {
service = &ServiceBaseFunc{}
}
name := getSimplName(control) + ".Add"
meBefore := AopUtil{}.CallBeforeFunc(name, ctx)
if !meBefore.Success {
return meBefore
}
me := service.Add(ctx, entity, params)
if !me.Success {
return me
}
meAfter := AopUtil{}.CallAfterFunc(name, ctx, me)
if !meAfter.Success {
return meAfter
}
return me
}
/**
* 批量新增
* @param ctx GinHttp上下文对象
* @param control 控制层接口
* @return *msgentity.MsgEntity 返回验证结果
*/
func (controlUtil ControllerUtil) Adds(ctx ginutil.Context, control Controller) *msgentity.MsgEntity {
objStr := urlutil.GetParam(ctx.Request, "objs", "").(string)
if objStr == "" {
return msgentity.Err(9001, "未能获取'objs'参数")
}
var objs []map[string]interface{}
err := json.Unmarshal([]byte(objStr), &objs)
if err != nil {
Log.Error("参数'objs'转换出错:", err)
return msgentity.Err(9002, "参数'objs'转换出错")
}
if len(objs) < 1 {
return msgentity.Err(9003, "参数'objs'转换后没有数据")
}
entity, err := control.GetModuleEntity(control) //按模块数据实体创建新实例,并实例化
if err != nil {
return msgentity.Err(9011, err)
}
ctx.Set("ControllerSimplName", control.SimplName(control))
ctx.Set("Controller", control)
entitys := make([]dbinfo.Entity, len(objs))
for i := 0; i < len(objs); i++ {
entitys = append(entitys, entity.New())
}
service, err := control.GetModuleService(control)
if err != nil {
service = &ServiceBaseFunc{}
}
name := getSimplName(control) + ".Adds"
meBefore := AopUtil{}.CallBeforeFunc(name, ctx)
if !meBefore.Success {
return meBefore
}
me := service.Adds(ctx, entitys, objs)
if !me.Success {
return me
}
meAfter := AopUtil{}.CallAfterFunc(name, ctx, me)
if !meAfter.Success {
return meAfter
}
return me
}
/**
* 新增树节点
* @param ctx GinHttp上下文对象
* @param control 控制层接口
* @return *msgentity.MsgEntity 返回验证结果
*/
func (controlUtil ControllerUtil) AddNode(ctx ginutil.Context, control Controller) *msgentity.MsgEntity {
entity, err := control.GetModuleEntity(control) //按模块数据实体创建新实例,并实例化
if err != nil {
return msgentity.Err(9011, err)
}
bl, msg, data := urlutil.GetParams(ctx.Request, entity)
if !bl {
return msgentity.Err(data.(int), msg)
}
ctx.Set("ControllerSimplName", control.SimplName(control))
ctx.Set("Controller", control)
params := data.(map[string]interface{})
service, err := control.GetModuleService(control)
if err != nil {
service = &ServiceBaseFunc{}
}
name := getSimplName(control) + ".AddNode"
meBefore := AopUtil{}.CallBeforeFunc(name, ctx)
if !meBefore.Success {
return meBefore
}
me := service.AddNode(ctx, entity, params)
if !me.Success {
return me
}
meAfter := AopUtil{}.CallAfterFunc(name, ctx, me)
if !meAfter.Success {
return meAfter
}
return me
}
/**
* 删除
* @param ctx GinHttp上下文对象
* @param control 控制层接口
* @return *msgentity.MsgEntity 返回验证结果
*/
func (controlUtil ControllerUtil) Del(ctx ginutil.Context, control Controller) *msgentity.MsgEntity {
entity, err := control.GetModuleEntity(control) //按模块数据实体创建新实例,并实例化
if err != nil {
return msgentity.Err(9011, err)
}
tableInfo := entity.TableInfo()
ctx.Set("ControllerSimplName", control.SimplName(control))
ctx.Set("Controller", control)
id := urlutil.GetParamToId(ctx.Request, tableInfo.KeyJson) //取请求参数中的记录编号
if id == nil || (fmt.Sprintf("%v", id) == "") {
id = urlutil.GetParamToId(ctx.Request, "id")
if id == nil || (fmt.Sprintf("%v", id) == "") {
return msgentity.Err(9012, "未能获取'", tableInfo.KeyJson, "'参数")
}
}
Edition := urlutil.GetParamToEdition(ctx.Request, tableInfo.HasEdition, dbinfo.TableEdition[1]) //取请求参数中的版本号
service, err := control.GetModuleService(control)
if err != nil {
service = &ServiceBaseFunc{}
}
name := getSimplName(control) + ".Del"
meBefore := AopUtil{}.CallBeforeFunc(name, ctx)
if !meBefore.Success {
return meBefore
}
me := service.Del(ctx, entity, id, Edition)
if !me.Success {
return me
}
meAfter := AopUtil{}.CallAfterFunc(name, ctx, me)
if !meAfter.Success {
return meAfter
}
return me
}
/**
* 修改
* @param ctx GinHttp上下文对象
* @param control 控制层接口
* @return *msgentity.MsgEntity 返回验证结果
*/
func (controlUtil ControllerUtil) Edit(ctx ginutil.Context, control Controller) *msgentity.MsgEntity {
entity, err := control.GetModuleEntity(control) //按模块数据实体创建新实例,并实例化
if err != nil {
return msgentity.Err(9011, err)
}
tableInfo := entity.TableInfo()
id := urlutil.GetParamToId(ctx.Request, tableInfo.KeyJson) //取请求参数中的记录编号
// Edition := urlutil.GetParamToEdition(ctx.Request, dbinfo.EntityHasEdition(entity), dbinfo.TableEdition) //取请求参数中的版本号
bl, msg, da := urlutil.GetParams(ctx.Request, entity)
if !bl {
return msgentity.Err(da.(int), msg)
}
data := da.(map[string]interface{})
if id == nil || (fmt.Sprintf("%v", id) == "") {
id = data[tableInfo.KeyJson]
if id == nil || (fmt.Sprintf("%v", id) == "") {
return msgentity.Err(1001, "未能获取'", tableInfo.KeyJson, "'参数")
}
}
service, err := control.GetModuleService(control)
if err != nil {
service = &ServiceBaseFunc{}
}
name := getSimplName(control) + ".Edit"
ctx.Set("ControllerSimplName", control.SimplName(control))
ctx.Set("Controller", control)
me := AopUtil{}.CallBeforeFunc(name, ctx)
if !me.Success {
return me
}
me = service.Edit(ctx, entity, data)
if !me.Success {
return me
}
meAfter := AopUtil{}.CallAfterFunc(name, ctx, me)
if !meAfter.Success {
return meAfter
}
return me
}
/**
* 保存(有ID则更新,否则新增)
* @param ctx GinHttp上下文对象
* @param control 控制层接口
* @return *msgentity.MsgEntity 返回验证结果
*/
func (controlUtil ControllerUtil) Save(ctx ginutil.Context, control Controller) *msgentity.MsgEntity {
entity, err := control.GetModuleEntity(control) //按模块数据实体创建新实例,并实例化
if err != nil {
return msgentity.Err(9011, err)
}
bl, msg, da := urlutil.GetParams(ctx.Request, entity)
if !bl {
return msgentity.Err(da.(int), msg)
}
data := da.(map[string]interface{})
service, err := control.GetModuleService(control)
if err != nil {
service = &ServiceBaseFunc{}
}
name := getSimplName(control) + ".Save"
ctx.Set("ControllerSimplName", control.SimplName(control))
ctx.Set("Controller", control)
me := AopUtil{}.CallBeforeFunc(name, ctx)
if !me.Success {
return me
}
me = service.Save(ctx, entity, data)
if !me.Success {
return me
}
meAfter := AopUtil{}.CallAfterFunc(name, ctx, me)
if !meAfter.Success {
return meAfter
}
return me
}
/**
* 批量修改
* @param ctx GinHttp上下文对象
* @param control 控制层接口
* @param transactional 启用事务
* @return *msgentity.MsgEntity 返回验证结果
*/
func (controlUtil ControllerUtil) Edits(ctx ginutil.Context, control Controller, transactional bool) *msgentity.MsgEntity {
entity, err := control.GetModuleEntity(control) //按模块数据实体创建新实例,并实例化
if err != nil {
return msgentity.Err(9011, err)
}
bl, msg, data := urlutil.GetParams(ctx.Request, entity)
if !bl {
return msgentity.Err(data.(int), msg)
}
datas := data.([]map[string]interface{})
service, err := control.GetModuleService(control)
if err != nil {
service = &ServiceBaseFunc{}
}
name := getSimplName(control) + ".Edits"
ctx.Set("ControllerSimplName", control.SimplName(control))
ctx.Set("Controller", control)
me := AopUtil{}.CallBeforeFunc(name, ctx)
if !me.Success {
return me
}
me = service.Edits(ctx, entity, datas, transactional)
if !me.Success {
return me
}
meAfter := AopUtil{}.CallAfterFunc(name, ctx, me)
if !meAfter.Success {
return meAfter
}
return me
}
/**
* 批量保存
* @param ctx GinHttp上下文对象
* @param control 控制层接口
* @param transactional 启用事务
* @return *msgentity.MsgEntity 返回验证结果
*/
func (controlUtil ControllerUtil) Saves(ctx ginutil.Context, control Controller, transactional bool) *msgentity.MsgEntity {
entity, err := control.GetModuleEntity(control) //按模块数据实体创建新实例,并实例化
if err != nil {
return msgentity.Err(9011, err)
}
bl, msg, data := urlutil.GetParams(ctx.Request, entity)
if !bl {
return msgentity.Err(data.(int), msg)
}
datas := data.([]map[string]interface{})
service, err := control.GetModuleService(control)
if err != nil {
service = &ServiceBaseFunc{}
}
name := getSimplName(control) + ".Saves"
ctx.Set("ControllerSimplName", control.SimplName(control))
ctx.Set("Controller", control)
me := AopUtil{}.CallBeforeFunc(name, ctx)
if !me.Success {
return me
}
me = service.Saves(ctx, entity, datas, transactional)
if !me.Success {
return me
}
meAfter := AopUtil{}.CallAfterFunc(name, ctx, me)
if !meAfter.Success {
return meAfter
}
return me
}
/**
* 批量操作
* @param ctx GinHttp上下文对象
* @param control 控制层接口
* @param transactional 启用事务
* @return *msgentity.MsgEntity 返回验证结果
*/
func (controlUtil ControllerUtil) SaveList(ctx ginutil.Context, control Controller, transactional bool) *msgentity.MsgEntity {
entity, err := control.GetModuleEntity(control) //按模块数据实体创建新实例,并实例化
if err != nil {
return msgentity.Err(9011, err)
}
bl, msg, da := urlutil.GetParams(ctx.Request, entity)
if !bl {
return msgentity.Err(da.(int), msg)
}
data := da.(map[string]interface{})
addList := []map[string]interface{}{}
editList := []map[string]interface{}{}
delList := []map[string]interface{}{}
if temp, ok := data["addList"]; ok {
addList = temp.([]map[string]interface{})
}
if temp, ok := data["editList"]; ok {
editList = temp.([]map[string]interface{})
}
if temp, ok := data["delList"]; ok {
delList = temp.([]map[string]interface{})
}
service, err := control.GetModuleService(control)
if err != nil {
service = &ServiceBaseFunc{}
}
name := getSimplName(control) + ".SaveList"
ctx.Set("ControllerSimplName", control.SimplName(control))
ctx.Set("Controller", control)
me := AopUtil{}.CallBeforeFunc(name, ctx)
if !me.Success {
return me
}
me = service.SaveList(ctx, entity, addList, editList, delList, transactional)
if !me.Success {
return me
}
meAfter := AopUtil{}.CallAfterFunc(name, ctx, me)
if !meAfter.Success {
return meAfter
}
return me
}
/**
* 根据主键查询数据
* @param ctx GinHttp上下文对象
* @param control 控制层接口
*/
func (controlUtil ControllerUtil) FindById(ctx ginutil.Context, control Controller) *msgentity.MsgEntity {
entity, err := control.GetModuleEntity(control) //按模块数据实体创建新实例,并实例化
if err != nil {
return msgentity.Err(9011, err)
}
tableInfo := entity.TableInfo()
id := urlutil.GetParamToId(ctx.Request, tableInfo.KeyJson) //取请求参数中的记录编号
if (id == nil) || (fmt.Sprintf("%v", id) == "") {
id = urlutil.GetParamToId(ctx.Request, "id")
}
if id == nil || (fmt.Sprintf("%v", id) == "") {
return msgentity.Err(1001, "记录编号为空")
}
service, err := control.GetModuleService(control)
if err != nil {
service = &ServiceBaseFunc{}
}
name := getSimplName(control) + ".FindById"
ctx.Set("ControllerSimplName", control.SimplName(control))
ctx.Set("Controller", control)
meBefore := AopUtil{}.CallBeforeFunc(name, ctx)
if !meBefore.Success {
return meBefore
}
me := service.FindById(ctx, entity, id)
if !me.Success {
return me
}
meAfter := AopUtil{}.CallAfterFunc(name, ctx, me)
if !meAfter.Success {
return meAfter
}
return me
}
/**
* 查询所有数据
* @param ctx GinHttp上下文对象
* @param control 控制层接口
* @return *msgentity.MsgEntity 返回验证结果
*/
func (controlUtil ControllerUtil) FindAll(ctx ginutil.Context, control Controller, attachWhere ...set.Set) *msgentity.MsgEntity {
whereInfo := []dbinfo.WhereInfo{}
if len(attachWhere) > 0 {
for i := 0; i < len(attachWhere); i++ {
whereInfo = append(whereInfo, dbinfo.WhereInfo{Name: attachWhere[i].Key, Value: attachWhere[i].Value})
}
}
entity, err := control.GetModuleEntity(control) //按模块数据实体创建新实例,并实例化
if err != nil {
return msgentity.Err(9011, err)
}
service, err := control.GetModuleService(control)
if err != nil {
service = &ServiceBaseFunc{}
}
name := getSimplName(control) + ".FindAll"
ctx.Set("ControllerSimplName", control.SimplName(control))
ctx.Set("Controller", control)
meBefore := AopUtil{}.CallBeforeFunc(name, ctx)
if !meBefore.Success {
return meBefore
}
me := service.FindAll(ctx, entity, whereInfo)
if !me.Success {
return me
}
meAfter := AopUtil{}.CallAfterFunc(name, ctx, me)
if !meAfter.Success {
return meAfter
}
return me
}
/**
* 查询时间范围内数据
* @param ctx GinHttp上下文对象
* @param control 控制层接口
* @return *msgentity.MsgEntity 返回验证结果
*/
func (controlUtil ControllerUtil) FindByDate(ctx ginutil.Context, control Controller) *msgentity.MsgEntity {
dateSt := urlutil.GetParam(ctx.Request, "dateSt", "").(string) //记录开始时间
dateEd := urlutil.GetParam(ctx.Request, "dateEd", "").(string) //记录结束时间
entity, err := control.GetModuleEntity(control) //按模块数据实体创建新实例,并实例化
if err != nil {
return msgentity.Err(9011, err)
}
service, err := control.GetModuleService(control)
if err != nil {
service = &ServiceBaseFunc{}
}
name := getSimplName(control) + ".FindByDate"
ctx.Set("ControllerSimplName", control.SimplName(control))
ctx.Set("Controller", control)
meBefore := AopUtil{}.CallBeforeFunc(name, ctx)
if !meBefore.Success {
return meBefore
}
me := service.FindByDate(ctx, entity, dateSt, dateEd)
if !me.Success {
return me
}
meAfter := AopUtil{}.CallAfterFunc(name, ctx, me)
if !meAfter.Success {
return meAfter
}
return me
}
/**
* 查找指定行数据
* @param ctx GinHttp上下文对象
* @param control 控制层接口
* @return *msgentity.MsgEntity 返回验证结果
*/
func (controlUtil ControllerUtil) FindByRow(ctx ginutil.Context, control Controller) *msgentity.MsgEntity {
entity, err := control.GetModuleEntity(control) //按模块数据实体创建新实例,并实例化
if err != nil {
return msgentity.Err(9011, err)
}
tableInfo := entity.TableInfo()
id := urlutil.GetParamToId(ctx.Request, tableInfo.KeyJson) //取请求参数中的记录编号
if id == nil || (fmt.Sprintf("%v", id) == "") {
id = urlutil.GetParamToId(ctx.Request, "id")
if id == nil || (fmt.Sprintf("%v", id) == "") {
return msgentity.Err(1001, "未能获取'", tableInfo.KeyJson, "'参数")
}
}
service, err := control.GetModuleService(control)
if err != nil {
service = &ServiceBaseFunc{}
}
name := getSimplName(control) + ".FindByRow"
ctx.Set("ControllerSimplName", control.SimplName(control))
ctx.Set("Controller", control)
meBefore := AopUtil{}.CallBeforeFunc(name, ctx)
if !meBefore.Success {
return meBefore
}
me := service.FindByRow(ctx, entity, id)
if !me.Success {
return me
}
meAfter := AopUtil{}.CallAfterFunc(name, ctx, me)
if !meAfter.Success {
return meAfter
}
return me
}
/**
* 查询分页数据
* @param ctx GinHttp上下文对象
* @param control 控制层接口
* @param injectionCondition 注入条件
* @return *msgentity.MsgEntity 返回验证结果
*/
func (controlUtil ControllerUtil) FindByPage(ctx ginutil.Context, control Controller, injectionCondition ...set.Set) *msgentity.MsgEntity {
var findByPageParam dbinfo.FindByPageParam
if err := ctx.ShouldBind(&findByPageParam); err != nil {
return msgentity.Err(9101, "请求参数错误", err.Error())
}
if findByPageParam.Page.Size < 1 {
findByPageParam.Page.Size = 10
}
if findByPageParam.Page.Current < 1 {
findByPageParam.Page.Current = 1
}
if (injectionCondition != nil) || (len(injectionCondition) > 0) { //将注入条件覆盖到查询条件
if findByPageParam.Condition == nil {
findByPageParam.Condition = map[string]interface{}{}
}
for _, set := range injectionCondition {
findByPageParam.Condition.(map[string]interface{})[set.Key] = set.Value
}
}
LikeStr := strings.TrimSpace(findByPageParam.LikeStr) //全文检索条件
if LikeStr != "" { //存在全文检索条件则需要考虑时间范围的问题
sLikeDateSt := strings.TrimSpace(findByPageParam.LikeDateSt) //模糊查询记录修改时间范围条件-开始
sLikeDateEd := strings.TrimSpace(findByPageParam.LikeDateEd) //模糊查询记录修改时间范围条件-结束
var dLikeDateEd time.Time
if sLikeDateEd == "" { //如果结束时间为空,则当前时间就是结束时间
dLikeDateEd = time.Now()
sLikeDateEd = dLikeDateEd.Format("2006-01-02 15:04:05")
} else {
dLikeDateEd = timeutil.ToDate(sLikeDateEd)
}
if sLikeDateSt == "" { //如果开始时间为空,则用结束时间-时间限制
iLikeTimeLimit := control.LikeTimeLimit()
sLikeDateSt = timeutil.AddDay(dLikeDateEd, -iLikeTimeLimit).Format("2006-01-02 15:04:05")
}
findByPageParam.LikeDateSt = sLikeDateSt
findByPageParam.LikeDateEd = sLikeDateEd
}
entity, err := control.GetModuleEntity(control) //按模块数据实体创建新实例,并实例化
if err != nil {
return msgentity.Err(9011, err)
}
service, err := control.GetModuleService(control)
if err != nil {
service = &ServiceBaseFunc{}
}
name := getSimplName(control) + ".FindByPage"
ctx.Set("ControllerSimplName", control.SimplName(control))
ctx.Set("Controller", control)
meBefore := AopUtil{}.CallBeforeFunc(name, ctx)
if !meBefore.Success {
return meBefore
}
me := service.FindByPage(ctx, entity, findByPageParam)
if !me.Success {
return me
}
meAfter := AopUtil{}.CallAfterFunc(name, ctx, me)
if !meAfter.Success {
return meAfter
}
return me
}
/**
* 取所有参数,并转换成对应实体属性类型(map[string]interface{})
* @param ctx GinHttp上下文对象
* @param control 控制层接口
* @return *msgentity.MsgEntity 返回验证结果
*/
func (controlUtil ControllerUtil) GetParams(ctx ginutil.Context, entity interface{}) *msgentity.MsgEntity {
if reflect.TypeOf(entity).Kind() == reflect.Struct {
br, _ := io.ReadAll(ctx.Request.Body)
ctx.Request.Body.Close()
ctx.Request.Body = io.NopCloser(bytes.NewBuffer(br))
json.NewDecoder(bytes.NewBuffer(br)).Decode(entity)
// fmt.Println(reflect.TypeOf(entity).String()) // map[string]interface {}
return msgentity.Success(entity, "转换结束")
}
bl, msg, data := urlutil.GetParams(ctx.Request, entity)
return msgentity.Create(bl, msg, data)
}
/**
* 读取树形结构数据
* @param ctx GinHttp上下文对象
* @param control 控制层接口
* @return *msgentity.MsgEntity 返回验证结果
*/
func (controlUtil ControllerUtil) FindByTree(ctx ginutil.Context, control Controller) *msgentity.MsgEntity {
groupColumn := urlutil.GetParam(ctx.Request, "groupColumn", "").(string)
groupName := urlutil.GetParam(ctx.Request, "groupName", "").(string)
entity, err := control.GetModuleEntity(control) //按模块数据实体创建新实例,并实例化
if err != nil {
return msgentity.Err(9011, err)
}
service, err := control.GetModuleService(control)
if err != nil {
service = &ServiceBaseFunc{}
}
name := getSimplName(control) + ".FindByTree"
ctx.Set("ControllerSimplName", control.SimplName(control))
ctx.Set("Controller", control)
meBefore := AopUtil{}.CallBeforeFunc(name, ctx)
if !meBefore.Success {
return meBefore
}
me := service.FindByTree(ctx, entity, groupColumn, groupName)
if !me.Success {
return me
}
meAfter := AopUtil{}.CallAfterFunc(name, ctx, me)
if !meAfter.Success {
return meAfter
}
return me
}
/**
* 根据字段名取指定记录编号的数据库表中对应字段的值
* @param ctx GinHttp上下文对象
* @param control 控制层接口
* @return *msgentity.MsgEntity 返回验证结果
*/
func (controlUtil ControllerUtil) GetValueByFieldName(ctx ginutil.Context, control Controller) *msgentity.MsgEntity {
temp := urlutil.GetParam(ctx.Request, "fieldNames", "").(string)
fieldNames := strings.Split(temp, ",")
entity, err := control.GetModuleEntity(control) //按模块数据实体创建新实例,并实例化
if err != nil {
return msgentity.Err(9011, err)
}
tableInfo := entity.TableInfo()
id := urlutil.GetParamToId(ctx.Request, tableInfo.KeyJson) //取请求参数中的记录编号
if id == nil || (fmt.Sprintf("%v", id) == "") {
id = urlutil.GetParamToId(ctx.Request, "id")
}
service, err := control.GetModuleService(control)
if err != nil {
service = &ServiceBaseFunc{}
}
name := getSimplName(control) + ".GetValueByFieldName"
ctx.Set("ControllerSimplName", control.SimplName(control))
ctx.Set("Controller", control)
meBefore := AopUtil{}.CallBeforeFunc(name, ctx)
if !meBefore.Success {
return meBefore
}
me := service.GetValueByFieldName(ctx, entity, id, fieldNames)
if !me.Success {
return me
}
meAfter := AopUtil{}.CallAfterFunc(name, ctx, me)
if !meAfter.Success {
return meAfter
}
return me
}
/**
* 根据字段名取指定记录编号的数据库表中对应字段的值
* @param ctx GinHttp上下文对象
* @param control 控制层接口
* @return *msgentity.MsgEntity 返回验证结果
*/
func (controlUtil ControllerUtil) GetValueByField(ctx ginutil.Context, control Controller) *msgentity.MsgEntity {
entity, err := control.GetModuleEntity(control) //按模块数据实体创建新实例,并实例化
if err != nil {
return msgentity.Err(9011, err)
}
tableInfo := entity.TableInfo()
id := urlutil.GetParamToId(ctx.Request, tableInfo.KeyJson) //取请求参数中的记录编号
if id == nil || (fmt.Sprintf("%v", id) == "") {
id = urlutil.GetParamToId(ctx.Request, "id")
if id == nil || (fmt.Sprintf("%v", id) == "") {
return msgentity.Err(9012, "未能获取'", tableInfo.KeyJson, "'参数")
}
}
fieldName := urlutil.GetParam(ctx.Request, "fieldName", "").(string)
service, err := control.GetModuleService(control)
if err != nil {
service = &ServiceBaseFunc{}
}
name := getSimplName(control) + ".GetValueByField"
ctx.Set("ControllerSimplName", control.SimplName(control))
ctx.Set("Controller", control)
meBefore := AopUtil{}.CallBeforeFunc(name, ctx)
if !meBefore.Success {
return meBefore
}
me := service.GetValueByField(ctx, entity, id, fieldName)
if !me.Success {
return me
}
meAfter := AopUtil{}.CallAfterFunc(name, ctx, me)
if !meAfter.Success {
return meAfter
}
return me
}
/**
* 根据关键值取对象集合
* @param ctx GinHttp上下文对象
* @param control 控制层接口
* @return *msgentity.MsgEntity 返回验证结果
*/
func (controlUtil ControllerUtil) FindByKey(ctx ginutil.Context, control Controller) *msgentity.MsgEntity {
entity, err := control.GetModuleEntity(control) //按模块数据实体创建新实例,并实例化
if err != nil {
return msgentity.Err(9011, err)
}
bl, msg, da := urlutil.GetParams(ctx.Request, entity)
if !bl {
return msgentity.Err(da.(int), msg)
}
params := da.(map[string]interface{})
whereInfo := []dbinfo.WhereInfo{}
for k, v := range params {
info := dbinfo.WhereInfo{Name: k, Value: v}
whereInfo = append(whereInfo, info)
}
service, err := control.GetModuleService(control)
if err != nil {
service = &ServiceBaseFunc{}
}
name := getSimplName(control) + ".FindByKey"
ctx.Set("ControllerSimplName", control.SimplName(control))
ctx.Set("Controller", control)
meBefore := AopUtil{}.CallBeforeFunc(name, ctx)
if !meBefore.Success {
return meBefore
}
me := service.FindByKey(ctx, entity, whereInfo)
if !me.Success {
return me
}
meAfter := AopUtil{}.CallAfterFunc(name, ctx, me)
if !meAfter.Success {
return meAfter
}
return me
}
/**
* 根据关键值取对象集合中的第一个
* @param ctx GinHttp上下文对象
* @param control 控制层接口
* @return *msgentity.MsgEntity 返回验证结果
*/
func (controlUtil ControllerUtil) FindOneByKey(ctx ginutil.Context, control Controller) *msgentity.MsgEntity {
temp := urlutil.GetParam(ctx.Request, "fields", "").(string)
fields := strings.Split(temp, ",")
entity, err := control.GetModuleEntity(control) //按模块数据实体创建新实例,并实例化
if err != nil {
return msgentity.Err(9011, err)
}
bl, msg, da := urlutil.GetParams(ctx.Request, entity)
if !bl {
return msgentity.Err(da.(int), msg)
}
params := da.(map[string]interface{})
whereInfo := []dbinfo.WhereInfo{}
for k, v := range params {
info := dbinfo.WhereInfo{Name: k, Value: v}
whereInfo = append(whereInfo, info)
}
service, err := control.GetModuleService(control)
if err != nil {
service = &ServiceBaseFunc{}
}
name := getSimplName(control) + ".FindOneByKey"
ctx.Set("ControllerSimplName", control.SimplName(control))
ctx.Set("Controller", control)
meBefore := AopUtil{}.CallBeforeFunc(name, ctx)
if !meBefore.Success {
return meBefore
}
me := service.FindOneByKey(ctx, entity, whereInfo, fields...)
if !me.Success {
return me
}
meAfter := AopUtil{}.CallAfterFunc(name, ctx, me)
if !meAfter.Success {
return meAfter
}
return me
}
/**
* 根据关键值取对象集合中的符合条件的第一条记录的指定字段
* @param ctx GinHttp上下文对象
* @param control 控制层接口
* @return *msgentity.MsgEntity 返回验证结果
*/
func (controlUtil ControllerUtil) FindValueByKey(ctx ginutil.Context, control Controller) *msgentity.MsgEntity {
entity, err := control.GetModuleEntity(control) //按模块数据实体创建新实例,并实例化
if err != nil {
return msgentity.Err(9011, err)
}
bl, msg, da := urlutil.GetParams(ctx.Request, entity)
if !bl {
return msgentity.Err(da.(int), msg)
}
params := da.(map[string]interface{})
whereInfo := []dbinfo.WhereInfo{}
for k, v := range params {
info := dbinfo.WhereInfo{Name: k, Value: v}
whereInfo = append(whereInfo, info)
}
fieldName := urlutil.GetParam(ctx.Request, "fieldName", "").(string)
service, err := control.GetModuleService(control)
if err != nil {
service = &ServiceBaseFunc{}
}
name := getSimplName(control) + ".FindValueByKey"
ctx.Set("ControllerSimplName", control.SimplName(control))
ctx.Set("Controller", control)
meBefore := AopUtil{}.CallBeforeFunc(name, ctx)
if !meBefore.Success {
return meBefore
}
me := service.FindValueByKey(ctx, entity, whereInfo, fieldName)
if !me.Success {
return me
}
meAfter := AopUtil{}.CallAfterFunc(name, ctx, me)
if !meAfter.Success {
return meAfter
}
return me
}
/**
* 根据关键值查数量
* @param ctx GinHttp上下文对象
* @param control 控制层接口
* @return *msgentity.MsgEntity 返回验证结果
*/
func (controlUtil ControllerUtil) FindCountByKey(ctx ginutil.Context, control Controller) *msgentity.MsgEntity {
entity, err := control.GetModuleEntity(control) //按模块数据实体创建新实例,并实例化
if err != nil {
return msgentity.Err(9011, err)
}
bl, msg, da := urlutil.GetParams(ctx.Request, entity)
if !bl {
return msgentity.Err(da.(int), msg)
}
params := da.(map[string]interface{})
whereInfo := []dbinfo.WhereInfo{}
for k, v := range params {
info := dbinfo.WhereInfo{Name: k, Value: v}
whereInfo = append(whereInfo, info)
}
service, err := control.GetModuleService(control)
if err != nil {
service = &ServiceBaseFunc{}
}
name := getSimplName(control) + ".FindCountByKey"
ctx.Set("ControllerSimplName", control.SimplName(control))
ctx.Set("Controller", control)
meBefore := AopUtil{}.CallBeforeFunc(name, ctx)
if !meBefore.Success {
return meBefore
}
me := service.FindCountByKey(ctx, entity, whereInfo)
if !me.Success {
return me
}
meAfter := AopUtil{}.CallAfterFunc(name, ctx, me)
if !meAfter.Success {
return meAfter
}
return me
}
/**
* 根据字段名取分组数据
* @param ctx GinHttp上下文对象
* @param control 控制层接口
* @param fields 分组字段[字段名,字段别名]
* @return *msgentity.MsgEntity 返回验证结果
*/
func (controlUtil ControllerUtil) Group(ctx ginutil.Context, control Controller, fields map[string]string) *msgentity.MsgEntity {
entity, err := control.GetModuleEntity(control) //按模块数据实体创建新实例,并实例化
if err != nil {
return msgentity.Err(9011, err)
}
service, err := control.GetModuleService(control)
if err != nil {
service = &ServiceBaseFunc{}
}
name := getSimplName(control) + ".GroupByField"
ctx.Set("ControllerSimplName", control.SimplName(control))
ctx.Set("Controller", control)
meBefore := AopUtil{}.CallBeforeFunc(name, ctx)
if !meBefore.Success {
return meBefore
}
me := service.GroupByField(ctx, entity, "", fields)
if !me.Success {
return me
}
meAfter := AopUtil{}.CallAfterFunc(name, ctx, me)
if !meAfter.Success {
return meAfter
}
return me
}
/**
* 根据字段名取分组数据且取数量
* @param ctx GinHttp上下文对象
* @param control 控制层接口
* @param fields 分组字段[字段名,字段别名]
* @return *msgentity.MsgEntity 返回验证结果
*/
func (controlUtil ControllerUtil) GroupAndCount(ctx ginutil.Context, control Controller, fields map[string]string) *msgentity.MsgEntity {
entity, err := control.GetModuleEntity(control) //按模块数据实体创建新实例,并实例化
if err != nil {
return msgentity.Err(9011, err)
}
service, err := control.GetModuleService(control)
if err != nil {
service = &ServiceBaseFunc{}
}
name := getSimplName(control) + ".GroupByFieldAndCount"
ctx.Set("ControllerSimplName", control.SimplName(control))
ctx.Set("Controller", control)
meBefore := AopUtil{}.CallBeforeFunc(name, ctx)
if !meBefore.Success {
return meBefore
}
me := service.GroupByFieldAndCount(ctx, entity, "", fields)
if !me.Success {
return me
}
meAfter := AopUtil{}.CallAfterFunc(name, ctx, me)
if !meAfter.Success {
return meAfter
}
return me
}
/**
* 根据字段名取分组数据
* @param ctx GinHttp上下文对象
* @param control 控制层接口
* @return *msgentity.MsgEntity 返回验证结果
*/
func (controlUtil ControllerUtil) GroupByField(ctx ginutil.Context, control Controller) *msgentity.MsgEntity {
entity, err := control.GetModuleEntity(control) //按模块数据实体创建新实例,并实例化
if err != nil {
return msgentity.Err(9011, err)
}
bl, msg, da := urlutil.GetParams(ctx.Request, entity)
if !bl {
return msgentity.Err(da.(int), msg)
}
fieldsTemp := da.(map[string]interface{})
fields := make(map[string]string)
for k, v := range fieldsTemp {
fields[k] = fmt.Sprintf("%v", v)
}
service, err := control.GetModuleService(control)
if err != nil {
service = &ServiceBaseFunc{}
}
name := getSimplName(control) + ".GroupByField"
ctx.Set("ControllerSimplName", control.SimplName(control))
ctx.Set("Controller", control)
meBefore := AopUtil{}.CallBeforeFunc(name, ctx)
if !meBefore.Success {
return meBefore
}
me := service.GroupByField(ctx, entity, "", fields)
if !me.Success {
return me
}
meAfter := AopUtil{}.CallAfterFunc(name, ctx, me)
if !meAfter.Success {
return meAfter
}
return me
}
/**
* 取表中指定字段的最大值
* @param ctx GinHttp上下文对象
* @param control 控制层接口
* @return *msgentity.MsgEntity 返回验证结果
*/
func (controlUtil ControllerUtil) MaxByField(ctx ginutil.Context, control Controller) *msgentity.MsgEntity {
entity, err := control.GetModuleEntity(control) //按模块数据实体创建新实例,并实例化
if err != nil {
return msgentity.Err(9011, err)
}
bl, msg, da := urlutil.GetParams(ctx.Request, entity)
if !bl {
return msgentity.Err(da.(int), msg)
}
field := urlutil.GetParam(ctx.Request, "field", "").(string)
if field == "" {
return msgentity.Err(9012, "field参数为空")
}
params := da.(map[string]interface{})
whereInfo := []dbinfo.WhereInfo{}
for k, v := range params {
info := dbinfo.WhereInfo{Name: k, Value: v}
whereInfo = append(whereInfo, info)
}
service, err := control.GetModuleService(control)
if err != nil {
service = &ServiceBaseFunc{}
}
name := getSimplName(control) + ".MaxByField"
ctx.Set("ControllerSimplName", control.SimplName(control))
ctx.Set("Controller", control)
meBefore := AopUtil{}.CallBeforeFunc(name, ctx)
if !meBefore.Success {
return meBefore
}
me := service.MaxByField(ctx, entity, "", field, whereInfo)
if !me.Success {
return me
}
meAfter := AopUtil{}.CallAfterFunc(name, ctx, me)
if !meAfter.Success {
return meAfter
}
return me
}
/**
* 取表中指定字段的最小值
* @param ctx GinHttp上下文对象
* @param control 控制层接口
* @return *msgentity.MsgEntity 返回验证结果
*/
func (controlUtil ControllerUtil) MinByField(ctx ginutil.Context, control Controller) *msgentity.MsgEntity {
field := urlutil.GetParam(ctx.Request, "field", "").(string)
if field == "" {
return msgentity.Err(9012, "field参数为空")
}
entity, err := control.GetModuleEntity(control) //按模块数据实体创建新实例,并实例化
if err != nil {
return msgentity.Err(9011, err)
}
bl, msg, da := urlutil.GetParams(ctx.Request, entity)
if !bl {
return msgentity.Err(da.(int), msg)
}
params := da.(map[string]interface{})
whereInfo := []dbinfo.WhereInfo{}
for k, v := range params {
info := dbinfo.WhereInfo{Name: k, Value: v}
whereInfo = append(whereInfo, info)
}
service, err := control.GetModuleService(control)
if err != nil {
service = &ServiceBaseFunc{}
}
name := getSimplName(control) + ".MinByField"
ctx.Set("ControllerSimplName", control.SimplName(control))
ctx.Set("Controller", control)
meBefore := AopUtil{}.CallBeforeFunc(name, ctx)
if !meBefore.Success {
return meBefore
}
me := service.MinByField(ctx, entity, "", field, whereInfo)
if !me.Success {
return me
}
meAfter := AopUtil{}.CallAfterFunc(name, ctx, me)
if !meAfter.Success {
return meAfter
}
return me
}
/**
* 取表中指定字段的最小值
* @param ctx GinHttp上下文对象
* @param control 控制层接口
* @return *msgentity.MsgEntity 返回验证结果
*/
func (controlUtil ControllerUtil) HasById(ctx ginutil.Context, control Controller) *msgentity.MsgEntity {
entity, err := control.GetModuleEntity(control) //按模块数据实体创建新实例,并实例化
if err != nil {
return msgentity.Err(9011, err)
}
tableInfo := entity.TableInfo()
id := urlutil.GetParamToId(ctx.Request, tableInfo.KeyJson) //取请求参数中的记录编号
if id == nil || (fmt.Sprintf("%v", id) == "") {
id = urlutil.GetParamToId(ctx.Request, "id")
if id == nil || (fmt.Sprintf("%v", id) == "") {
return msgentity.Err(1001, "未能获取'", tableInfo.KeyJson, "'参数")
}
}
service, err := control.GetModuleService(control)
if err != nil {
service = &ServiceBaseFunc{}
}
name := getSimplName(control) + ".HasById"
ctx.Set("ControllerSimplName", control.SimplName(control))
ctx.Set("Controller", control)
meBefore := AopUtil{}.CallBeforeFunc(name, ctx)
if !meBefore.Success {
return meBefore
}
me := service.HasById(ctx, entity, id)
if !me.Success {
return me
}
meAfter := AopUtil{}.CallAfterFunc(name, ctx, me)
if !meAfter.Success {
return meAfter
}
return me
}
/**
* 检查关键值记录是否存在(返回1:存在;0:不存在)
* @param ctx GinHttp上下文对象
* @param control 控制层接口
* @return *msgentity.MsgEntity 返回验证结果
*/
func (controlUtil ControllerUtil) HasByKey(ctx ginutil.Context, control Controller) *msgentity.MsgEntity {
keyName := urlutil.GetParam(ctx.Request, "keyName", "") //取请求参数中的字段名
keyValue := urlutil.GetParam(ctx.Request, "keyValue", "") //取请求参数中的字段值
if keyName == "" {
return msgentity.Err(9001, "keyName参数为空")
}
entity, err := control.GetModuleEntity(control) //按模块数据实体创建新实例,并实例化
if err != nil {
return msgentity.Err(9011, err)
}
service, err := control.GetModuleService(control)
if err != nil {
service = &ServiceBaseFunc{}
}
name := getSimplName(control) + ".HasByKey"
ctx.Set("ControllerSimplName", control.SimplName(control))
ctx.Set("Controller", control)
meBefore := AopUtil{}.CallBeforeFunc(name, ctx)
if !meBefore.Success {
return meBefore
}
me := service.HasByKey(ctx, entity, keyName.(string), keyValue)
if !me.Success {
return me
}
meAfter := AopUtil{}.CallAfterFunc(name, ctx, me)
if !meAfter.Success {
return meAfter
}
return me
}
/**
* 清理指定用户的缓存
* @param ctx GinHttp上下文对象
* @param control 控制层接口
* @return *msgentity.MsgEntity 返回验证结果
*/
func (controlUtil ControllerUtil) ClearCache(ctx ginutil.Context, control Controller) *msgentity.MsgEntity {
user := urlutil.GetParam(ctx.Request, "user", "").(string) //取请求参数中的用户名
cacheName := urlutil.GetParam(ctx.Request, "cacheName", "").(string) //取请求参数中的缓存名
service, err := control.GetModuleService(control)
if err != nil {
service = &ServiceBaseFunc{}
}
name := getSimplName(control) + ".ClearCache"
ctx.Set("ControllerSimplName", control.SimplName(control))
ctx.Set("Controller", control)
meBefore := AopUtil{}.CallBeforeFunc(name, ctx)
if !meBefore.Success {
return meBefore
}
me := service.ClearCache(ctx, cacheName, user)
if !me.Success {
return me
}
meAfter := AopUtil{}.CallAfterFunc(name, ctx, me)
if !meAfter.Success {
return meAfter
}
return me
}
/**
* 查询组结构数据
* @param ctx GinHttp上下文对象
* @param control 控制层接口
* @return *msgentity.MsgEntity 返回验证结果
*/
func (controlUtil ControllerUtil) FindByGroup(ctx ginutil.Context, control Controller) *msgentity.MsgEntity {
groupColumn := urlutil.GetParam(ctx.Request, "groupColumn", "").(string) //分组名(树节点)所在字段名
groupName := urlutil.GetParam(ctx.Request, "groupName", "").(string) //分组名(树节点)
if groupName == "" {
return controlUtil.FindByTree(ctx, control)
}
entity, err := control.GetModuleEntity(control) //按模块数据实体创建新实例,并实例化
if err != nil {
return msgentity.Err(9011, err)
}
service, err := control.GetModuleService(control)
if err != nil {
service = &ServiceBaseFunc{}
}
name := getSimplName(control) + ".FindByGroup"
ctx.Set("ControllerSimplName", control.SimplName(control))
ctx.Set("Controller", control)
meBefore := AopUtil{}.CallBeforeFunc(name, ctx)
if !meBefore.Success {
return meBefore
}
me := service.FindByGroup(ctx, entity, groupColumn, groupName)
if !me.Success {
return me
}
meAfter := AopUtil{}.CallAfterFunc(name, ctx, me)
if !meAfter.Success {
return meAfter
}
return me
}
/**
* 添加数据到指定组下
* 警告:对象必须符合树形结构要求,如:Id、Pid
* @param ctx GinHttp上下文对象
* @param control 控制层接口
* @return *msgentity.MsgEntity 返回验证结果
*/
func (controlUtil ControllerUtil) AddToGroup(ctx ginutil.Context, control Controller) *msgentity.MsgEntity {
groupName := urlutil.GetParam(ctx.Request, "groupName", "").(string) //分组字段名称(树节点)
groupValue := urlutil.GetParam(ctx.Request, "groupValue", "").(string) //分组字段值(树节点)
entity, err := control.GetModuleEntity(control) //按模块数据实体创建新实例,并实例化
if err != nil {
return msgentity.Err(9001, "控制层未设置ModuleEntit:", err)
}
service, err := control.GetModuleService(control)
if err != nil {
service = &ServiceBaseFunc{}
}
name := getSimplName(control) + ".AddToGroup"
ctx.Set("ControllerSimplName", control.SimplName(control))
ctx.Set("Controller", control)
meBefore := AopUtil{}.CallBeforeFunc(name, ctx)
if !meBefore.Success {
return meBefore
}
me := service.AddToGroup(ctx, entity, groupName, groupValue)
if !me.Success {
return me
}
meAfter := AopUtil{}.CallAfterFunc(name, ctx, me)
if !meAfter.Success {
return meAfter
}
return me
}
/**
* 根据关键值翻转值(限布尔值类型,1转2,2转1)
* 警告:此方法只支持布尔值类型,且只支持翻转1和2
* @Param ctx http请求对象
* @param control 控制层接口
* @return *msgentity.MsgEntity 返回验证结果
*/
func (controlUtil ControllerUtil) ReversalByKey(ctx ginutil.Context, control Controller) *msgentity.MsgEntity {
reversalColumn := urlutil.GetParam(ctx.Request, "sReversalColumn", "").(string) //翻转的字段名
entity, err := control.GetModuleEntity(control) //按模块数据实体创建新实例,并实例化
if err != nil {
return msgentity.Err(9001, "控制层未设置ModuleEntit:", err)
}
bl, msg, da := urlutil.GetParams(ctx.Request, entity)
if !bl {
return msgentity.Err(da.(int), msg)
}
ctx.Set("ControllerSimplName", control.SimplName(control))
ctx.Set("Controller", control)
params := da.(map[string]interface{})
whereInfo := []dbinfo.WhereInfo{}
for k, v := range params {
info := dbinfo.WhereInfo{Name: k, Value: v}
whereInfo = append(whereInfo, info)
}
service, err := control.GetModuleService(control)
if err != nil {
service = &ServiceBaseFunc{}
}
name := getSimplName(control) + ".ReversalByKey"
ctx.Set("ControllerSimplName", control.SimplName(control))
ctx.Set("Controller", control)
meBefore := AopUtil{}.CallBeforeFunc(name, ctx)
if !meBefore.Success {
return meBefore
}
me := service.ReversalByKey(ctx, entity, whereInfo, reversalColumn)
if !me.Success {
return me
}
meAfter := AopUtil{}.CallAfterFunc(name, ctx, me)
if !meAfter.Success {
return meAfter
}
return me
}
/**
* 增加请求属性
* 注:函数应用于模块控制器时修改或传递到通用方法时,切勿滥用
* @Param ctx http请求对象
* @Param attribs 参数键值对数组,[name,value],如果value不存在则为''
* @return *msgentity.MsgEntity 返回验证结果
*/
func (controlUtil ControllerUtil) AddRequestAttrib(ctx ginutil.Context, attribs ...[]string) {
if (attribs == nil) || (len(attribs) < 1) {
return
}
ctx.Request.ParseForm() //警告:必须先 解析所有请求数据
form := ctx.Request.Form
if form == nil {
form = make(uu.Values)
ctx.Request.Form = form
}
for _, attrib := range attribs {
if (attrib == nil) || (len(attrib) < 1) {
continue
}
name := attrib[0]
value := ""
if (len(attrib) > 1) && (attrib[1] != "") {
value = attrib[1] //fmt.Sprintf("%v", attrib[1])
}
form.Set(name, value)
}
}
/**
* 上传文件
* @param ctx http请求对象
* @param control 控制层接口
* @param modelName 模块名称
* @return *msgentity.MsgEntity 返回验证结果
*/
func (controlUtil ControllerUtil) UpFile(ctx ginutil.Context, control Controller, modelName string) *msgentity.MsgEntity {
ctx.Set("ControllerSimplName", control.SimplName(control))
ctx.Set("Controller", control)
service, err := control.GetModuleService(control)
if err != nil {
service = &ServiceBaseFunc{}
}
return service.UpFile(ctx, modelName)
}
/**
* 获取图片
* @param ctx http请求对象
* @param control 控制层接口
* @param modelName 模块名称
* @param filename 文件名
* @return *msgentity.MsgEntity 返回验证结果
*/
func (controlUtil ControllerUtil) LookImg(ctx ginutil.Context, control Controller, modelName, filename string) {
ctx.Set("ControllerSimplName", control.SimplName(control))
ctx.Set("Controller", control)
service, err := control.GetModuleService(control)
if err != nil {
service = &ServiceBaseFunc{}
}
service.LookImg(ctx, modelName, filename)
}
//-----------------------------------------------//
/**
* 取对应模块名称
* object 对象
*/
func getSimplName(object interface{}) string {
name := reflect.TypeOf(object).String()
iSt := strings.Index(name, ".")
if iSt > -1 {
name = name[iSt+1:]
}
return name
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/tomatomeatman/golang-repository.git
git@gitee.com:tomatomeatman/golang-repository.git
tomatomeatman
golang-repository
GolangRepository
61e401b0d628

搜索帮助