assessment_form.go 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. package models
  2. import (
  3. sql2 "database/sql"
  4. "eta/eta_hub/global"
  5. "eta/eta_hub/utils"
  6. "fmt"
  7. "strings"
  8. "time"
  9. )
  10. type AssessmentForm struct {
  11. AssessmentFormId int `gorm:"column:assessment_form_id;primaryKey;autoIncrement"`
  12. FormCode string `description:"单号"`
  13. ResearcherId int `description:"研究员ID"`
  14. ResearcherAdminId int `description:"研究员用户ID"`
  15. ResearcherName string `description:"研究员姓名"`
  16. VarietyId int `description:"品种ID"`
  17. VarietyCode string `description:"品种编码"`
  18. VarietyName string `description:"品种名称"`
  19. WeekTime string `description:"周度(格式:202501,202502)"`
  20. WeekStart time.Time `description:"当周开始日期"`
  21. WeekEnd time.Time `description:"当周结束日期"`
  22. BaseDate time.Time `description:"价格基准日期"`
  23. MonthlyPriceForecast string `description:"月度涨跌:涨/跌/震荡"`
  24. WeeklyUpForecast string `description:"周度上行风险:是/否"`
  25. WeeklyDownForecast string `description:"周度下行风险:是/否"`
  26. Status int `description:"状态:0-草稿;1-已提交;"`
  27. OutNo string `description:"外部编码(客户内部系统编码)"`
  28. OutStatus int `description:"外部状态(象屿):0-未使用;1-已使用"`
  29. SubmitTime time.Time `description:"提交时间"`
  30. CreateTime time.Time `description:"创建时间"`
  31. ModifyTime time.Time `description:"修改时间"`
  32. }
  33. func (m *AssessmentForm) TableName() string {
  34. return "assessment_form"
  35. }
  36. type AssessmentFormCols struct {
  37. PrimaryId string
  38. FormCode string
  39. ResearcherId string
  40. ResearcherAdminId string
  41. ResearcherName string
  42. VarietyId string
  43. VarietyCode string
  44. VarietyName string
  45. WeekTime string
  46. WeekStart string
  47. WeekEnd string
  48. BaseDate string
  49. MonthlyPriceForecast string
  50. WeeklyUpForecast string
  51. WeeklyDownForecast string
  52. Status string
  53. SubmitTime string
  54. CreateTime string
  55. ModifyTime string
  56. }
  57. func (m *AssessmentForm) Cols() AssessmentFormCols {
  58. return AssessmentFormCols{
  59. PrimaryId: "assessment_form_id",
  60. FormCode: "form_code",
  61. ResearcherId: "researcher_id",
  62. ResearcherAdminId: "researcher_admin_id",
  63. ResearcherName: "researcher_name",
  64. VarietyId: "variety_id",
  65. VarietyCode: "variety_code",
  66. VarietyName: "variety_name",
  67. WeekTime: "week_time",
  68. WeekStart: "week_start",
  69. WeekEnd: "week_end",
  70. BaseDate: "base_date",
  71. MonthlyPriceForecast: "monthly_price_forecast",
  72. WeeklyUpForecast: "weekly_up_forecast",
  73. WeeklyDownForecast: "weekly_down_forecast",
  74. Status: "status",
  75. SubmitTime: "submit_time",
  76. CreateTime: "create_time",
  77. ModifyTime: "modify_time",
  78. }
  79. }
  80. func (m *AssessmentForm) Create() (err error) {
  81. err = global.DEFAULT_DB.Create(m).Error
  82. return
  83. }
  84. func (m *AssessmentForm) Update(cols []string) (err error) {
  85. err = global.DEFAULT_DB.Select(cols).Updates(m).Error
  86. return
  87. }
  88. func (m *AssessmentForm) Remove() (err error) {
  89. sql := fmt.Sprintf(`DELETE FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.Cols().PrimaryId)
  90. err = global.DEFAULT_DB.Exec(sql, m.AssessmentFormId).Error
  91. return
  92. }
  93. func (m *AssessmentForm) MultiRemove(ids []int) (err error) {
  94. if len(ids) == 0 {
  95. return
  96. }
  97. sql := fmt.Sprintf(`DELETE FROM %s WHERE %s IN (%s)`, m.TableName(), m.Cols().PrimaryId, utils.GetOrmInReplace(len(ids)))
  98. err = global.DEFAULT_DB.Exec(sql, ids).Error
  99. return
  100. }
  101. func (m *AssessmentForm) RemoveByCondition(condition string, pars []interface{}) (err error) {
  102. if condition == "" {
  103. return
  104. }
  105. sql := fmt.Sprintf(`DELETE FROM %s WHERE %s`, m.TableName(), condition)
  106. err = global.DEFAULT_DB.Exec(sql, pars...).Error
  107. return
  108. }
  109. func (m *AssessmentForm) GetItemById(primaryId int) (item *AssessmentForm, err error) {
  110. sql := fmt.Sprintf(`SELECT * FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.Cols().PrimaryId)
  111. err = global.DEFAULT_DB.Raw(sql, primaryId).First(&item).Error
  112. return
  113. }
  114. func (m *AssessmentForm) GetItemByCondition(condition string, pars []interface{}, orderRule string) (item *AssessmentForm, err error) {
  115. order := ``
  116. if orderRule != "" {
  117. order = ` ORDER BY ` + orderRule
  118. }
  119. sql := fmt.Sprintf(`SELECT * FROM %s WHERE 1=1 %s %s LIMIT 1`, m.TableName(), condition, order)
  120. err = global.DEFAULT_DB.Raw(sql, pars...).First(&item).Error
  121. return
  122. }
  123. func (m *AssessmentForm) GetCountByCondition(condition string, pars []interface{}) (count int, err error) {
  124. var totalNull sql2.NullInt64
  125. sql := fmt.Sprintf(`SELECT COUNT(1) FROM %s WHERE 1=1 %s`, m.TableName(), condition)
  126. err = global.DEFAULT_DB.Raw(sql, pars...).Scan(&totalNull).Error
  127. if err != nil {
  128. return
  129. }
  130. count = int(totalNull.Int64)
  131. return
  132. }
  133. func (m *AssessmentForm) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*AssessmentForm, err error) {
  134. fields := strings.Join(fieldArr, ",")
  135. if len(fieldArr) == 0 {
  136. fields = `*`
  137. }
  138. order := fmt.Sprintf(`ORDER BY %s DESC`, m.Cols().CreateTime)
  139. if orderRule != "" {
  140. order = ` ORDER BY ` + orderRule
  141. }
  142. sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s`, fields, m.TableName(), condition, order)
  143. err = global.DEFAULT_DB.Raw(sql, pars...).Find(&items).Error
  144. return
  145. }
  146. func (m *AssessmentForm) GetPageItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string, startSize, pageSize int) (items []*AssessmentForm, err error) {
  147. fields := strings.Join(fieldArr, ",")
  148. if len(fieldArr) == 0 {
  149. fields = `*`
  150. }
  151. order := fmt.Sprintf(`ORDER BY %s DESC`, m.Cols().CreateTime)
  152. if orderRule != "" {
  153. order = ` ORDER BY ` + orderRule
  154. }
  155. sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s LIMIT ?,?`, fields, m.TableName(), condition, order)
  156. pars = append(pars, startSize, pageSize)
  157. err = global.DEFAULT_DB.Raw(sql, pars...).Find(&items).Error
  158. return
  159. }
  160. // AssessmentFormDetail 填报单信息
  161. type AssessmentFormDetail struct {
  162. //AssessmentFormId int `description:"填报单ID"`
  163. //FormCode string `description:"单号"`
  164. //ResearcherId int `description:"研究员ID"`
  165. //ResearcherAdminId int `description:"研究员用户ID"`
  166. ResearcherName string `description:"研究员姓名" json:"researcherName"`
  167. //VarietyId int `description:"品种ID"`
  168. VarietyCode string `description:"品种编码" json:"varietyCode"`
  169. VarietyName string `description:"品种名称" json:"varietyName"`
  170. WeekTime string `description:"周度(格式:202501,202502)" json:"weekTime"`
  171. BaseDate string `description:"价格基准日期" json:"baseDate"`
  172. MonthlyPriceForecast string `description:"月度涨跌:涨/跌/震荡" json:"monthlyPriceForecast"`
  173. WeeklyUpForecast string `description:"周度上行风险:是/否" json:"weeklyUpForecast"`
  174. WeeklyDownForecast string `description:"周度下行风险:是/否" json:"weeklyDownForecast"`
  175. //Status int `description:"状态:0-草稿;1-已提交;"`
  176. SubmitTime string `description:"提交时间" json:"submitTime"`
  177. CreateTime string `description:"创建时间" json:"createTime"`
  178. ModifyTime string `description:"修改时间" json:"modifyTime"`
  179. //Button AssessmentFormButton `description:"按钮权限"`
  180. }
  181. type AssessmentFormButton struct {
  182. ViewButton bool `description:"查看按钮"`
  183. EditButton bool `description:"编辑按钮"`
  184. RemoveButton bool `description:"删除按钮"`
  185. SubmitButton bool `description:"提交按钮"`
  186. CancelButton bool `description:"撤销按钮"`
  187. }
  188. func (m *AssessmentForm) Format2Detail() (item *AssessmentFormDetail) {
  189. item = new(AssessmentFormDetail)
  190. //item.AssessmentFormId = m.AssessmentFormId
  191. //item.FormCode = m.FormCode
  192. //item.ResearcherId = m.ResearcherId
  193. //item.ResearcherAdminId = m.ResearcherAdminId
  194. item.ResearcherName = m.ResearcherName
  195. //item.VarietyId = m.VarietyId
  196. item.VarietyCode = m.VarietyCode
  197. item.VarietyName = m.VarietyName
  198. item.WeekTime = m.WeekTime
  199. item.BaseDate = utils.TimeTransferString(utils.FormatDate, m.BaseDate)
  200. item.MonthlyPriceForecast = m.MonthlyPriceForecast
  201. item.WeeklyUpForecast = m.WeeklyUpForecast
  202. item.WeeklyDownForecast = m.WeeklyDownForecast
  203. //item.Status = m.Status
  204. item.SubmitTime = utils.TimeTransferString(utils.FormatDate, m.SubmitTime)
  205. item.CreateTime = utils.TimeTransferString(utils.FormatDateTime, m.CreateTime)
  206. item.ModifyTime = utils.TimeTransferString(utils.FormatDateTime, m.ModifyTime)
  207. return
  208. }
  209. // AssessmentFormViewResp 查看填报单
  210. type AssessmentFormViewResp struct {
  211. List []*AssessmentFormDetail `description:"填报单详情" json:"dataList"`
  212. Status int `description:"状态" json:"status"`
  213. OutStatus int `description:"外部状态" json:"outStatus"`
  214. OutNo string `description:"外部单号" json:"outNo"`
  215. DataId string `description:"单号" json:"dataId"`
  216. Head AssessmentFormDetail `description:"表头信息" json:"head"`
  217. }
  218. // UpdateOutStatusByFormCode
  219. // @Description: 根据填报单号更新外部单号和外部状态
  220. // @author: Roc
  221. // @receiver m
  222. // @datetime 2025-06-26 17:38:59
  223. // @param formCode string
  224. // @param outNo string
  225. // @param outStatus int
  226. // @return err error
  227. func (m *AssessmentForm) UpdateOutStatusByFormCode(formCode, outNo string, outStatus int) (err error) {
  228. sql := fmt.Sprintf(`UPDATE %s SET out_status = ?,out_no = ? WHERE %s = ? `, m.TableName(), m.Cols().FormCode)
  229. err = global.DEFAULT_DB.Exec(sql, outStatus, outNo, formCode).Error
  230. return
  231. }