|
@@ -0,0 +1,246 @@
|
|
|
+package models
|
|
|
+
|
|
|
+import (
|
|
|
+ "eta/eta_hub/global"
|
|
|
+ "eta/eta_hub/utils"
|
|
|
+ "fmt"
|
|
|
+ "strings"
|
|
|
+ "time"
|
|
|
+)
|
|
|
+
|
|
|
+type AssessmentForm struct {
|
|
|
+ AssessmentFormId int `gorm:"column:assessment_form_id;primaryKey;autoIncrement"`
|
|
|
+ FormCode string `description:"单号"`
|
|
|
+ ResearcherId int `description:"研究员ID"`
|
|
|
+ ResearcherAdminId int `description:"研究员用户ID"`
|
|
|
+ ResearcherName string `description:"研究员姓名"`
|
|
|
+ VarietyId int `description:"品种ID"`
|
|
|
+ VarietyCode string `description:"品种编码"`
|
|
|
+ VarietyName string `description:"品种名称"`
|
|
|
+ WeekTime string `description:"周度(格式:202501,202502)"`
|
|
|
+ WeekStart time.Time `description:"当周开始日期"`
|
|
|
+ WeekEnd time.Time `description:"当周结束日期"`
|
|
|
+ BaseDate time.Time `description:"价格基准日期"`
|
|
|
+ MonthlyPriceForecast string `description:"月度涨跌:涨/跌/震荡"`
|
|
|
+ WeeklyUpForecast string `description:"周度上行风险:是/否"`
|
|
|
+ WeeklyDownForecast string `description:"周度下行风险:是/否"`
|
|
|
+ Status int `description:"状态:0-草稿;1-已提交;"`
|
|
|
+ OutNo string `description:"外部编码(客户内部系统编码)"`
|
|
|
+ OutStatus int `description:"外部状态(象屿):0-未使用;1-已使用"`
|
|
|
+ SubmitTime time.Time `description:"提交时间"`
|
|
|
+ CreateTime time.Time `description:"创建时间"`
|
|
|
+ ModifyTime time.Time `description:"修改时间"`
|
|
|
+}
|
|
|
+
|
|
|
+func (m *AssessmentForm) TableName() string {
|
|
|
+ return "assessment_form"
|
|
|
+}
|
|
|
+
|
|
|
+type AssessmentFormCols struct {
|
|
|
+ PrimaryId string
|
|
|
+ FormCode string
|
|
|
+ ResearcherId string
|
|
|
+ ResearcherAdminId string
|
|
|
+ ResearcherName string
|
|
|
+ VarietyId string
|
|
|
+ VarietyCode string
|
|
|
+ VarietyName string
|
|
|
+ WeekTime string
|
|
|
+ WeekStart string
|
|
|
+ WeekEnd string
|
|
|
+ BaseDate string
|
|
|
+ MonthlyPriceForecast string
|
|
|
+ WeeklyUpForecast string
|
|
|
+ WeeklyDownForecast string
|
|
|
+ Status string
|
|
|
+ SubmitTime string
|
|
|
+ CreateTime string
|
|
|
+ ModifyTime string
|
|
|
+}
|
|
|
+
|
|
|
+func (m *AssessmentForm) Cols() AssessmentFormCols {
|
|
|
+ return AssessmentFormCols{
|
|
|
+ PrimaryId: "assessment_form_id",
|
|
|
+ FormCode: "form_code",
|
|
|
+ ResearcherId: "researcher_id",
|
|
|
+ ResearcherAdminId: "researcher_admin_id",
|
|
|
+ ResearcherName: "researcher_name",
|
|
|
+ VarietyId: "variety_id",
|
|
|
+ VarietyCode: "variety_code",
|
|
|
+ VarietyName: "variety_name",
|
|
|
+ WeekTime: "week_time",
|
|
|
+ WeekStart: "week_start",
|
|
|
+ WeekEnd: "week_end",
|
|
|
+ BaseDate: "base_date",
|
|
|
+ MonthlyPriceForecast: "monthly_price_forecast",
|
|
|
+ WeeklyUpForecast: "weekly_up_forecast",
|
|
|
+ WeeklyDownForecast: "weekly_down_forecast",
|
|
|
+ Status: "status",
|
|
|
+ SubmitTime: "submit_time",
|
|
|
+ CreateTime: "create_time",
|
|
|
+ ModifyTime: "modify_time",
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+func (m *AssessmentForm) Create() (err error) {
|
|
|
+ err = global.DEFAULT_DB.Create(m).Error
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+func (m *AssessmentForm) Update(cols []string) (err error) {
|
|
|
+ err = global.DEFAULT_DB.Select(cols).Updates(m).Error
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+func (m *AssessmentForm) Remove() (err error) {
|
|
|
+ sql := fmt.Sprintf(`DELETE FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.Cols().PrimaryId)
|
|
|
+ err = global.DEFAULT_DB.Exec(sql, m.AssessmentFormId).Error
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+func (m *AssessmentForm) MultiRemove(ids []int) (err error) {
|
|
|
+ if len(ids) == 0 {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ sql := fmt.Sprintf(`DELETE FROM %s WHERE %s IN (%s)`, m.TableName(), m.Cols().PrimaryId, utils.GetOrmInReplace(len(ids)))
|
|
|
+ err = global.DEFAULT_DB.Exec(sql, ids).Error
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+func (m *AssessmentForm) RemoveByCondition(condition string, pars []interface{}) (err error) {
|
|
|
+ if condition == "" {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ sql := fmt.Sprintf(`DELETE FROM %s WHERE %s`, m.TableName(), condition)
|
|
|
+ err = global.DEFAULT_DB.Exec(sql, pars...).Error
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+func (m *AssessmentForm) GetItemById(primaryId int) (item *AssessmentForm, err error) {
|
|
|
+ sql := fmt.Sprintf(`SELECT * FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.Cols().PrimaryId)
|
|
|
+ err = global.DEFAULT_DB.Raw(sql, primaryId).First(&item).Error
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+func (m *AssessmentForm) GetItemByCondition(condition string, pars []interface{}, orderRule string) (item *AssessmentForm, err error) {
|
|
|
+ order := ``
|
|
|
+ if orderRule != "" {
|
|
|
+ order = ` ORDER BY ` + orderRule
|
|
|
+ }
|
|
|
+ sql := fmt.Sprintf(`SELECT * FROM %s WHERE 1=1 %s %s LIMIT 1`, m.TableName(), condition, order)
|
|
|
+ err = global.DEFAULT_DB.Raw(sql, pars...).First(&item).Error
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+func (m *AssessmentForm) GetCountByCondition(condition string, pars []interface{}) (count int, err error) {
|
|
|
+ sql := fmt.Sprintf(`SELECT COUNT(1) FROM %s WHERE 1=1 %s`, m.TableName(), condition)
|
|
|
+ err = global.DEFAULT_DB.Raw(sql, pars...).Scan(&count).Error
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+func (m *AssessmentForm) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*AssessmentForm, err error) {
|
|
|
+ fields := strings.Join(fieldArr, ",")
|
|
|
+ if len(fieldArr) == 0 {
|
|
|
+ fields = `*`
|
|
|
+ }
|
|
|
+ order := fmt.Sprintf(`ORDER BY %s DESC`, m.Cols().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.DEFAULT_DB.Raw(sql, pars...).Find(&items).Error
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+func (m *AssessmentForm) GetPageItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string, startSize, pageSize int) (items []*AssessmentForm, err error) {
|
|
|
+ fields := strings.Join(fieldArr, ",")
|
|
|
+ if len(fieldArr) == 0 {
|
|
|
+ fields = `*`
|
|
|
+ }
|
|
|
+ order := fmt.Sprintf(`ORDER BY %s DESC`, m.Cols().CreateTime)
|
|
|
+ if orderRule != "" {
|
|
|
+ order = ` ORDER BY ` + orderRule
|
|
|
+ }
|
|
|
+ sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s LIMIT ?,?`, fields, m.TableName(), condition, order)
|
|
|
+ pars = append(pars, startSize, pageSize)
|
|
|
+ err = global.DEFAULT_DB.Raw(sql, pars...).Find(&items).Error
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+// AssessmentFormDetail 填报单信息
|
|
|
+type AssessmentFormDetail struct {
|
|
|
+ //AssessmentFormId int `description:"填报单ID"`
|
|
|
+ //FormCode string `description:"单号"`
|
|
|
+ //ResearcherId int `description:"研究员ID"`
|
|
|
+ //ResearcherAdminId int `description:"研究员用户ID"`
|
|
|
+ ResearcherName string `description:"研究员姓名" json:"researcherName"`
|
|
|
+ //VarietyId int `description:"品种ID"`
|
|
|
+ VarietyCode string `description:"品种编码" json:"varietyCode"`
|
|
|
+ VarietyName string `description:"品种名称" json:"varietyName"`
|
|
|
+ WeekTime string `description:"周度(格式:202501,202502)" json:"weekTime"`
|
|
|
+ BaseDate string `description:"价格基准日期" json:"baseDate"`
|
|
|
+ MonthlyPriceForecast string `description:"月度涨跌:涨/跌/震荡" json:"monthlyPriceForecast"`
|
|
|
+ WeeklyUpForecast string `description:"周度上行风险:是/否" json:"weeklyUpForecast"`
|
|
|
+ WeeklyDownForecast string `description:"周度下行风险:是/否" json:"weeklyDownForecast"`
|
|
|
+ //Status int `description:"状态:0-草稿;1-已提交;"`
|
|
|
+ SubmitTime string `description:"提交时间" json:"submitTime"`
|
|
|
+ CreateTime string `description:"创建时间" json:"createTime"`
|
|
|
+ ModifyTime string `description:"修改时间" json:"modifyTime"`
|
|
|
+ //Button AssessmentFormButton `description:"按钮权限"`
|
|
|
+}
|
|
|
+
|
|
|
+type AssessmentFormButton struct {
|
|
|
+ ViewButton bool `description:"查看按钮"`
|
|
|
+ EditButton bool `description:"编辑按钮"`
|
|
|
+ RemoveButton bool `description:"删除按钮"`
|
|
|
+ SubmitButton bool `description:"提交按钮"`
|
|
|
+ CancelButton bool `description:"撤销按钮"`
|
|
|
+}
|
|
|
+
|
|
|
+func (m *AssessmentForm) Format2Detail() (item *AssessmentFormDetail) {
|
|
|
+ item = new(AssessmentFormDetail)
|
|
|
+ //item.AssessmentFormId = m.AssessmentFormId
|
|
|
+ //item.FormCode = m.FormCode
|
|
|
+ //item.ResearcherId = m.ResearcherId
|
|
|
+ //item.ResearcherAdminId = m.ResearcherAdminId
|
|
|
+ item.ResearcherName = m.ResearcherName
|
|
|
+ //item.VarietyId = m.VarietyId
|
|
|
+ item.VarietyCode = m.VarietyCode
|
|
|
+ item.VarietyName = m.VarietyName
|
|
|
+ item.WeekTime = m.WeekTime
|
|
|
+ item.BaseDate = utils.TimeTransferString(utils.FormatDate, m.BaseDate)
|
|
|
+ item.MonthlyPriceForecast = m.MonthlyPriceForecast
|
|
|
+ item.WeeklyUpForecast = m.WeeklyUpForecast
|
|
|
+ item.WeeklyDownForecast = m.WeeklyDownForecast
|
|
|
+ //item.Status = m.Status
|
|
|
+ item.SubmitTime = utils.TimeTransferString(utils.FormatDate, m.SubmitTime)
|
|
|
+ item.CreateTime = utils.TimeTransferString(utils.FormatDateTime, m.CreateTime)
|
|
|
+ item.ModifyTime = utils.TimeTransferString(utils.FormatDateTime, m.ModifyTime)
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+// AssessmentFormViewResp 查看填报单
|
|
|
+type AssessmentFormViewResp struct {
|
|
|
+ List []*AssessmentFormDetail `description:"填报单详情" json:"dataList"`
|
|
|
+ Status int `description:"状态" json:"status"`
|
|
|
+ OutStatus int `description:"外部状态" json:"outStatus"`
|
|
|
+ OutNo string `description:"外部单号" json:"outNo"`
|
|
|
+ DataId string `description:"单号" json:"dataId"`
|
|
|
+ Head AssessmentFormDetail `description:"表头信息" json:"head"`
|
|
|
+}
|
|
|
+
|
|
|
+// UpdateOutStatusByFormCode
|
|
|
+// @Description: 根据填报单号更新外部单号和外部状态
|
|
|
+// @author: Roc
|
|
|
+// @receiver m
|
|
|
+// @datetime 2025-06-26 17:38:59
|
|
|
+// @param formCode string
|
|
|
+// @param outNo string
|
|
|
+// @param outStatus int
|
|
|
+// @return err error
|
|
|
+func (m *AssessmentForm) UpdateOutStatusByFormCode(formCode, outNo string, outStatus int) (err error) {
|
|
|
+ sql := fmt.Sprintf(`UPDATE %s SET out_status = ?,out_no = ? WHERE %s = ? `, m.TableName(), m.Cols().FormCode)
|
|
|
+ err = global.DEFAULT_DB.Exec(sql, outStatus, outNo, formCode).Error
|
|
|
+
|
|
|
+ return
|
|
|
+}
|