13 changed files with 751 additions and 7 deletions
@ -0,0 +1,334 @@ |
|||||
|
package honoraryArchives |
||||
|
|
||||
|
import ( |
||||
|
"fmt" |
||||
|
"key_performance_indicators/middleware/snowflake" |
||||
|
"key_performance_indicators/models" |
||||
|
"key_performance_indicators/overall" |
||||
|
"key_performance_indicators/overall/publicmethod" |
||||
|
"strconv" |
||||
|
"time" |
||||
|
|
||||
|
"github.com/gin-gonic/gin" |
||||
|
"gorm.io/gorm" |
||||
|
) |
||||
|
|
||||
|
//荣誉列表
|
||||
|
func (a *ApiMethod) HonorList(c *gin.Context) { |
||||
|
var requestData honorListKey |
||||
|
c.ShouldBindJSON(&requestData) |
||||
|
var honorsList []models.HonoraryArchives |
||||
|
gormDb := overall.CONSTANT_DB_MANAGE_ARCHIVES.Model(&models.HonoraryArchives{}).Where("state BETWEEN ? AND ?", 1, 2) |
||||
|
if requestData.Name != "" { |
||||
|
gormDb = gormDb.Where("`name` LIKE ?", "%"+requestData.Name+"%") |
||||
|
} |
||||
|
if requestData.IssuingAgency != "" { |
||||
|
gormDb = gormDb.Where("`issuing_unit` LIKE ?", "%"+requestData.IssuingAgency+"%") |
||||
|
} |
||||
|
if requestData.Carrier != 0 { |
||||
|
gormDb = gormDb.Where("carrier = ?", requestData.Carrier) |
||||
|
} |
||||
|
if requestData.AwardTimeBegin != "" && requestData.AwardTimeEnd != "" { |
||||
|
timeBegin := fmt.Sprintf("%v 00:00:00", requestData.AwardTimeBegin) |
||||
|
timeEnd := fmt.Sprintf("%v 23:59:59", requestData.AwardTimeEnd) |
||||
|
gormDb = gormDb.Where("`award_time` BETWEEN ?", timeBegin, timeEnd) |
||||
|
} else if requestData.AwardTimeBegin != "" && requestData.AwardTimeEnd == "" { |
||||
|
timeBegin := fmt.Sprintf("%v 00:00:00", requestData.AwardTimeBegin) |
||||
|
timeEnd := fmt.Sprintf("%v 23:59:59", requestData.AwardTimeBegin) |
||||
|
gormDb = gormDb.Where("`award_time` BETWEEN ?", timeBegin, timeEnd) |
||||
|
} else if requestData.AwardTimeBegin == "" && requestData.AwardTimeEnd != "" { |
||||
|
timeBegin := fmt.Sprintf("%v 00:00:00", requestData.AwardTimeEnd) |
||||
|
timeEnd := fmt.Sprintf("%v 23:59:59", requestData.AwardTimeEnd) |
||||
|
gormDb = gormDb.Where("`award_time` BETWEEN ?", timeBegin, timeEnd) |
||||
|
} |
||||
|
if requestData.Organize != "" { |
||||
|
gormDb = gormDb.Where("organization = ?", requestData.Organize) |
||||
|
} |
||||
|
if requestData.UserKey != "" { |
||||
|
gormDb = gormDb.Where("userid = ?", requestData.UserKey) |
||||
|
} |
||||
|
var total int64 |
||||
|
totalErr := gormDb.Count(&total).Error |
||||
|
if totalErr != nil { |
||||
|
total = 0 |
||||
|
} |
||||
|
gormDb = publicmethod.PageTurningSettings(gormDb, requestData.Page, requestData.PageSize) |
||||
|
err := gormDb.Order("`id` DESC").Find(&honorsList).Error |
||||
|
if err != nil { |
||||
|
publicmethod.Result(105, err, c) |
||||
|
return |
||||
|
} |
||||
|
publicmethod.ResultList(0, requestData.Page, requestData.PageSize, total, int64(len(honorsList)), honorsList, c) |
||||
|
} |
||||
|
|
||||
|
//添加荣誉
|
||||
|
func (a *ApiMethod) AddHonorCont(c *gin.Context) { |
||||
|
var requestData addHonorCont //添加荣誉字段
|
||||
|
c.ShouldBindJSON(&requestData) |
||||
|
if requestData.Name == "" || requestData.IssuingAgency == "" || requestData.AwardTime == "" { |
||||
|
publicmethod.Result(101, requestData, c) |
||||
|
return |
||||
|
} |
||||
|
if requestData.Carrier == 0 { |
||||
|
publicmethod.Result(101, requestData, c) |
||||
|
return |
||||
|
} |
||||
|
var uuId int64 = 0 |
||||
|
snowflakeId, snowflakeErr := snowflake.NewWorker(1) |
||||
|
if snowflakeErr != nil { |
||||
|
uuId = publicmethod.TableNumber() |
||||
|
} else { |
||||
|
uuId = snowflakeId.GetId() |
||||
|
} |
||||
|
var honorCont models.HonoraryArchives |
||||
|
honorCont.Id = uuId |
||||
|
honorCont.Name = requestData.Name //荣誉名称"`
|
||||
|
honorCont.IssuingUnit = requestData.IssuingAgency //发放单位"`
|
||||
|
honorCont.Carrier = int64(requestData.Carrier) //载体"`
|
||||
|
awardTime, _ := publicmethod.DateToTimeStamp(fmt.Sprintf("%v 12:00:00", requestData.AwardTime)) |
||||
|
honorCont.AwardTime = awardTime //获奖时间"`
|
||||
|
if requestData.EfficientDate != "" { |
||||
|
termvalidity, _ := publicmethod.DateToTimeStamp(fmt.Sprintf("%v 12:00:00", requestData.EfficientDate)) |
||||
|
if termvalidity <= awardTime { |
||||
|
publicmethod.Result(1, requestData, c, "有效日期必须晚于获奖日期!") |
||||
|
return |
||||
|
} |
||||
|
honorCont.TermOfValidity = termvalidity //有效期限"`
|
||||
|
} |
||||
|
|
||||
|
honorCont.Contet = requestData.Remark //备注"`
|
||||
|
if requestData.Organize != "" { |
||||
|
organizationId, _ := strconv.ParseInt(requestData.Organize, 10, 64) |
||||
|
honorCont.Organization = organizationId //归属行政组织"`
|
||||
|
} |
||||
|
if requestData.UserKey != "" { |
||||
|
userId, _ := strconv.ParseInt(requestData.UserKey, 10, 64) |
||||
|
honorCont.Userid = userId //归属人员"`
|
||||
|
} |
||||
|
honorCont.Time = time.Now().Unix() //创建时间"`
|
||||
|
honorCont.State = 1 //状态(1:启用;2:禁用;3:删除)"`
|
||||
|
if len(requestData.ImgUrl) > 0 { |
||||
|
var imgList []models.PhotosGallery //图片档案
|
||||
|
for _, v := range requestData.ImgUrl { |
||||
|
var imgCont models.PhotosGallery |
||||
|
imgCont.Url = v.Url //图片地址"`
|
||||
|
imgCont.ImgPath = v.Imgpath //物理地址"`
|
||||
|
imgCont.Name = v.Name //文档名称"`
|
||||
|
imgCont.FileSize = v.FileSize //文档大小"`
|
||||
|
imgCont.Time = time.Now().Unix() //创建时间"`
|
||||
|
imgCont.AscriptionId = uuId //归属"`
|
||||
|
imgCont.AscriptionDataSheet = "honorary_archives" //归属哪个数据表"`
|
||||
|
imgCont.State = 1 //状态(1:启用;2:禁用;3:删除)"`
|
||||
|
imgList = append(imgList, imgCont) |
||||
|
} |
||||
|
addErr := overall.CONSTANT_DB_MANAGE_ARCHIVES.Transaction(func(tx *gorm.DB) error { |
||||
|
if err := tx.Create(&honorCont).Error; err != nil { |
||||
|
// 返回任何错误都会回滚事务
|
||||
|
return err |
||||
|
} |
||||
|
if err := tx.Create(&imgList).Error; err != nil { |
||||
|
// 返回任何错误都会回滚事务
|
||||
|
return err |
||||
|
} |
||||
|
return nil |
||||
|
}) |
||||
|
if addErr != nil { |
||||
|
publicmethod.Result(104, addErr.Error(), c) |
||||
|
} else { |
||||
|
publicmethod.Result(0, addErr, c) |
||||
|
} |
||||
|
} else { |
||||
|
addErr := overall.CONSTANT_DB_MANAGE_ARCHIVES.Create(&honorCont) |
||||
|
if addErr != nil { |
||||
|
publicmethod.Result(104, addErr, c) |
||||
|
} else { |
||||
|
publicmethod.Result(0, addErr, c) |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
//编辑荣誉
|
||||
|
func (a *ApiMethod) EidyHonorCont(c *gin.Context) { |
||||
|
var requestData eidtHonorCont |
||||
|
c.ShouldBindJSON(&requestData) |
||||
|
if requestData.Id == "" || requestData.Name == "" || requestData.IssuingAgency == "" || requestData.AwardTime == "" { |
||||
|
publicmethod.Result(101, requestData, c) |
||||
|
return |
||||
|
} |
||||
|
if requestData.Carrier == 0 { |
||||
|
publicmethod.Result(101, requestData, c) |
||||
|
return |
||||
|
} |
||||
|
where := publicmethod.MapOut[string]() |
||||
|
where["id"] = requestData.Id |
||||
|
//原信息
|
||||
|
var honContOld models.HonoraryArchives |
||||
|
err := honContOld.GetCont(where) |
||||
|
if err != nil { |
||||
|
publicmethod.Result(107, err, c) |
||||
|
return |
||||
|
} |
||||
|
//要修改的内容
|
||||
|
saveData := publicmethod.MapOut[string]() |
||||
|
if requestData.Name != "" && requestData.Name != honContOld.Name { |
||||
|
saveData["name"] = requestData.Name |
||||
|
} |
||||
|
if requestData.IssuingAgency != "" && requestData.IssuingAgency != honContOld.IssuingUnit { |
||||
|
saveData["issuing_unit"] = requestData.IssuingAgency |
||||
|
} |
||||
|
if requestData.Carrier != honContOld.Carrier { |
||||
|
saveData["carrier"] = requestData.Carrier |
||||
|
} |
||||
|
var awardTime int64 = 0 |
||||
|
if requestData.AwardTime != "" { |
||||
|
awardTime, _ = publicmethod.DateToTimeStamp(fmt.Sprintf("%v 12:00:00", requestData.AwardTime)) |
||||
|
if awardTime != honContOld.AwardTime { |
||||
|
saveData["award_time"] = awardTime |
||||
|
} |
||||
|
} |
||||
|
if requestData.EfficientDate != "" { |
||||
|
efficientDate, _ := publicmethod.DateToTimeStamp(fmt.Sprintf("%v 12:00:00", requestData.EfficientDate)) |
||||
|
if efficientDate != honContOld.TermOfValidity { |
||||
|
if awardTime != 0 && awardTime >= efficientDate { |
||||
|
publicmethod.Result(1, requestData, c, "有效日期必须晚于获奖日期!") |
||||
|
return |
||||
|
} else { |
||||
|
saveData["award_time"] = efficientDate |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
} |
||||
|
if requestData.Organize != "" { |
||||
|
organizationId, _ := strconv.ParseInt(requestData.Organize, 10, 64) |
||||
|
if organizationId != honContOld.Organization { |
||||
|
saveData["organization"] = organizationId |
||||
|
} |
||||
|
} |
||||
|
if requestData.UserKey != "" { |
||||
|
userId, _ := strconv.ParseInt(requestData.UserKey, 10, 64) |
||||
|
if userId != honContOld.Userid { |
||||
|
saveData["userid"] = userId |
||||
|
} |
||||
|
} |
||||
|
if requestData.Remark != "" && requestData.Remark != honContOld.Contet { |
||||
|
saveData["contet"] = requestData.Remark |
||||
|
} |
||||
|
var imgUrlListNoId []models.PhotosGallery |
||||
|
var pldImgId []int64 |
||||
|
if len(requestData.ImgUrl) > 0 { |
||||
|
for _, v := range requestData.ImgUrl { |
||||
|
if v.Id != "" { |
||||
|
oldIdInt, _ := strconv.ParseInt(v.Id, 10, 64) |
||||
|
if publicmethod.IsInTrue[int64](oldIdInt, pldImgId) == false { |
||||
|
pldImgId = append(pldImgId, oldIdInt) |
||||
|
} |
||||
|
} else { |
||||
|
var imgCont models.PhotosGallery |
||||
|
imgCont.Url = v.Url //图片地址"`
|
||||
|
imgCont.ImgPath = v.Imgpath //物理地址"`
|
||||
|
imgCont.Name = v.Name //文档名称"`
|
||||
|
imgCont.FileSize = v.FileSize //文档大小"`
|
||||
|
imgCont.Time = time.Now().Unix() //创建时间"`
|
||||
|
imgCont.AscriptionId = honContOld.Id //归属"`
|
||||
|
imgCont.AscriptionDataSheet = "honorary_archives" //归属拿个数据表"`
|
||||
|
imgCont.State = 1 //状态(1:启用;2:禁用;3:删除)"`
|
||||
|
imgUrlListNoId = append(imgUrlListNoId, imgCont) |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
if len(imgUrlListNoId) > 0 { |
||||
|
var imgList models.PhotosGallery |
||||
|
saveErr := overall.CONSTANT_DB_MANAGE_ARCHIVES.Transaction(func(tx *gorm.DB) error { |
||||
|
if len(pldImgId) > 0 { |
||||
|
if err := tx.Not(map[string]interface{}{"`id`": pldImgId}).Where(map[string]interface{}{"`ascription_id`": requestData.Id, "`ascription_data_sheet`": "honorary_archives"}).Delete(&imgList).Error; err != nil { |
||||
|
return err |
||||
|
} |
||||
|
} else { |
||||
|
if err := tx.Where(map[string]interface{}{"`ascription_id`": requestData.Id, "`ascription_data_sheet`": "honorary_archives"}).Delete(&imgList).Error; err != nil { |
||||
|
return err |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
saveData["time"] = time.Now().Unix() |
||||
|
|
||||
|
if err := tx.Model(&models.HonoraryArchives{}).Where(where).Updates(&saveData).Error; err != nil { |
||||
|
// 返回任何错误都会回滚事务
|
||||
|
return err |
||||
|
} |
||||
|
|
||||
|
if err := tx.Create(&imgUrlListNoId).Error; err != nil { |
||||
|
// 返回任何错误都会回滚事务
|
||||
|
return err |
||||
|
} |
||||
|
|
||||
|
return nil |
||||
|
}) |
||||
|
if saveErr == nil { |
||||
|
publicmethod.Result(0, err, c) |
||||
|
} else { |
||||
|
publicmethod.Result(106, err, c) |
||||
|
} |
||||
|
|
||||
|
} else { |
||||
|
saveData["time"] = time.Now().Unix() |
||||
|
saveErr := honContOld.EiteCont(where, saveData) |
||||
|
if saveErr == nil { |
||||
|
var imgList models.PhotosGallery |
||||
|
if len(pldImgId) > 0 { |
||||
|
overall.CONSTANT_DB_MANAGE_ARCHIVES.Not(map[string]interface{}{"`id`": pldImgId, "`ascription_id`": requestData.Id, "`ascription_data_sheet`": "honorary_archives"}).Delete(&imgList) |
||||
|
} else { |
||||
|
imgList.DelCont(map[string]interface{}{"ascription_id": requestData.Id, "ascription_data_sheet": "honorary_archives"}) |
||||
|
} |
||||
|
publicmethod.Result(0, err, c) |
||||
|
} else { |
||||
|
publicmethod.Result(106, err, c) |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
//编辑状态
|
||||
|
func (a *ApiMethod) EidyHonorContState(c *gin.Context) { |
||||
|
var requestData publicmethod.PublicState |
||||
|
c.ShouldBindJSON(&requestData) |
||||
|
if requestData.Id == "" { |
||||
|
publicmethod.Result(101, requestData, c) |
||||
|
return |
||||
|
} |
||||
|
if requestData.State == 0 { |
||||
|
requestData.State = 1 |
||||
|
} |
||||
|
if requestData.IsTrue == 0 { |
||||
|
requestData.IsTrue = 2 |
||||
|
} |
||||
|
where := publicmethod.MapOut[string]() |
||||
|
where["id"] = requestData.Id |
||||
|
var carrierTypeCont models.HonoraryArchives |
||||
|
judgeErr := carrierTypeCont.GetCont(where, "`id`") |
||||
|
if judgeErr != nil { |
||||
|
publicmethod.Result(107, judgeErr, c) |
||||
|
return |
||||
|
} |
||||
|
if requestData.State != 3 { |
||||
|
err := carrierTypeCont.EiteCont(where, map[string]interface{}{"`state`": requestData.State}) |
||||
|
if err != nil { |
||||
|
publicmethod.Result(106, err, c) |
||||
|
return |
||||
|
} |
||||
|
} else { |
||||
|
if requestData.IsTrue == 1 { |
||||
|
err := carrierTypeCont.DelCont(where) |
||||
|
if err != nil { |
||||
|
publicmethod.Result(106, err, c) |
||||
|
return |
||||
|
} |
||||
|
} else { |
||||
|
err := carrierTypeCont.EiteCont(where, map[string]interface{}{"`state`": requestData.State}) |
||||
|
if err != nil { |
||||
|
publicmethod.Result(106, err, c) |
||||
|
return |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
publicmethod.Result(0, carrierTypeCont, c) |
||||
|
} |
||||
@ -0,0 +1,31 @@ |
|||||
|
package honorsRoute |
||||
|
|
||||
|
import ( |
||||
|
"key_performance_indicators/api/version1" |
||||
|
|
||||
|
"github.com/gin-gonic/gin" |
||||
|
) |
||||
|
|
||||
|
//荣誉墙
|
||||
|
func (a *ApiRouter) RouterGroup(router *gin.RouterGroup) { |
||||
|
apiRouter := router.Group("honors") |
||||
|
|
||||
|
var methodBinding = version1.AppApiEntry.HonorsApi |
||||
|
{ |
||||
|
apiRouter.GET("", methodBinding.Index) //入口
|
||||
|
apiRouter.POST("", methodBinding.Index) //入口
|
||||
|
apiRouter.POST("honorlist", methodBinding.HonorList) //荣誉列表
|
||||
|
apiRouter.POST("addhonorcont", methodBinding.AddHonorCont) //添加荣誉
|
||||
|
apiRouter.POST("eidyhonorcont", methodBinding.EidyHonorCont) //编辑荣誉
|
||||
|
apiRouter.POST("eidyhonorcontstate", methodBinding.EidyHonorContState) //编辑荣誉状态
|
||||
|
|
||||
|
//载体类型
|
||||
|
apiRouter.POST("carrierlist", methodBinding.CarrierList) //载体类型列表
|
||||
|
apiRouter.POST("addcarrier", methodBinding.AddCarrier) //添加载体类型
|
||||
|
apiRouter.POST("eidycarrier", methodBinding.EidyCarrier) //编辑载体类型
|
||||
|
apiRouter.POST("eidycarrierstate", methodBinding.EidyCarrierState) //编辑载体类型状态
|
||||
|
|
||||
|
// 查看图片
|
||||
|
apiRouter.POST("reviewimage", methodBinding.ReviewImage) // 查看图片
|
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,82 @@ |
|||||
|
package configDatabase |
||||
|
|
||||
|
import ( |
||||
|
"fmt" |
||||
|
|
||||
|
"gorm.io/driver/mysql" |
||||
|
"gorm.io/gorm" |
||||
|
"gorm.io/gorm/logger" |
||||
|
) |
||||
|
|
||||
|
type MysqlSetUp struct { |
||||
|
MasterMysql MasterMysqlSetUp `mapstructure:"master" json:"master" yaml:"master"` //主数据库
|
||||
|
//其他数据库依次添加
|
||||
|
WechatMysql MasterMysqlSetUp `mapstructure:"wechat" json:"wechat" yaml:"wechat"` //微信数据库
|
||||
|
HrMysql MasterMysqlSetUp `mapstructure:"hrdatabase" json:"hrdatabase" yaml:"hrdatabase"` //HR数据库
|
||||
|
FileBookDate MasterMysqlSetUp `mapstructure:"fileBookDate" json:"fileBookDate" yaml:"fileBookDate"` //文档属性数据库
|
||||
|
ErrorSubjectDate MasterMysqlSetUp `mapstructure:"errorSubjectDate" json:"errorSubjectDate" yaml:"errorSubjectDate"` //错题库
|
||||
|
MyTestDate MasterMysqlSetUp `mapstructure:"myTestDate" json:"myTestDate" yaml:"myTestDate"` //自我测验
|
||||
|
ImageTextDate MasterMysqlSetUp `mapstructure:"imageTextDate" json:"imageTextDate" yaml:"imageTextDate"` //图文信息数据库
|
||||
|
ScoringDetailsDate MasterMysqlSetUp `mapstructure:"scoringDetailsDate" json:"scoringDetailsDate" yaml:"scoringDetailsDate"` //计分明细数据库
|
||||
|
QuestionsAnswersDate MasterMysqlSetUp `mapstructure:"questionsAnswersDate" json:"questionsAnswersDate" yaml:"questionsAnswersDate"` //趣味问答
|
||||
|
BillboardDate MasterMysqlSetUp `mapstructure:"billboardDate" json:"billboardDate" yaml:"billboardDate"` //风云榜统计数据库
|
||||
|
HealthReportDate MasterMysqlSetUp `mapstructure:"healthReportDate" json:"healthReportDate" yaml:"healthReportDate"` //健康上报数据库
|
||||
|
KpiDate MasterMysqlSetUp `mapstructure:"kpiDate" json:"kpiDate" yaml:"kpiDate"` //绩效考核数据库
|
||||
|
WechatCallBackLogDate MasterMysqlSetUp `mapstructure:"wechatCallBackLogDate" json:"wechatCallBackLogDate" yaml:"wechatCallBackLogDate"` //企业微信回调记录
|
||||
|
Managearchives MasterMysqlSetUp `mapstructure:"managearchives" json:"managearchives" yaml:"managearchives"` //管理档案
|
||||
|
} |
||||
|
|
||||
|
type MasterMysqlSetUp struct { |
||||
|
UrlPath string `mapstructure:"url_path" json:"url_path" yaml:"url_path"` // 服务器地址
|
||||
|
Port int `mapstructure:"port" json:"port" yaml:"port"` // 端口
|
||||
|
Charset string `mapstructure:"charset" json:"charset" yaml:"charset"` // 编码方式
|
||||
|
ParseTime bool `mapstructure:"parseTime" json:"parseTime" yaml:"parseTime"` // 是否自动转换时间
|
||||
|
Loc string `mapstructure:"loc" json:"loc" yaml:"loc"` // 时区
|
||||
|
Name string `mapstructure:"name" json:"name" yaml:"name"` // 数据库名称
|
||||
|
UserName string `mapstructure:"username" json:"username" yaml:"username"` // 账号
|
||||
|
PassWord string `mapstructure:"password" json:"password" yaml:"password"` // 密码
|
||||
|
MaxIdleConns int `mapstructure:"max_idle_conns" json:"max_idle_conns" yaml:"max_idle_conns"` // 最大空闲数
|
||||
|
MaxOpenConns int `mapstructure:"max_open_conns" json:"max_open_conns" yaml:"max_open_conns"` // 最大链接数
|
||||
|
GormLog bool `mapstructure:"gorm_log" json:"gorm_log" yaml:"gorm_log"` // 是否开启Gorm全局日志
|
||||
|
} |
||||
|
|
||||
|
func (m *MasterMysqlSetUp) SqlDsn() (dsnStr string) { |
||||
|
dsnStr = fmt.Sprintf("%v:%v@tcp(%v:%v)/%v?charset=%v", m.UserName, m.PassWord, m.UrlPath, m.Port, m.Name, m.Charset) |
||||
|
if m.ParseTime == true { |
||||
|
dsnStr = fmt.Sprintf("%v:%v@tcp(%v:%v)/%v?charset=%v&parseTime=%v&loc=%v", m.UserName, m.PassWord, m.UrlPath, m.Port, m.Name, m.Charset, m.ParseTime, m.Loc) |
||||
|
} |
||||
|
return |
||||
|
} |
||||
|
|
||||
|
func (m *MasterMysqlSetUp) OpenSql() *gorm.DB { |
||||
|
sqlConfig := mysql.Config{ |
||||
|
DSN: m.SqlDsn(), // DSN
|
||||
|
DefaultStringSize: 255, // string 类型字段的默认长度
|
||||
|
DisableDatetimePrecision: true, // 禁用 datetime 精度,MySQL 5.6 之前的数据库不支持
|
||||
|
DontSupportRenameIndex: true, // 重命名索引时采用删除并新建的方式,MySQL 5.7 之前的数据库和 MariaDB 不支持重命名索引
|
||||
|
DontSupportRenameColumn: true, // 用 `change` 重命名列,MySQL 8 之前的数据库和 MariaDB 不支持重命名列
|
||||
|
SkipInitializeWithVersion: false, // 根据版本自动配置
|
||||
|
} |
||||
|
if m.GormLog == true { |
||||
|
if opDb, err := gorm.Open(mysql.New(sqlConfig), &gorm.Config{ |
||||
|
Logger: logger.Default.LogMode(logger.Info), |
||||
|
}); err != nil { |
||||
|
return nil |
||||
|
} else { |
||||
|
sqlDb, _ := opDb.DB() |
||||
|
sqlDb.SetMaxIdleConns(m.MaxIdleConns) |
||||
|
sqlDb.SetMaxOpenConns(m.MaxOpenConns) |
||||
|
return opDb |
||||
|
} |
||||
|
} else { |
||||
|
if opDb, err := gorm.Open(mysql.New(sqlConfig)); err != nil { |
||||
|
return nil |
||||
|
} else { |
||||
|
sqlDb, _ := opDb.DB() |
||||
|
sqlDb.SetMaxIdleConns(m.MaxIdleConns) |
||||
|
sqlDb.SetMaxOpenConns(m.MaxOpenConns) |
||||
|
return opDb |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,66 @@ |
|||||
|
package route |
||||
|
|
||||
|
import ( |
||||
|
"key_performance_indicators/apirouter" |
||||
|
"key_performance_indicators/identification/interceptor" |
||||
|
|
||||
|
"github.com/gin-gonic/gin" |
||||
|
) |
||||
|
|
||||
|
//初始化主路由
|
||||
|
func InitialRouter() *gin.Engine { |
||||
|
var router = gin.Default() |
||||
|
|
||||
|
//app默认相应
|
||||
|
appLoadRouterGroup := router.Group("") |
||||
|
{ |
||||
|
|
||||
|
// 跨域设置
|
||||
|
// router.Use(middleware.CrossDomainRequest()) // 如需跨域可以打开
|
||||
|
//app默认相应
|
||||
|
appLoadRouterGroup.GET("/", func(c *gin.Context) { |
||||
|
c.JSON(0, "通讯成功!") |
||||
|
}) |
||||
|
appLoadRouterGroup.POST("/", func(c *gin.Context) { |
||||
|
c.JSON(0, "通讯成功!") |
||||
|
}) |
||||
|
//实验路由
|
||||
|
|
||||
|
shiyanApi := apirouter.RouterGroupEntry.ShiyanApi |
||||
|
{ |
||||
|
shiyanApi.RouterGroup(appLoadRouterGroup) |
||||
|
} |
||||
|
//OAuth 2.0 授权
|
||||
|
oAuthEmpowerApi := apirouter.RouterGroupEntry.EmpowerRouter |
||||
|
{ |
||||
|
oAuthEmpowerApi.RouterGroup(appLoadRouterGroup) |
||||
|
} |
||||
|
//登录验证
|
||||
|
loginVerifyApi := apirouter.RouterGroupEntry.VerifyLogin |
||||
|
{ |
||||
|
loginVerifyApi.RouterGroup(appLoadRouterGroup) |
||||
|
} |
||||
|
|
||||
|
// 自定义测试
|
||||
|
mytestapi := apirouter.RouterGroupEntry.MyTest |
||||
|
{ |
||||
|
mytestapi.RouterGroup(appLoadRouterGroup) |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
//验证身份接口
|
||||
|
VerifyIdentity := router.Group("") |
||||
|
VerifyIdentity.Use(interceptor.AuthenticateUser()).Use(interceptor.VerifyUrl()) |
||||
|
{ |
||||
|
//v1版本接口
|
||||
|
version1Api := apirouter.RouterGroupEntry.HonorsSouteRouter |
||||
|
version1Api.RouterGroup(VerifyIdentity) |
||||
|
} |
||||
|
//Token身份验证
|
||||
|
VerifyIdentityToken := router.Group("") |
||||
|
VerifyIdentityToken.Use(interceptor.IdentificationToken()) |
||||
|
{ |
||||
|
|
||||
|
} |
||||
|
return router |
||||
|
} |
||||
@ -0,0 +1,47 @@ |
|||||
|
package models |
||||
|
|
||||
|
import ( |
||||
|
"key_performance_indicators/overall" |
||||
|
"strings" |
||||
|
) |
||||
|
|
||||
|
//图片库
|
||||
|
type PhotosGallery struct { |
||||
|
Id int64 `json:"id" gorm:"primaryKey;column:id;type:bigint(20) unsigned;not null;comment:ID"` |
||||
|
Url string `json:"url" gorm:"column:url;type:varchar(255) unsigned;default:'';not null;comment:图片地址"` |
||||
|
ImgPath string `json:"imgpath" gorm:"column:img_path;type:varchar(255) unsigned;default:'';not null;comment:物理地址"` |
||||
|
Name string `json:"name" gorm:"column:name;type:varchar(255) unsigned;default:'';not null;comment:文档名称"` |
||||
|
FileSize string `json:"filesize" gorm:"column:file_size;type:varchar(255) unsigned;default:'';not null;comment:文档大小"` |
||||
|
Time int64 `json:"time" gorm:"column:time;type:bigint(20) unsigned;default:0;not null;comment:创建时间"` |
||||
|
AscriptionId int64 `json:"ascriptionid" gorm:"column:ascription_id;type:bigint(20) unsigned;default:0;not null;comment:归属"` |
||||
|
AscriptionDataSheet string `json:"ascriptiondatasheet" gorm:"column:ascription_data_sheet;type:varchar(255) unsigned;default:'';not null;comment:归属哪个数据表"` |
||||
|
State int `json:"state" gorm:"column:state;type:tinyint(1) unsigned;default:1;not null;comment:状态(1:启用;2:禁用;3:删除)"` |
||||
|
} |
||||
|
|
||||
|
func (PhotosGallery *PhotosGallery) TableName() string { |
||||
|
return "photos_gallery" |
||||
|
} |
||||
|
|
||||
|
//编辑图片库内容
|
||||
|
func (cont *PhotosGallery) EiteCont(whereMap interface{}, saveData interface{}) (err error) { |
||||
|
err = overall.CONSTANT_DB_MANAGE_ARCHIVES.Model(&cont).Where(whereMap).Updates(saveData).Error |
||||
|
return |
||||
|
} |
||||
|
|
||||
|
//获取图片库内容
|
||||
|
func (cont *PhotosGallery) GetCont(whereMap interface{}, field ...string) (err error) { |
||||
|
gormDb := overall.CONSTANT_DB_MANAGE_ARCHIVES.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 *PhotosGallery) DelCont(whereMap interface{}) (err error) { |
||||
|
err = overall.CONSTANT_DB_MANAGE_ARCHIVES.Where(whereMap).Delete(&cont).Error |
||||
|
return |
||||
|
} |
||||
@ -0,0 +1,47 @@ |
|||||
|
package models |
||||
|
|
||||
|
import ( |
||||
|
"key_performance_indicators/overall" |
||||
|
"strings" |
||||
|
) |
||||
|
|
||||
|
//图片库
|
||||
|
type PhotosGallery struct { |
||||
|
Id int64 `json:"id" gorm:"primaryKey;column:id;type:bigint(20) unsigned;not null;comment:ID"` |
||||
|
Url string `json:"url" gorm:"column:url;type:varchar(255) unsigned;default:'';not null;comment:图片地址"` |
||||
|
ImgPath string `json:"imgpath" gorm:"column:img_path;type:varchar(255) unsigned;default:'';not null;comment:物理地址"` |
||||
|
Name string `json:"name" gorm:"column:name;type:varchar(255) unsigned;default:'';not null;comment:文档名称"` |
||||
|
FileSize string `json:"filesize" gorm:"column:file_size;type:varchar(255) unsigned;default:'';not null;comment:文档大小"` |
||||
|
Time int64 `json:"time" gorm:"column:time;type:bigint(20) unsigned;default:0;not null;comment:创建时间"` |
||||
|
AscriptionId int64 `json:"ascriptionid" gorm:"column:ascription_id;type:bigint(20) unsigned;default:0;not null;comment:归属"` |
||||
|
AscriptionDataSheet string `json:"ascriptiondatasheet" gorm:"column:ascription_data_sheet;type:varchar(255) unsigned;default:'';not null;comment:归属哪个数据表"` |
||||
|
State int `json:"state" gorm:"column:state;type:tinyint(1) unsigned;default:1;not null;comment:状态(1:启用;2:禁用;3:删除)"` |
||||
|
} |
||||
|
|
||||
|
func (PhotosGallery *PhotosGallery) TableName() string { |
||||
|
return "photos_gallery" |
||||
|
} |
||||
|
|
||||
|
//编辑图片库内容
|
||||
|
func (cont *PhotosGallery) EiteCont(whereMap interface{}, saveData interface{}) (err error) { |
||||
|
err = overall.CONSTANT_DB_MANAGE_ARCHIVES.Model(&cont).Where(whereMap).Updates(saveData).Error |
||||
|
return |
||||
|
} |
||||
|
|
||||
|
//获取图片库内容
|
||||
|
func (cont *PhotosGallery) GetCont(whereMap interface{}, field ...string) (err error) { |
||||
|
gormDb := overall.CONSTANT_DB_MANAGE_ARCHIVES.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 *PhotosGallery) DelCont(whereMap interface{}) (err error) { |
||||
|
err = overall.CONSTANT_DB_MANAGE_ARCHIVES.Where(whereMap).Delete(&cont).Error |
||||
|
return |
||||
|
} |
||||
@ -0,0 +1,47 @@ |
|||||
|
package models |
||||
|
|
||||
|
import ( |
||||
|
"key_performance_indicators/overall" |
||||
|
"strings" |
||||
|
) |
||||
|
|
||||
|
//图片库
|
||||
|
type PhotosGallery struct { |
||||
|
Id int64 `json:"id" gorm:"primaryKey;column:id;type:bigint(20) unsigned;not null;comment:ID"` |
||||
|
Url string `json:"url" gorm:"column:url;type:varchar(255) unsigned;default:'';not null;comment:图片地址"` |
||||
|
ImgPath string `json:"imgpath" gorm:"column:img_path;type:varchar(255) unsigned;default:'';not null;comment:物理地址"` |
||||
|
Name string `json:"name" gorm:"column:name;type:varchar(255) unsigned;default:'';not null;comment:文档名称"` |
||||
|
FileSize string `json:"filesize" gorm:"column:file_size;type:varchar(255) unsigned;default:'';not null;comment:文档大小"` |
||||
|
Time int64 `json:"time" gorm:"column:time;type:bigint(20) unsigned;default:0;not null;comment:创建时间"` |
||||
|
AscriptionId int64 `json:"ascriptionid" gorm:"column:ascription_id;type:bigint(20) unsigned;default:0;not null;comment:归属"` |
||||
|
AscriptionDataSheet string `json:"ascriptiondatasheet" gorm:"column:ascription_data_sheet;type:varchar(255) unsigned;default:'';not null;comment:归属哪个数据表"` |
||||
|
State int `json:"state" gorm:"column:state;type:tinyint(1) unsigned;default:1;not null;comment:状态(1:启用;2:禁用;3:删除)"` |
||||
|
} |
||||
|
|
||||
|
func (PhotosGallery *PhotosGallery) TableName() string { |
||||
|
return "photos_gallery" |
||||
|
} |
||||
|
|
||||
|
//编辑图片库内容
|
||||
|
func (cont *PhotosGallery) EiteCont(whereMap interface{}, saveData interface{}) (err error) { |
||||
|
err = overall.CONSTANT_DB_MANAGE_ARCHIVES.Model(&cont).Where(whereMap).Updates(saveData).Error |
||||
|
return |
||||
|
} |
||||
|
|
||||
|
//获取图片库内容
|
||||
|
func (cont *PhotosGallery) GetCont(whereMap interface{}, field ...string) (err error) { |
||||
|
gormDb := overall.CONSTANT_DB_MANAGE_ARCHIVES.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 *PhotosGallery) DelCont(whereMap interface{}) (err error) { |
||||
|
err = overall.CONSTANT_DB_MANAGE_ARCHIVES.Where(whereMap).Delete(&cont).Error |
||||
|
return |
||||
|
} |
||||
@ -0,0 +1,47 @@ |
|||||
|
package models |
||||
|
|
||||
|
import ( |
||||
|
"key_performance_indicators/overall" |
||||
|
"strings" |
||||
|
) |
||||
|
|
||||
|
//图片库
|
||||
|
type PhotosGallery struct { |
||||
|
Id int64 `json:"id" gorm:"primaryKey;column:id;type:bigint(20) unsigned;not null;comment:ID"` |
||||
|
Url string `json:"url" gorm:"column:url;type:varchar(255) unsigned;default:'';not null;comment:图片地址"` |
||||
|
ImgPath string `json:"imgpath" gorm:"column:img_path;type:varchar(255) unsigned;default:'';not null;comment:物理地址"` |
||||
|
Name string `json:"name" gorm:"column:name;type:varchar(255) unsigned;default:'';not null;comment:文档名称"` |
||||
|
FileSize string `json:"filesize" gorm:"column:file_size;type:varchar(255) unsigned;default:'';not null;comment:文档大小"` |
||||
|
Time int64 `json:"time" gorm:"column:time;type:bigint(20) unsigned;default:0;not null;comment:创建时间"` |
||||
|
AscriptionId int64 `json:"ascriptionid" gorm:"column:ascription_id;type:bigint(20) unsigned;default:0;not null;comment:归属"` |
||||
|
AscriptionDataSheet string `json:"ascriptiondatasheet" gorm:"column:ascription_data_sheet;type:varchar(255) unsigned;default:'';not null;comment:归属哪个数据表"` |
||||
|
State int `json:"state" gorm:"column:state;type:tinyint(1) unsigned;default:1;not null;comment:状态(1:启用;2:禁用;3:删除)"` |
||||
|
} |
||||
|
|
||||
|
func (PhotosGallery *PhotosGallery) TableName() string { |
||||
|
return "photos_gallery" |
||||
|
} |
||||
|
|
||||
|
//编辑图片库内容
|
||||
|
func (cont *PhotosGallery) EiteCont(whereMap interface{}, saveData interface{}) (err error) { |
||||
|
err = overall.CONSTANT_DB_MANAGE_ARCHIVES.Model(&cont).Where(whereMap).Updates(saveData).Error |
||||
|
returnbang'din |
||||
|
} |
||||
|
|
||||
|
//获取图片库内容
|
||||
|
func (cont *PhotosGallery) GetCont(whereMap interface{}, field ...string) (err error) { |
||||
|
gormDb := overall.CONSTANT_DB_MANAGE_ARCHIVES.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 *PhotosGallery) DelCont(whereMap interface{}) (err error) { |
||||
|
err = overall.CONSTANT_DB_MANAGE_ARCHIVES.Where(whereMap).Delete(&cont).Error |
||||
|
return |
||||
|
} |
||||
@ -0,0 +1,47 @@ |
|||||
|
package models |
||||
|
|
||||
|
import ( |
||||
|
"key_performance_indicators/overall" |
||||
|
"strings" |
||||
|
) |
||||
|
|
||||
|
//图片库
|
||||
|
type PhotosGallery struct { |
||||
|
Id int64 `json:"id" gorm:"primaryKey;column:id;type:bigint(20) unsigned;not null;comment:ID"` |
||||
|
Url string `json:"url" gorm:"column:url;type:varchar(255) unsigned;default:'';not null;comment:图片地址"` |
||||
|
ImgPath string `json:"imgpath" gorm:"column:img_path;type:varchar(255) unsigned;default:'';not null;comment:物理地址"` |
||||
|
Name string `json:"name" gorm:"column:name;type:varchar(255) unsigned;default:'';not null;comment:文档名称"` |
||||
|
FileSize string `json:"filesize" gorm:"column:file_size;type:varchar(255) unsigned;default:'';not null;comment:文档大小"` |
||||
|
Time int64 `json:"time" gorm:"column:time;type:bigint(20) unsigned;default:0;not null;comment:创建时间"` |
||||
|
AscriptionId int64 `json:"ascriptionid" gorm:"column:ascription_id;type:bigint(20) unsigned;default:0;not null;comment:归属"` |
||||
|
AscriptionDataSheet string `json:"ascriptiondatasheet" gorm:"column:ascription_data_sheet;type:varchar(255) unsigned;default:'';not null;comment:归属哪个数据表"` |
||||
|
State int `json:"state" gorm:"column:state;type:tinyint(1) unsigned;default:1;not null;comment:状态(1:启用;2:禁用;3:删除)"` |
||||
|
} |
||||
|
|
||||
|
func (PhotosGallery *PhotosGallery) TableName() string { |
||||
|
return "photos_gallery" |
||||
|
} |
||||
|
|
||||
|
//编辑图片库内容
|
||||
|
func (cont *PhotosGallery) EiteCont(whereMap interface{}, saveData interface{}) (err error) { |
||||
|
err = overall.CONSTANT_DB_MANAGE_ARCHIVES.Model(&cont).Where(whereMap).Updates(saveData).Error |
||||
|
return |
||||
|
} |
||||
|
|
||||
|
//获取图片库内容
|
||||
|
func (cont *PhotosGallery) GetCont(whereMap interface{}, field ...string) (err error) { |
||||
|
gormDb := overall.CONSTANT_DB_MANAGE_ARCHIVES.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 *PhotosGallery) DelCont(whereMap interface{}) (err error) { |
||||
|
err = overall.CONSTANT_DB_MANAGE_ARCHIVES.Where(whereMap).Delete(&cont).Error |
||||
|
return |
||||
|
} |
||||
Loading…
Reference in new issue