123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206 |
- package fe_calendar
- import (
- "eta_gn/eta_api/global"
- "eta_gn/eta_api/utils"
- "fmt"
- "strings"
- "time"
- )
- const (
- MatterTypeFree = 1 // 事项类型-自定义事项
- MatterTypeEdb = 2 // 事项类型-基础指标
- MatterTypePredict = 3 // 事项类型-预测指标
- )
- type FeCalendarMatter struct {
- FeCalendarMatterId int `gorm:"primaryKey;column:fe_calendar_matter_id;type:int(10) unsigned;not null"` // 事项Id
- ChartPermissionId int `gorm:"index:idx_chart_permission_id;column:chart_permission_id;type:int(10) unsigned;not null;default:0"` // 品种Id
- ChartPermissionName string `gorm:"column:chart_permission_name;type:varchar(128);not null;default:''"` // 品种名称
- MatterMonth string `gorm:"index:idx_matter_month;column:matter_month;type:varchar(16);not null;default:''"` // 事项年月:格式2006-01
- MatterDate time.Time `gorm:"index:idx_matter_date;column:matter_date;type:date"` // 事项日期
- Title string `gorm:"column:title;type:varchar(255);not null;default:''"` // 标题
- MatterType int `gorm:"column:matter_type;type:tinyint(4) unsigned;not null;default:0"` // 事项类型:1-自定义事项;2-基础指标;3-预测指标
- EdbInfoId int `gorm:"column:edb_info_id;type:int(10) unsigned;not null;default:0"` // 指标Id
- EdbUniqueCode string `gorm:"column:edb_unique_code;type:varchar(128);not null;default:''"` // 指标唯一编码
- EdbCode string `gorm:"column:edb_code;type:varchar(128);not null;default:''"` // 指标编码
- FontColor string `gorm:"column:font_color;type:varchar(64);not null;default:''"` // 字体颜色
- FillingColor string `gorm:"column:filling_color;type:varchar(64);not null;default:''"` // 填充颜色
- FontBold int `gorm:"column:font_bold;type:tinyint(4) unsigned;not null;default:0"` // 字体加粗:0-否;1-是
- Sort int `gorm:"column:sort;type:int(10) unsigned;not null;default:0"` // 排序
- SysUserId int `gorm:"column:sys_user_id;type:int(10) unsigned;not null;default:0"` // 创建人Id
- SysUserName string `gorm:"column:sys_user_name;type:varchar(128);not null;default:''"` // 创建人姓名
- CreateTime time.Time `gorm:"column:create_time;type:datetime"` // 创建时间
- ModifyTime time.Time `gorm:"column:modify_time;type:datetime"` // 更新时间
- }
- var FeCalendarMatterCols = struct {
- FeCalendarMatterId string
- ChartPermissionId string
- ChartPermissionName string
- MatterMonth string
- MatterDate string
- Title string
- MatterType string
- EdbInfoId string
- EdbUniqueCode string
- EdbCode string
- FontColor string
- FillingColor string
- FontBold string
- Sort string
- SysUserId string
- SysUserName string
- CreateTime string
- ModifyTime string
- }{
- FeCalendarMatterId: "fe_calendar_matter_id",
- ChartPermissionId: "chart_permission_id",
- ChartPermissionName: "chart_permission_name",
- MatterMonth: "matter_month",
- MatterDate: "matter_date",
- Title: "title",
- MatterType: "matter_type",
- EdbInfoId: "edb_info_id",
- EdbUniqueCode: "edb_unique_code",
- EdbCode: "edb_code",
- FontColor: "font_color",
- FillingColor: "filling_color",
- FontBold: "font_bold",
- Sort: "sort",
- SysUserId: "sys_user_id",
- SysUserName: "sys_user_name",
- CreateTime: "create_time",
- ModifyTime: "modify_time",
- }
- func (m *FeCalendarMatter) TableName() string {
- return "fe_calendar_matter"
- }
- func (m *FeCalendarMatter) PrimaryId() string {
- return FeCalendarMatterCols.FeCalendarMatterId
- }
- func (m *FeCalendarMatter) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*FeCalendarMatter, err error) {
- fields := strings.Join(fieldArr, ",")
- if len(fieldArr) == 0 {
- fields = `*`
- }
- order := fmt.Sprintf(`ORDER BY %s DESC`, FeCalendarMatterCols.CreateTime)
- if orderRule != "" {
- order = ` ORDER BY ` + orderRule
- }
- sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s`, fields, m.TableName(), condition, order)
- err = global.DmSQL["data"].Raw(sql, pars...).Find(&items).Error
- return
- }
- type FeCalendarMatterItem struct {
- FeCalendarMatterId int `description:"事项ID"`
- ChartPermissionId int `description:"品种ID"`
- ChartPermissionName string `description:"品种名称"`
- MatterDate string `description:"事项日期"`
- Title string `description:"标题"`
- MatterType int `description:"事项类型:1-自定义事项;2-基础指标;3-预测指标"`
- EdbInfoId int `description:"指标ID"`
- EdbUniqueCode string `description:"指标唯一编码"`
- EdbCode string `description:"指标编码"`
- FontColor string `description:"字体颜色"`
- FillingColor string `description:"填充颜色"`
- FontBold int `description:"字体加粗:0-否;1-是"`
- Sort int `description:"排序"`
- }
- func FormatFeCalendarMatter2Item(origin *FeCalendarMatter) (item *FeCalendarMatterItem) {
- if origin == nil {
- return
- }
- item = new(FeCalendarMatterItem)
- item.FeCalendarMatterId = origin.FeCalendarMatterId
- item.ChartPermissionId = origin.ChartPermissionId
- item.ChartPermissionName = origin.ChartPermissionName
- item.MatterDate = utils.TimeTransferString(utils.FormatDate, origin.MatterDate)
- item.Title = origin.Title
- item.MatterType = origin.MatterType
- item.EdbInfoId = origin.EdbInfoId
- item.EdbUniqueCode = origin.EdbUniqueCode
- item.EdbCode = origin.EdbCode
- item.FontColor = origin.FontColor
- item.FillingColor = origin.FillingColor
- item.FontBold = origin.FontBold
- item.Sort = origin.Sort
- return
- }
- // FeCalendarMatterListReq 事项列表请求体
- type FeCalendarMatterListReq struct {
- ChartPermissionId int `form:"ChartPermissionId" description:"品种ID"`
- StartDate string `form:"StartDate" description:"开始日期"`
- EndDate string `form:"EndDate" description:"结束日期"`
- }
- // FeCalendarMatterListItem 事项列表
- type FeCalendarMatterListItem struct {
- Date string `description:"日期"`
- Matters []*FeCalendarMatterItem `description:"日期事项"`
- }
- // FeCalendarMatterSaveReq 保存事项请求体
- type FeCalendarMatterSaveReq struct {
- ChartPermissionId int `description:"品种ID"`
- MatterDate string `description:"日期"`
- Matters []*FeCalendarMatterSaveItem `description:"事项"`
- }
- type FeCalendarMatterSaveItem struct {
- FeCalendarMatterId int `description:"事项ID"`
- Title string `description:"标题"`
- MatterType int `description:"事项类型:1-自定义事项;2-基础指标;3-预测指标"`
- EdbInfoId int `description:"指标ID"`
- EdbUniqueCode string `description:"指标唯一编码"`
- EdbCode string `description:"指标编码"`
- FontColor string `description:"字体颜色"`
- FillingColor string `description:"填充颜色"`
- FontBold int `description:"字体加粗:0-否;1-是"`
- Sort int `description:"排序"`
- }
- func (m *FeCalendarMatter) Save(addMatters, editMatters, removeMatters []*FeCalendarMatter, updateCols []string) (err error) {
- tx := global.DmSQL["data"].Begin()
- defer func() {
- if err != nil {
- _ = tx.Rollback()
- return
- }
- _ = tx.Commit()
- }()
- if len(addMatters) > 0 {
- e := tx.CreateInBatches(addMatters, utils.MultiAddNum).Error
- if e != nil {
- err = fmt.Errorf("insert multi err: %v", e)
- return
- }
- }
- if len(editMatters) > 0 {
- for _, v := range editMatters {
- e := tx.Select(updateCols).Updates(v).Error
- if e != nil {
- err = fmt.Errorf("update err: %v", e)
- return
- }
- }
- }
- if len(removeMatters) > 0 {
- sql := fmt.Sprintf(`DELETE FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.PrimaryId())
- for _, v := range removeMatters {
- e := tx.Exec(sql, v.FeCalendarMatterId).Error
- if e != nil {
- err = fmt.Errorf("remove exec err: %v", e)
- return
- }
- }
- }
- return
- }
|