19 changed files with 1653 additions and 202 deletions
@ -0,0 +1,571 @@ |
|||||
|
package loginVerify |
||||
|
|
||||
|
import ( |
||||
|
"encoding/json" |
||||
|
"fmt" |
||||
|
"key_performance_indicators/middleware/grocerystore" |
||||
|
"key_performance_indicators/middleware/wechatapp/wechatstatice" |
||||
|
"key_performance_indicators/models/modelshr" |
||||
|
"key_performance_indicators/overall" |
||||
|
"key_performance_indicators/overall/publicmethod" |
||||
|
"net/http" |
||||
|
"net/url" |
||||
|
"strconv" |
||||
|
"time" |
||||
|
|
||||
|
"github.com/flipped-aurora/gin-vue-admin/server/model/common/response" |
||||
|
"github.com/gin-gonic/gin" |
||||
|
) |
||||
|
|
||||
|
/* |
||||
|
* |
||||
|
@ 作者: 秦东 |
||||
|
@ 时间: 2022-10-31 13:31:05 |
||||
|
@ 功能: 获取企业微信基础配置 |
||||
|
@ 参数 |
||||
|
|
||||
|
# |
||||
|
|
||||
|
@ 返回值 |
||||
|
|
||||
|
# |
||||
|
*/ |
||||
|
func (a *ApiMethod) GetWorkWechatJsApiConfig(c *gin.Context) { |
||||
|
host := c.Request.Header.Get("Host") |
||||
|
userAgent := c.Request.Header.Get("User-Agent") |
||||
|
wechatTokenStr := fmt.Sprintf("%v_%v", host, userAgent) |
||||
|
var md5JiaMi publicmethod.Md5Encryption |
||||
|
md5JiaMi.Md5EncryptionInit(wechatTokenStr) |
||||
|
md5Token := md5JiaMi.Md5EncryptionAlgorithm() |
||||
|
|
||||
|
var receivedValue ExamConfig |
||||
|
err := c.ShouldBindJSON(&receivedValue) |
||||
|
if err != nil { |
||||
|
publicmethod.Result(100, receivedValue, c) |
||||
|
return |
||||
|
} |
||||
|
if receivedValue.Url == "" { |
||||
|
publicmethod.Result(1, receivedValue, c, "参数错误!请重新提交!") |
||||
|
return |
||||
|
} |
||||
|
if receivedValue.State == 0 { |
||||
|
receivedValue.State = 1 |
||||
|
} |
||||
|
//获取JsApi_ticket
|
||||
|
_, jsapiTicker, err := GetJsapiTicket("kpi", md5Token, receivedValue.State) |
||||
|
if err != nil { |
||||
|
publicmethod.Result(1, err, c, "获取jsapi_ticket数据失败!") |
||||
|
return |
||||
|
} |
||||
|
noncestr := publicmethod.GetUUid(3) |
||||
|
timestamp := time.Now().Unix() |
||||
|
url := receivedValue.Url |
||||
|
jiamistr := fmt.Sprintf("jsapi_ticket=%v&noncestr=%v×tamp=%v&url=%v", jsapiTicker, noncestr, timestamp, url) |
||||
|
jiamistrHa1 := publicmethod.Sha1Encryption(jiamistr) |
||||
|
outData := publicmethod.MapOut[string]() |
||||
|
outData["corpid"] = overall.CONSTANT_CONFIG.WechatCompany.CompanyId |
||||
|
outData["agentid"] = overall.CONSTANT_CONFIG.WechatKpi.Agentid |
||||
|
outData["timestamp"] = strconv.FormatInt(timestamp, 10) |
||||
|
outData["nonceStr"] = strconv.FormatInt(noncestr, 10) |
||||
|
outData["signature"] = jiamistrHa1 |
||||
|
outData["orderid"] = strconv.FormatInt(publicmethod.GetUUid(2), 10) |
||||
|
|
||||
|
outData["jsapi_ticket"] = jsapiTicker |
||||
|
|
||||
|
outData["state"] = receivedValue.State |
||||
|
|
||||
|
response.Result(0, outData, "查询成功", c) |
||||
|
} |
||||
|
|
||||
|
/* |
||||
|
* |
||||
|
@ 作者: 秦东 |
||||
|
@ 时间: 2022-10-31 13:07:35 |
||||
|
@ 功能: 获取企业的jsapi_ticket 或 获取应用的jsapi_ticket |
||||
|
@ 参数 |
||||
|
|
||||
|
#systemApp 系统 |
||||
|
#key 身份识别 |
||||
|
#calss 1:应用,2:企业 |
||||
|
|
||||
|
@ 返回值 |
||||
|
|
||||
|
#sendUrlstr jsapiTicket访问URL |
||||
|
*/ |
||||
|
func GetJsapiTicket(systemApp, key string, class int) (sendUrlstr, jsApiTickerStr string, err error) { |
||||
|
|
||||
|
//获取token
|
||||
|
tokenStr, err := wechatstatice.GetWechatTokenEs(systemApp, key, 1) |
||||
|
if class != 1 { |
||||
|
sendUrlstr = "https://qyapi.weixin.qq.com/cgi-bin/get_jsapi_ticket?access_token=" + tokenStr //获取企业级
|
||||
|
} else { |
||||
|
sendUrlstr = "https://qyapi.weixin.qq.com/cgi-bin/ticket/get?access_token=" + tokenStr + "&type=agent_config" //获取应用级
|
||||
|
} |
||||
|
jsApiTicketRedis := fmt.Sprintf("WorkWechat:JsapiTicket:%v_%v_%v", systemApp, overall.CONSTANT_CONFIG.RedisPrefixStr.Alias, class) |
||||
|
redisClient := grocerystore.RunRedis(overall.CONSTANT_REDIS3) |
||||
|
isTrue, jsApiTickerStr := redisClient.Get(jsApiTicketRedis) //读取redis数据
|
||||
|
if isTrue != true { |
||||
|
//获取企业微信jsapi_ticket
|
||||
|
jsapiTickerMsg := publicmethod.CurlGet(sendUrlstr) |
||||
|
var callBackCont wechatstatice.WeChatCallBack |
||||
|
err = json.Unmarshal(jsapiTickerMsg, &callBackCont) |
||||
|
if err != nil { |
||||
|
return |
||||
|
} |
||||
|
if callBackCont.Errcode != 0 { |
||||
|
return |
||||
|
} |
||||
|
jsApiTickerStr = callBackCont.Ticket |
||||
|
redisClient.SetRedisTime(7200) |
||||
|
redisClient.Set(jsApiTicketRedis, jsApiTickerStr) |
||||
|
} else { |
||||
|
return |
||||
|
} |
||||
|
return |
||||
|
} |
||||
|
|
||||
|
// 获取身份认证
|
||||
|
func (a *ApiMethod) AuthenticationUser(c *gin.Context) { |
||||
|
|
||||
|
host := c.Request.Header.Get("Host") |
||||
|
userAgent := c.Request.Header.Get("User-Agent") |
||||
|
wechatTokenStr := fmt.Sprintf("%v_%v", host, userAgent) |
||||
|
var md5JiaMi publicmethod.Md5Encryption |
||||
|
md5JiaMi.Md5EncryptionInit(wechatTokenStr) |
||||
|
md5Token := md5JiaMi.Md5EncryptionAlgorithm() |
||||
|
//获取token
|
||||
|
tokenStr, err := wechatstatice.GetWechatTokenEs("kpi", md5Token, 1) |
||||
|
if err != nil { |
||||
|
publicmethod.Result(100, err, c, "身份认证失败!----------------->") |
||||
|
// user_code_url := fmt.Sprintf("%v", overall.CONSTANT_CONFIG.Appsetup.WebUrl)
|
||||
|
// c.Redirect(http.StatusMovedPermanently, user_code_url)
|
||||
|
return |
||||
|
} |
||||
|
//重定向身份认证
|
||||
|
callBackUrl := url.QueryEscape(fmt.Sprintf("%v/kpiapi/base/callbackauthuser", overall.CONSTANT_CONFIG.Appsetup.WebUrl)) |
||||
|
redirectUrl := fmt.Sprintf("https://open.weixin.qq.com/connect/oauth2/authorize?appid=%v&redirect_uri=%v&response_type=code&scope=snsapi_base&state=%v#wechat_redirect", overall.CONSTANT_CONFIG.WechatCompany.CompanyId, callBackUrl, tokenStr) |
||||
|
c.Redirect(http.StatusMovedPermanently, redirectUrl) |
||||
|
// publicmethod.Result(1, tokenStr, c, "身份认证失败!!")
|
||||
|
} |
||||
|
|
||||
|
/* |
||||
|
* |
||||
|
@ 作者: 秦东 |
||||
|
@ 时间: 2022-11-01 10:02:09 |
||||
|
@ 功能: 企业微信身份回调认证 |
||||
|
@ 参数 |
||||
|
|
||||
|
# |
||||
|
|
||||
|
@ 返回值 |
||||
|
|
||||
|
# |
||||
|
*/ |
||||
|
func (a *ApiMethod) CallBackAuthUser(c *gin.Context) { |
||||
|
code := c.Query("code") |
||||
|
state := c.Query("state") |
||||
|
if code == "" || state == "" { |
||||
|
publicmethod.Result(1, code, c, "未能查询到您的信息!企业微信授权失败!1") |
||||
|
return |
||||
|
} |
||||
|
|
||||
|
sendUser := fmt.Sprintf("https://qyapi.weixin.qq.com/cgi-bin/auth/getuserinfo?access_token=%v&code=%v", state, code) |
||||
|
tokenByte := publicmethod.CurlGet(sendUser) |
||||
|
var callBackData wechatstatice.WorkWechatUserAuter |
||||
|
err := json.Unmarshal(tokenByte, &callBackData) |
||||
|
if err != nil { |
||||
|
publicmethod.Result(1, err, c, "未能查询到您的信息!企业微信授权失败!2") |
||||
|
return |
||||
|
} |
||||
|
if callBackData.Errcode != 0 { |
||||
|
|
||||
|
if callBackData.Errcode == 42001 { |
||||
|
AgainEmpower(c) |
||||
|
return |
||||
|
} |
||||
|
publicmethod.Result(1, callBackData, c, "未能查询到您的信息!企业微信授权失败!3") |
||||
|
return |
||||
|
} |
||||
|
var userWechatId string |
||||
|
if callBackData.OpenId != "" { |
||||
|
userWechatId = callBackData.OpenId |
||||
|
} |
||||
|
if callBackData.Userid != "" { |
||||
|
userWechatId = callBackData.Userid |
||||
|
} |
||||
|
if userWechatId == "" { |
||||
|
publicmethod.Result(1, err, c, "未能查询到您的信息!企业微信授权失败!4") |
||||
|
return |
||||
|
} |
||||
|
_, sendMap, msg, isTrue := SetUpUserLogin(userWechatId) |
||||
|
callBackLoginUrl := fmt.Sprintf("%v/#/pages/login/login", overall.CONSTANT_CONFIG.Appsetup.WebUrl) |
||||
|
switch isTrue { |
||||
|
case 2: |
||||
|
publicmethod.Result(1, err, c, msg) |
||||
|
return |
||||
|
case 3: |
||||
|
publicmethod.Result(1, err, c, msg) |
||||
|
return |
||||
|
case 4: |
||||
|
callBackLoginUrl = fmt.Sprintf("%v?exitstr=0&openid=%v&userkey=%v&token=%v", callBackLoginUrl, userWechatId, sendMap["key"], sendMap["token"]) |
||||
|
default: |
||||
|
callBackLoginUrl = fmt.Sprintf("%v?exitstr=1&openid=%v", callBackLoginUrl, userWechatId) |
||||
|
} |
||||
|
c.Redirect(http.StatusMovedPermanently, callBackLoginUrl) |
||||
|
} |
||||
|
|
||||
|
/* |
||||
|
* |
||||
|
@ 作者: 秦东 |
||||
|
@ 时间: 2022-11-02 13:22:08 |
||||
|
@ 功能: 重新等下授权 |
||||
|
@ 参数 |
||||
|
|
||||
|
# |
||||
|
|
||||
|
@ 返回值 |
||||
|
|
||||
|
# |
||||
|
*/ |
||||
|
func AgainEmpower(c *gin.Context) { |
||||
|
host := c.Request.Header.Get("Host") |
||||
|
userAgent := c.Request.Header.Get("User-Agent") |
||||
|
wechatTokenStr := fmt.Sprintf("%v_%v", host, userAgent) |
||||
|
var md5JiaMi publicmethod.Md5Encryption |
||||
|
md5JiaMi.Md5EncryptionInit(wechatTokenStr) |
||||
|
md5Token := md5JiaMi.Md5EncryptionAlgorithm() |
||||
|
//获取token
|
||||
|
tokenStr, err := wechatstatice.GetWechatTokenEs("kpi", md5Token, 2) |
||||
|
if err != nil { |
||||
|
// publicmethod.Result(1, err, c, "身份认证失败!")
|
||||
|
user_code_url := fmt.Sprintf("%v", overall.CONSTANT_CONFIG.Appsetup.WebUrl) |
||||
|
c.Redirect(http.StatusMovedPermanently, user_code_url) |
||||
|
return |
||||
|
} |
||||
|
//重定向身份认证
|
||||
|
callBackUrl := url.QueryEscape(fmt.Sprintf("%v/kpiapi/base/callbackauthuser", overall.CONSTANT_CONFIG.Appsetup.WebUrl)) |
||||
|
redirectUrl := fmt.Sprintf("https://open.weixin.qq.com/connect/oauth2/authorize?appid=%v&redirect_uri=%v&response_type=code&scope=snsapi_base&state=%v#wechat_redirect", overall.CONSTANT_CONFIG.WechatCompany.CompanyId, callBackUrl, tokenStr) |
||||
|
c.Redirect(http.StatusMovedPermanently, redirectUrl) |
||||
|
} |
||||
|
|
||||
|
/* |
||||
|
* |
||||
|
@ 作者: 秦东 |
||||
|
@ 时间: 2022-11-01 11:24:40 |
||||
|
@ 功能: 设定登录信息 |
||||
|
@ 参数 |
||||
|
|
||||
|
# |
||||
|
|
||||
|
@ 返回值 |
||||
|
|
||||
|
# |
||||
|
*/ |
||||
|
func SetUpUserLogin(openId string) (userCont modelshr.ManCont, sendMap map[string]interface{}, msg string, isTrue int) { |
||||
|
isTrue = 1 |
||||
|
|
||||
|
// var userCont modelshr.ManCont
|
||||
|
err := overall.CONSTANT_DB_HR.Where("`wechat` = ? OR `work_wechat` = ?", openId, openId).First(&userCont).Error //获取人员信息
|
||||
|
if err != nil { |
||||
|
return |
||||
|
} |
||||
|
|
||||
|
if userCont.State == 2 { |
||||
|
msg = "登陆失败! 该账号已经被禁用!" |
||||
|
isTrue = 2 |
||||
|
return |
||||
|
} |
||||
|
if userCont.State == 3 { |
||||
|
msg = "登陆失败! 该账号不存在!" |
||||
|
isTrue = 3 |
||||
|
return |
||||
|
} |
||||
|
|
||||
|
uuIdVal := publicmethod.GetUUid(3) //获取随机数
|
||||
|
uuIdValStr := strconv.FormatInt(uuIdVal, 10) |
||||
|
fmt.Printf("%v\n", uuIdValStr) |
||||
|
//Token定参
|
||||
|
userAgent := overall.CONSTANT_CONFIG.Appsetup.AppKey |
||||
|
var md5JiaMi publicmethod.Md5Encryption |
||||
|
md5JiaMi.Md5EncryptionInit(userAgent) |
||||
|
md5Token := md5JiaMi.Md5EncryptionAlgorithm() |
||||
|
//工号MD5加密
|
||||
|
var md5JiaMiNumber publicmethod.Md5Encryption |
||||
|
// md5JiaMiNumber.Md5EncryptionInit(userCont.Number + uuIdValStr)
|
||||
|
md5JiaMiNumber.Md5EncryptionInit(userCont.Number) |
||||
|
userKeyCode := md5JiaMiNumber.Md5EncryptionAlgorithm() |
||||
|
//组成Token字符串进行
|
||||
|
// sha1Str := userKeyCode + userCont.Number + userCont.Password + md5Token + uuIdValStr
|
||||
|
sha1Str := userKeyCode + userCont.Number + userCont.Password + md5Token |
||||
|
sha1Token := publicmethod.Sha1Encryption(sha1Str) |
||||
|
//身份识别数据
|
||||
|
menuoper, jurisdiction := getRoleSeat(userCont.Role) |
||||
|
writeRedisData := map[string]interface{}{ |
||||
|
"userkey": userKeyCode, |
||||
|
"key": userCont.Key, |
||||
|
"usernumber": userCont.Number, |
||||
|
"userpwd": userCont.Password, |
||||
|
"usertoken": sha1Token, |
||||
|
"jurisdiction": jurisdiction, |
||||
|
"menuOper": menuoper, |
||||
|
"wand": 118, |
||||
|
} |
||||
|
|
||||
|
// fmt.Printf("writeRedisData--------->%v\n", writeRedisData)
|
||||
|
|
||||
|
//API Token数据
|
||||
|
redisFileKey := fmt.Sprintf("ScanCode:Authentication:LoginApi_%v_%v", overall.CONSTANT_CONFIG.RedisPrefixStr.Alias, userKeyCode) |
||||
|
redisClient := grocerystore.RunRedis(overall.CONSTANT_REDIS5) |
||||
|
redisClient.SetRedisTime(10800) |
||||
|
redisClient.HashMsetAdd(redisFileKey, writeRedisData) |
||||
|
|
||||
|
//缓存写入个人信息
|
||||
|
redisMyContKey := fmt.Sprintf("ScanCode:Authentication:UserCont_%v_%v", overall.CONSTANT_CONFIG.RedisPrefixStr.Alias, userCont.Number) |
||||
|
myCont := publicmethod.MapOut[string]() |
||||
|
myCont["id"] = userCont.Id |
||||
|
myCont["number"] = userCont.Number //员工工号
|
||||
|
myCont["name"] = userCont.Name //姓名
|
||||
|
myCont["icon"] = userCont.Icon //头像
|
||||
|
myCont["hireclass"] = userCont.HireClass //雇佣类型(1:雇佣入职;2:再入职;)
|
||||
|
myCont["emptype"] = userCont.EmpType //用工关系(1:临时工 , 2:编外人员 ;3:实习&实习生;4:试用员工;5:待分配;6:待岗;7:临时调入;8:正式员工;9:长期病假;10:停薪留职;11:退休;12:辞职;13:辞退;14:离职)
|
||||
|
myCont["company"] = userCont.Company //入职公司
|
||||
|
myCont["maindeparment"] = userCont.MainDeparment //主部门
|
||||
|
myCont["sunmaindeparment"] = userCont.SunMainDeparment //二级主部门
|
||||
|
myCont["deparment"] = userCont.Deparment //部门
|
||||
|
myCont["adminorg"] = userCont.AdminOrg //所属行政组织
|
||||
|
myCont["teamid"] = userCont.TeamId //班组
|
||||
|
myCont["position"] = userCont.Position //职位
|
||||
|
myCont["jobclass"] = userCont.JobClass //职务分类
|
||||
|
myCont["jobid"] = userCont.JobId //职务
|
||||
|
myCont["jobleve"] = userCont.JobLeve //职务等级
|
||||
|
myCont["wechat"] = userCont.Wechat //微信UserId
|
||||
|
myCont["workwechat"] = userCont.WorkWechat //企业微信UserId
|
||||
|
myCont["state"] = userCont.State //状态(1:启用;2:禁用;3:删除)
|
||||
|
myCont["key"] = userCont.Key //key
|
||||
|
myCont["isadmin"] = userCont.IsAdmin //是否为管理员(1:不是;2:分公司;3:集团管理员;4:超级管
|
||||
|
myCont["password"] = userCont.Password //密码
|
||||
|
myCont["role"] = userCont.Role //角色
|
||||
|
myCont["idcardno"] = userCont.Idcardno //身份证号
|
||||
|
myCont["passportno"] = userCont.Passportno //护照号码
|
||||
|
myCont["globalroaming"] = userCont.Globalroaming //国际区号
|
||||
|
myCont["mobilephone"] = userCont.Mobilephone //手机号码
|
||||
|
myCont["email"] = userCont.Email //电子邮件
|
||||
|
myCont["gender"] = userCont.Gender //性别(1:男性;2:女性;3:中性)
|
||||
|
myCont["birthday"] = userCont.Birthday //birthday
|
||||
|
myCont["myfolk"] = userCont.Myfolk //民族
|
||||
|
myCont["nativeplace"] = userCont.Nativeplace //籍贯
|
||||
|
myCont["idcardstartdate"] = userCont.Idcardstartdate //身份证有效期开始
|
||||
|
myCont["idcardenddate"] = userCont.Idcardenddate //身份证有效期结束
|
||||
|
myCont["idcardaddress"] = userCont.Idcardaddress //身份证地址
|
||||
|
myCont["idcardIssued"] = userCont.IdcardIssued //身份证签发机关
|
||||
|
myCont["health"] = userCont.Health //健康状况(1:良好;2:一般;3:较弱,4:有生理缺陷;5:残废)
|
||||
|
myCont["maritalstatus"] = userCont.Maritalstatus //婚姻状况(1:未婚;2:已婚;3:丧偶;4:离异)
|
||||
|
myCont["internaltelephone"] = userCont.Internaltelephone //内线电话
|
||||
|
myCont["currentresidence"] = userCont.Currentresidence //现居住地址
|
||||
|
myCont["constellationing"] = userCont.Constellation //星座(1:白羊座;2:金牛座;3:双子座;4:巨蟹座;5:狮子座;6:处女座;7:天枰座;8:天蝎座;9:射手座;10:摩羯座;11:水瓶座;12:双鱼座)
|
||||
|
myCont["isdoubleworker"] = userCont.Isdoubleworker //是否双职工(1:是;2:否)
|
||||
|
myCont["isveterans"] = userCont.Isveterans //是否为退役军人(1:是;2:否)
|
||||
|
myCont["veteransnumber"] = userCont.Veteransnumber //退役证编号
|
||||
|
myCont["jobstartdate"] = userCont.Jobstartdate //参加工作日期
|
||||
|
myCont["entrydate"] = userCont.Entrydate //入职日期
|
||||
|
myCont["probationperiod"] = userCont.Probationperiod //试用期
|
||||
|
myCont["planformaldate"] = userCont.Planformaldate //预计转正日期
|
||||
|
myCont["political_outlook"] = userCont.PoliticalOutlook //政治面貌(1:群众;2:无党派;3:台盟会员;4:九三社员;5:致公党员;6:农工党员;7:民进会员;8:民建会员;9:民盟盟员;10:民革会员,11:共青团员;12:预备党员;13:中共党员)
|
||||
|
|
||||
|
var companyCont modelshr.AdministrativeOrganization |
||||
|
companyCont.GetCont(map[string]interface{}{"`id`": userCont.Company}, "`name`") |
||||
|
myCont["companyname"] = companyCont.Name |
||||
|
var departmentCont modelshr.AdministrativeOrganization |
||||
|
departmentCont.GetCont(map[string]interface{}{"`id`": userCont.MainDeparment}, "`name`") |
||||
|
myCont["maindeparmentname"] = departmentCont.Name |
||||
|
var postInfo modelshr.Position |
||||
|
postInfo.GetCont(map[string]interface{}{"`id`": userCont.Position}, "`name`") |
||||
|
myCont["positionname"] = postInfo.Name |
||||
|
redisClient.HashMsetAdd(redisMyContKey, myCont) |
||||
|
|
||||
|
//返回值
|
||||
|
saveData := publicmethod.MapOut[string]() |
||||
|
saveData["key"] = userKeyCode |
||||
|
saveData["token"] = sha1Token |
||||
|
saveData["userinfo"] = userCont |
||||
|
saveData["usercont"] = myCont |
||||
|
|
||||
|
sendMap = saveData |
||||
|
isTrue = 4 |
||||
|
return |
||||
|
} |
||||
|
|
||||
|
// 手机端免登录验证
|
||||
|
func (a *ApiMethod) LaissezPasser(c *gin.Context) { |
||||
|
userKey := c.Request.Header.Get("user-key") |
||||
|
userToken := c.Request.Header.Get("user-token") |
||||
|
|
||||
|
//API Token数据
|
||||
|
redisFileKey := fmt.Sprintf("ScanCode:Authentication:LoginApi_%v_%v", overall.CONSTANT_CONFIG.RedisPrefixStr.Alias, userKey) |
||||
|
redisClient := grocerystore.RunRedis(overall.CONSTANT_REDIS5) |
||||
|
userRedisToken, isTrue := redisClient.HashGetAll(redisFileKey) |
||||
|
if !isTrue { |
||||
|
publicmethod.Result(1, isTrue, c, "未登录或非法访问!") |
||||
|
return |
||||
|
} |
||||
|
if userToken != userRedisToken["usertoken"] { |
||||
|
publicmethod.Result(1, isTrue, c, "令牌不正确!非法访问!") |
||||
|
return |
||||
|
} |
||||
|
userCont, myErr := publicmethod.GetUserRedisCont(userRedisToken["usernumber"]) |
||||
|
if myErr != nil { |
||||
|
publicmethod.Result(1, isTrue, c, "登录超时!请重新登录!") |
||||
|
return |
||||
|
} |
||||
|
myCont := publicmethod.MapOut[string]() |
||||
|
myCont["id"] = userCont.Id |
||||
|
myCont["number"] = userCont.Number //员工工号
|
||||
|
myCont["name"] = userCont.Name //姓名
|
||||
|
myCont["icon"] = userCont.Icon //头像
|
||||
|
myCont["hireclass"] = userCont.HireClass //雇佣类型(1:雇佣入职;2:再入职;)
|
||||
|
myCont["emptype"] = userCont.EmpType //用工关系(1:临时工 , 2:编外人员 ;3:实习&实习生;4:试用员工;5:待分配;6:待岗;7:临时调入;8:正式员工;9:长期病假;10:停薪留职;11:退休;12:辞职;13:辞退;14:离职)
|
||||
|
myCont["company"] = userCont.Company //入职公司
|
||||
|
myCont["maindeparment"] = userCont.MainDeparment //主部门
|
||||
|
myCont["sunmaindeparment"] = userCont.SunMainDeparment //二级主部门
|
||||
|
myCont["deparment"] = userCont.Deparment //部门
|
||||
|
myCont["adminorg"] = userCont.AdminOrg //所属行政组织
|
||||
|
myCont["teamid"] = userCont.TeamId //班组
|
||||
|
myCont["position"] = userCont.Position //职位
|
||||
|
myCont["jobclass"] = userCont.JobClass //职务分类
|
||||
|
myCont["jobid"] = userCont.JobId //职务
|
||||
|
myCont["jobleve"] = userCont.JobLeve //职务等级
|
||||
|
myCont["wechat"] = userCont.Wechat //微信UserId
|
||||
|
myCont["workwechat"] = userCont.WorkWechat //企业微信UserId
|
||||
|
myCont["state"] = userCont.State //状态(1:启用;2:禁用;3:删除)
|
||||
|
myCont["key"] = userCont.Key //key
|
||||
|
myCont["isadmin"] = userCont.IsAdmin //是否为管理员(1:不是;2:分公司;3:集团管理员;4:超级管
|
||||
|
myCont["password"] = userCont.Password //密码
|
||||
|
myCont["role"] = userCont.Role //角色
|
||||
|
myCont["idcardno"] = userCont.Idcardno //身份证号
|
||||
|
myCont["passportno"] = userCont.Passportno //护照号码
|
||||
|
myCont["globalroaming"] = userCont.Globalroaming //国际区号
|
||||
|
myCont["mobilephone"] = userCont.Mobilephone //手机号码
|
||||
|
myCont["email"] = userCont.Email //电子邮件
|
||||
|
myCont["gender"] = userCont.Gender //性别(1:男性;2:女性;3:中性)
|
||||
|
myCont["birthday"] = userCont.Birthday //birthday
|
||||
|
myCont["myfolk"] = userCont.Myfolk //民族
|
||||
|
myCont["nativeplace"] = userCont.Nativeplace //籍贯
|
||||
|
myCont["idcardstartdate"] = userCont.Idcardstartdate //身份证有效期开始
|
||||
|
myCont["idcardenddate"] = userCont.Idcardenddate //身份证有效期结束
|
||||
|
myCont["idcardaddress"] = userCont.Idcardaddress //身份证地址
|
||||
|
myCont["idcardIssued"] = userCont.IdcardIssued //身份证签发机关
|
||||
|
myCont["health"] = userCont.Health //健康状况(1:良好;2:一般;3:较弱,4:有生理缺陷;5:残废)
|
||||
|
myCont["maritalstatus"] = userCont.Maritalstatus //婚姻状况(1:未婚;2:已婚;3:丧偶;4:离异)
|
||||
|
myCont["internaltelephone"] = userCont.Internaltelephone //内线电话
|
||||
|
myCont["currentresidence"] = userCont.Currentresidence //现居住地址
|
||||
|
myCont["constellationing"] = userCont.Constellation //星座(1:白羊座;2:金牛座;3:双子座;4:巨蟹座;5:狮子座;6:处女座;7:天枰座;8:天蝎座;9:射手座;10:摩羯座;11:水瓶座;12:双鱼座)
|
||||
|
myCont["isdoubleworker"] = userCont.Isdoubleworker //是否双职工(1:是;2:否)
|
||||
|
myCont["isveterans"] = userCont.Isveterans //是否为退役军人(1:是;2:否)
|
||||
|
myCont["veteransnumber"] = userCont.Veteransnumber //退役证编号
|
||||
|
myCont["jobstartdate"] = userCont.Jobstartdate //参加工作日期
|
||||
|
myCont["entrydate"] = userCont.Entrydate //入职日期
|
||||
|
myCont["probationperiod"] = userCont.Probationperiod //试用期
|
||||
|
myCont["planformaldate"] = userCont.Planformaldate //预计转正日期
|
||||
|
myCont["political_outlook"] = userCont.PoliticalOutlook //政治面貌(1:群众;2:无党派;3:台盟会员;4:九三社员;5:致公党员;6:农工党员;7:民进会员;8:民建会员;9:民盟盟员;10:民革会员,11:共青团员;12:预备党员;13:中共党员)
|
||||
|
var companyCont modelshr.AdministrativeOrganization |
||||
|
companyCont.GetCont(map[string]interface{}{"`id`": userCont.Company}, "`name`") |
||||
|
myCont["companyname"] = companyCont.Name |
||||
|
var departmentCont modelshr.AdministrativeOrganization |
||||
|
departmentCont.GetCont(map[string]interface{}{"`id`": userCont.MainDeparment}, "`name`") |
||||
|
myCont["maindeparmentname"] = departmentCont.Name |
||||
|
var postInfo modelshr.Position |
||||
|
postInfo.GetCont(map[string]interface{}{"`id`": userCont.Position}, "`name`") |
||||
|
myCont["positionname"] = postInfo.Name |
||||
|
|
||||
|
//返回值
|
||||
|
saveData := publicmethod.MapOut[string]() |
||||
|
saveData["key"] = userKey |
||||
|
saveData["token"] = userToken |
||||
|
saveData["userinfo"] = userCont |
||||
|
saveData["usercont"] = myCont |
||||
|
|
||||
|
publicmethod.Result(0, saveData, c) |
||||
|
} |
||||
|
|
||||
|
/* |
||||
|
* |
||||
|
@ 作者: 秦东 |
||||
|
@ 时间: 2022-11-08 13:10:54 |
||||
|
@ 功能: 扫码登录 |
||||
|
@ 参数 |
||||
|
|
||||
|
# |
||||
|
|
||||
|
@ 返回值 |
||||
|
|
||||
|
# |
||||
|
*/ |
||||
|
func (a *ApiMethod) ScanQrCodeCallBackAuthUser(c *gin.Context) { |
||||
|
code := c.Query("code") |
||||
|
state := c.Query("state") |
||||
|
if code == "" || state == "" { |
||||
|
publicmethod.Result(1, code, c, "未能查询到您的信息!企业微信授权失败!1") |
||||
|
return |
||||
|
} |
||||
|
|
||||
|
host := c.Request.Header.Get("Host") |
||||
|
userAgent := c.Request.Header.Get("User-Agent") |
||||
|
wechatTokenStr := fmt.Sprintf("%v_%v", host, userAgent) |
||||
|
var md5JiaMi publicmethod.Md5Encryption |
||||
|
md5JiaMi.Md5EncryptionInit(wechatTokenStr) |
||||
|
md5Token := md5JiaMi.Md5EncryptionAlgorithm() |
||||
|
|
||||
|
//获取token
|
||||
|
tokenStr, err := wechatstatice.GetWechatTokenEs("kpi", md5Token, 1) |
||||
|
|
||||
|
if err != nil { |
||||
|
publicmethod.Result(1, err, c, "未能查询到您的信息!企业微信授权失败!4") |
||||
|
return |
||||
|
} |
||||
|
|
||||
|
sendUser := fmt.Sprintf("https://qyapi.weixin.qq.com/cgi-bin/auth/getuserinfo?access_token=%v&code=%v", tokenStr, code) |
||||
|
tokenByte := publicmethod.CurlGet(sendUser) |
||||
|
var callBackData wechatstatice.WorkWechatUserAuter |
||||
|
err = json.Unmarshal(tokenByte, &callBackData) |
||||
|
if err != nil { |
||||
|
publicmethod.Result(1, err, c, "未能查询到您的信息!企业微信授权失败!2") |
||||
|
return |
||||
|
} |
||||
|
if callBackData.Errcode != 0 { |
||||
|
|
||||
|
if callBackData.Errcode == 42001 { |
||||
|
AgainEmpower(c) |
||||
|
return |
||||
|
} |
||||
|
publicmethod.Result(1, callBackData, c, "未能查询到您的信息!企业微信授权失败!3") |
||||
|
return |
||||
|
} |
||||
|
var userWechatId string |
||||
|
if callBackData.OpenId != "" { |
||||
|
userWechatId = callBackData.OpenId |
||||
|
} |
||||
|
if callBackData.Userid != "" { |
||||
|
userWechatId = callBackData.Userid |
||||
|
} |
||||
|
if userWechatId == "" { |
||||
|
publicmethod.Result(1, err, c, "未能查询到您的信息!企业微信授权失败!4") |
||||
|
return |
||||
|
} |
||||
|
// userWechatId := "KaiXinGuo"
|
||||
|
_, sendMap, msg, isTrue := SetUpUserLogin(userWechatId) |
||||
|
callBackLoginUrl := fmt.Sprintf("%v/#/ceshi", overall.CONSTANT_CONFIG.Appsetup.PcbUrl) |
||||
|
switch isTrue { |
||||
|
case 2: |
||||
|
publicmethod.Result(1, err, c, msg) |
||||
|
return |
||||
|
case 3: |
||||
|
publicmethod.Result(1, err, c, msg) |
||||
|
return |
||||
|
case 4: |
||||
|
callBackLoginUrl = fmt.Sprintf("%v?token=%v&key=%v", callBackLoginUrl, sendMap["token"], sendMap["key"]) |
||||
|
default: |
||||
|
callBackLoginUrl = fmt.Sprintf("%v?token=%v&key=%v", callBackLoginUrl, sendMap["token"], sendMap["key"]) |
||||
|
} |
||||
|
// publicmethod.Result(1, callBackLoginUrl, c, "未能查询到您的信息!企业微信授权失败!5")
|
||||
|
c.Redirect(http.StatusMovedPermanently, callBackLoginUrl) |
||||
|
} |
||||
@ -0,0 +1,204 @@ |
|||||
|
package jurisdictionpc |
||||
|
|
||||
|
import ( |
||||
|
"key_performance_indicators/models/modelssystempermission" |
||||
|
"key_performance_indicators/overall" |
||||
|
"key_performance_indicators/overall/publicmethod" |
||||
|
"time" |
||||
|
|
||||
|
"github.com/gin-gonic/gin" |
||||
|
) |
||||
|
|
||||
|
//系统角色处理
|
||||
|
|
||||
|
func (a *ApiMethod) AddSystemRole(c *gin.Context) { |
||||
|
var receivedValue systemRole |
||||
|
err := c.ShouldBindJSON(&receivedValue) |
||||
|
if err != nil { |
||||
|
publicmethod.Result(100, err, c) |
||||
|
return |
||||
|
} |
||||
|
if receivedValue.Name == "" { |
||||
|
publicmethod.Result(101, receivedValue, c) |
||||
|
return |
||||
|
} |
||||
|
if receivedValue.Sort == 0 { |
||||
|
receivedValue.Sort = 50 |
||||
|
} |
||||
|
var systemRoleCont modelssystempermission.SystemRole |
||||
|
err = systemRoleCont.GetCont(map[string]interface{}{"`name`": receivedValue.Name}, "`id`") |
||||
|
if err == nil { |
||||
|
publicmethod.Result(103, systemRoleCont, c) |
||||
|
return |
||||
|
} |
||||
|
systemRoleCont.Name = receivedValue.Name |
||||
|
systemRoleCont.Sort = receivedValue.Sort |
||||
|
systemRoleCont.State = 1 |
||||
|
systemRoleCont.Time = time.Now().Unix() |
||||
|
err = overall.CONSTANT_DB_System_Permission.Create(&systemRoleCont).Error |
||||
|
if err != nil { |
||||
|
publicmethod.Result(104, err, c) |
||||
|
return |
||||
|
} |
||||
|
publicmethod.Result(0, err, c) |
||||
|
} |
||||
|
|
||||
|
/* |
||||
|
* |
||||
|
@ 作者: 秦东 |
||||
|
@ 时间: 2022-11-09 08:30:04 |
||||
|
@ 功能: 系统角色编辑 |
||||
|
@ 参数 |
||||
|
|
||||
|
#Id 项目ID |
||||
|
#Name 角色名称 |
||||
|
#Sort 角色排序 |
||||
|
|
||||
|
@ 返回值 |
||||
|
|
||||
|
# |
||||
|
*/ |
||||
|
func (a *ApiMethod) EditSystemRole(c *gin.Context) { |
||||
|
var receivedValue editSystemRoleCont |
||||
|
err := c.ShouldBindJSON(&receivedValue) |
||||
|
if err != nil { |
||||
|
publicmethod.Result(100, err, c) |
||||
|
return |
||||
|
} |
||||
|
if receivedValue.Id == "" { |
||||
|
publicmethod.Result(101, receivedValue, c) |
||||
|
return |
||||
|
} |
||||
|
if receivedValue.Name == "" { |
||||
|
publicmethod.Result(101, receivedValue, c) |
||||
|
return |
||||
|
} |
||||
|
if receivedValue.Sort == 0 { |
||||
|
receivedValue.Sort = 50 |
||||
|
} |
||||
|
var systemRoleCont modelssystempermission.SystemRole |
||||
|
err = systemRoleCont.GetCont(map[string]interface{}{"`id`": receivedValue.Id}, "`name`") |
||||
|
if err != nil { |
||||
|
publicmethod.Result(107, err, c) |
||||
|
return |
||||
|
} |
||||
|
|
||||
|
editCont := publicmethod.MapOut[string]() |
||||
|
if receivedValue.Sort != systemRoleCont.Sort { |
||||
|
editCont["`sort`"] = receivedValue.Sort |
||||
|
|
||||
|
} |
||||
|
if systemRoleCont.Name != receivedValue.Name { |
||||
|
err = systemRoleCont.GetCont(map[string]interface{}{"`name`": receivedValue.Name}, "`id`") |
||||
|
if err == nil { |
||||
|
publicmethod.Result(103, systemRoleCont, c) |
||||
|
return |
||||
|
} |
||||
|
editCont["`name`"] = receivedValue.Name |
||||
|
} |
||||
|
if len(editCont) > 0 { |
||||
|
editCont["`time`"] = time.Now().Unix() |
||||
|
editCont["`state`"] = 1 |
||||
|
err = systemRoleCont.EiteCont(map[string]interface{}{"`id`": receivedValue.Id}, editCont) |
||||
|
if err != nil { |
||||
|
publicmethod.Result(106, err, c) |
||||
|
return |
||||
|
} |
||||
|
} |
||||
|
publicmethod.Result(0, systemRoleCont, c) |
||||
|
} |
||||
|
|
||||
|
/* |
||||
|
* |
||||
|
@ 作者: 秦东 |
||||
|
@ 时间: 2022-11-09 08:41:20 |
||||
|
@ 功能: 角色列表 |
||||
|
@ 参数 |
||||
|
|
||||
|
# |
||||
|
|
||||
|
@ 返回值 |
||||
|
|
||||
|
# |
||||
|
*/ |
||||
|
func (a *ApiMethod) SystemRoleList(c *gin.Context) { |
||||
|
var receivedValue systemRoleContList |
||||
|
c.ShouldBindJSON(&receivedValue) |
||||
|
var systemRoleInfoList []modelssystempermission.SystemRole |
||||
|
gormDb := overall.CONSTANT_DB_System_Permission.Model(&modelssystempermission.SystemRole{}).Where("`state` BETWEEN ? AND ?", 1, 2) |
||||
|
if receivedValue.Name != "" { |
||||
|
gormDb = gormDb.Where("`name` LIKE ?", "%"+receivedValue.Name+"%") |
||||
|
} |
||||
|
err := gormDb.Order("`sort` ASC").Order("`id` DESC").Find(&systemRoleInfoList) |
||||
|
if err != nil { |
||||
|
publicmethod.Result(107, err, c) |
||||
|
return |
||||
|
} |
||||
|
publicmethod.Result(0, systemRoleInfoList, c) |
||||
|
} |
||||
|
|
||||
|
/* |
||||
|
* |
||||
|
@ 作者: 秦东 |
||||
|
@ 时间: 2022-11-09 08:52:56 |
||||
|
@ 功能: 编辑角色状态 |
||||
|
@ 参数 |
||||
|
|
||||
|
# |
||||
|
|
||||
|
@ 返回值 |
||||
|
|
||||
|
# |
||||
|
*/ |
||||
|
func (a *ApiMethod) EditSystemRoleState(c *gin.Context) { |
||||
|
var receivedValue publicmethod.PublicState |
||||
|
err := c.ShouldBindJSON(&receivedValue) |
||||
|
if err != nil { |
||||
|
publicmethod.Result(100, err, c) |
||||
|
return |
||||
|
} |
||||
|
if receivedValue.Id == "" { |
||||
|
publicmethod.Result(101, receivedValue, c) |
||||
|
return |
||||
|
} |
||||
|
if receivedValue.State == 0 { |
||||
|
receivedValue.State = 2 |
||||
|
} |
||||
|
wheAry := publicmethod.MapOut[string]() |
||||
|
wheAry["`id`"] = receivedValue.Id |
||||
|
var systemRoleCont modelssystempermission.SystemRole |
||||
|
err = systemRoleCont.GetCont(wheAry, "`state`") |
||||
|
if err != nil { |
||||
|
publicmethod.Result(107, err, c) |
||||
|
return |
||||
|
} |
||||
|
|
||||
|
if receivedValue.State != 3 { |
||||
|
editCont := publicmethod.MapOut[string]() |
||||
|
if receivedValue.State != systemRoleCont.State { |
||||
|
editCont["`state`"] = receivedValue.State |
||||
|
} |
||||
|
if len(editCont) > 0 { |
||||
|
editCont["`time`"] = time.Now().Unix() |
||||
|
err = systemRoleCont.EiteCont(wheAry, editCont) |
||||
|
} |
||||
|
} else { |
||||
|
if receivedValue.IsTrue != 1 { |
||||
|
editCont := publicmethod.MapOut[string]() |
||||
|
if receivedValue.State != systemRoleCont.State { |
||||
|
editCont["`state`"] = receivedValue.State |
||||
|
} |
||||
|
if len(editCont) > 0 { |
||||
|
editCont["`time`"] = time.Now().Unix() |
||||
|
err = systemRoleCont.EiteCont(wheAry, editCont) |
||||
|
} |
||||
|
} else { |
||||
|
err = systemRoleCont.DelCont(wheAry) |
||||
|
} |
||||
|
} |
||||
|
if err != nil { |
||||
|
publicmethod.Result(106, err, c) |
||||
|
return |
||||
|
} |
||||
|
publicmethod.Result(0, err, c) |
||||
|
} |
||||
@ -0,0 +1,63 @@ |
|||||
|
package modelssystempermission |
||||
|
|
||||
|
import ( |
||||
|
"key_performance_indicators/overall" |
||||
|
"strings" |
||||
|
) |
||||
|
|
||||
|
// 权限配置
|
||||
|
type RoleEmpower struct { |
||||
|
Id int64 `json:"id" gorm:"primaryKey;column:id;type:bigint(20) unsigned;not null;comment:Id;index"` |
||||
|
RoleId int64 `json:"roleid" gorm:"column:role_id;type:bigint(20) unsigned;default:0;not null;comment:行政组织"` |
||||
|
System string `json:"system" gorm:"column:system;type:varchar(255) ;comment:系统"` |
||||
|
PointId string `json:"pointid" gorm:"column:point_id;type:longtext;comment:权限点位"` |
||||
|
Operation string `json:"operation" gorm:"column:operation;type:longtext;comment:操作点位"` |
||||
|
State int `json:"state" gorm:"column:state;type:tinyint(1) unsigned;default:1;not null;comment:状态(1:启用;2:禁用;3:删除)"` |
||||
|
Level int `json:"level" gorm:"column:level;type:int(1) unsigned;default:1;not null;comment:授权范围等级(1:本部门;2:本分部;3:所有)"` |
||||
|
Time int64 `json:"time" gorm:"column:time;type:bigint(20) unsigned;default:0;not null;comment:创建时间"` |
||||
|
} |
||||
|
|
||||
|
func (RoleEmpower *RoleEmpower) TableName() string { |
||||
|
return "role_RoleEmpower" |
||||
|
} |
||||
|
|
||||
|
// 编辑内容
|
||||
|
func (cont *RoleEmpower) EiteCont(whereMap interface{}, saveData interface{}) (err error) { |
||||
|
err = overall.CONSTANT_DB_System_Permission.Model(&cont).Where(whereMap).Updates(saveData).Error |
||||
|
return |
||||
|
} |
||||
|
|
||||
|
// 获取内容
|
||||
|
func (cont *RoleEmpower) GetCont(whereMap interface{}, field ...string) (err error) { |
||||
|
gormDb := overall.CONSTANT_DB_System_Permission.Model(&cont) |
||||
|
if len(field) > 0 { |
||||
|
fieldStr := strings.Join(field, ",") |
||||
|
gormDb = gormDb.Select(fieldStr) |
||||
|
} |
||||
|
gormDb = gormDb.Where(whereMap) |
||||
|
err = gormDb.First(&cont).Error |
||||
|
return |
||||
|
} |
||||
|
|
||||
|
// 根据条件获取总数
|
||||
|
func (cont *RoleEmpower) CountCont(whereMap interface{}) (countId int64) { |
||||
|
overall.CONSTANT_DB_System_Permission.Model(&cont).Where(whereMap).Count(&countId) |
||||
|
return |
||||
|
} |
||||
|
|
||||
|
// 读取全部信息
|
||||
|
func (cont *RoleEmpower) ContMap(whereMap interface{}, field ...string) (countAry []RoleEmpower, err error) { |
||||
|
gormDb := overall.CONSTANT_DB_System_Permission.Model(&cont) |
||||
|
if len(field) > 0 { |
||||
|
fieldStr := strings.Join(field, ",") |
||||
|
gormDb = gormDb.Select(fieldStr) |
||||
|
} |
||||
|
err = gormDb.Where(whereMap).Find(&countAry).Error |
||||
|
return |
||||
|
} |
||||
|
|
||||
|
// 删除内容
|
||||
|
func (cont *RoleEmpower) DelCont(whereMap interface{}) (err error) { |
||||
|
err = overall.CONSTANT_DB_System_Permission.Where(whereMap).Delete(&cont).Error |
||||
|
return |
||||
|
} |
||||
@ -0,0 +1,60 @@ |
|||||
|
package modelssystempermission |
||||
|
|
||||
|
import ( |
||||
|
"key_performance_indicators/overall" |
||||
|
"strings" |
||||
|
) |
||||
|
|
||||
|
// 系统角色表
|
||||
|
type SystemRole struct { |
||||
|
Id int64 `json:"id" gorm:"primaryKey;column:id;type:bigint(20) unsigned;not null;comment:Id;index"` |
||||
|
Name string `json:"name" gorm:"column:name;type:varchar(255) ;comment:系统名称"` |
||||
|
State int `json:"state" gorm:"column:state;type:tinyint(1) unsigned;default:1;not null;comment:状态(1:启用;2:禁用;3:删除)"` |
||||
|
Time int64 `json:"time" gorm:"column:time;type:bigint(20) unsigned;default:0;not null;comment:创建时间"` |
||||
|
Sort int `json:"sort" gorm:"column:sort;type:int(5) unsigned;default:50;not null;comment:排序"` |
||||
|
} |
||||
|
|
||||
|
func (SystemRole *SystemRole) TableName() string { |
||||
|
return "system_role" |
||||
|
} |
||||
|
|
||||
|
// 编辑内容
|
||||
|
func (cont *SystemRole) EiteCont(whereMap interface{}, saveData interface{}) (err error) { |
||||
|
err = overall.CONSTANT_DB_System_Permission.Model(&cont).Where(whereMap).Updates(saveData).Error |
||||
|
return |
||||
|
} |
||||
|
|
||||
|
// 获取内容
|
||||
|
func (cont *SystemRole) GetCont(whereMap interface{}, field ...string) (err error) { |
||||
|
gormDb := overall.CONSTANT_DB_System_Permission.Model(&cont) |
||||
|
if len(field) > 0 { |
||||
|
fieldStr := strings.Join(field, ",") |
||||
|
gormDb = gormDb.Select(fieldStr) |
||||
|
} |
||||
|
gormDb = gormDb.Where(whereMap) |
||||
|
err = gormDb.First(&cont).Error |
||||
|
return |
||||
|
} |
||||
|
|
||||
|
// 根据条件获取总数
|
||||
|
func (cont *SystemRole) CountCont(whereMap interface{}) (countId int64) { |
||||
|
overall.CONSTANT_DB_System_Permission.Model(&cont).Where(whereMap).Count(&countId) |
||||
|
return |
||||
|
} |
||||
|
|
||||
|
// 读取全部信息
|
||||
|
func (cont *SystemRole) ContMap(whereMap interface{}, field ...string) (countAry []SystemRole, err error) { |
||||
|
gormDb := overall.CONSTANT_DB_System_Permission.Model(&cont) |
||||
|
if len(field) > 0 { |
||||
|
fieldStr := strings.Join(field, ",") |
||||
|
gormDb = gormDb.Select(fieldStr) |
||||
|
} |
||||
|
err = gormDb.Where(whereMap).Find(&countAry).Error |
||||
|
return |
||||
|
} |
||||
|
|
||||
|
// 删除内容
|
||||
|
func (cont *SystemRole) DelCont(whereMap interface{}) (err error) { |
||||
|
err = overall.CONSTANT_DB_System_Permission.Where(whereMap).Delete(&cont).Error |
||||
|
return |
||||
|
} |
||||
Loading…
Reference in new issue