SJA APS后端代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

225 lines
6.2 KiB

  1. package db
  2. import (
  3. "errors"
  4. "github.com/go-xorm/xorm"
  5. "leit.com/leit_seat_aps/common"
  6. "xorm.io/core"
  7. )
  8. // 项目对象
  9. type Me_project struct {
  10. Finr int `xorm:"pk"`
  11. Projectid string `xorm:"pk"`
  12. Descr string
  13. Enabled int
  14. Plantsitecode int
  15. Parse_tod int
  16. Parse_seq int
  17. Parse_reorder int
  18. Parse_calloff int
  19. Fileserver_host string
  20. Tod_folder string
  21. Seq_folder string
  22. Reorder_folder string
  23. Calloff_folder string
  24. Tod_filename_regexp string
  25. Seq_filename_regexp string
  26. Reorder_filename_regexp string
  27. Calloff_filename_regexp string
  28. Tod_verify_part int
  29. Tod_verify_partfamily int
  30. Tod_verify_supplygroup int
  31. Tod_verify_partfamilyattribute int
  32. Tod_verify_supplygroupattribute int
  33. Seq_verify_sequence int
  34. Seq_verfiy_partfamily string
  35. Seq_verify_carmodelattribute int
  36. Reorder_email_alert int
  37. Calloff_verify_checksequence int
  38. Calloff_verify_orderstatus int
  39. Calloff_verify_orderspec int
  40. Emailserver_host string
  41. Emailserver_port int
  42. From_email string
  43. From_pwd string
  44. Tod_error_to_recievers string
  45. Tod_error_cc_recievers string
  46. Seq_error_to_recievers string
  47. Seq_error_cc_recievers string
  48. Reorder_picktemplateid string
  49. Reorder_pickorder_snr string
  50. Reorder_error_to_recievers string
  51. Reorder_error_cc_recievers string
  52. Calloff_error_to_recievers string
  53. Calloff_error_cc_recievers string
  54. Log_url string
  55. Log_table string
  56. Custorder_snr string
  57. Workorder_snr string
  58. Manualwo_snr string
  59. Ordermsg_snr string
  60. Reorder_snr string
  61. Shippack_snr string
  62. Shippacksync_snr string
  63. Shipcar_snr string
  64. Asn_file_prefix string
  65. Asn_snr string
  66. Asn_pfmapper string
  67. Asn_file_type string
  68. Asn_folder string
  69. Backflush_folder string
  70. Shipfile_folder string
  71. Tier2_folder string
  72. Shipfile_snr string
  73. Lastmodif string
  74. Lastuser string
  75. Credatuz string
  76. }
  77. func (t *Me_project) Clipped() {
  78. common.TrimStruct(t, *t)
  79. }
  80. func (t *Me_project) TableName() string {
  81. return "me_project"
  82. }
  83. //增
  84. func (t *Me_project) Add() error {
  85. e := G_DbEngine
  86. projtab := new(Me_project)
  87. affw, err := e.Table("me_project").ID(core.PK{G_FINR, t.Projectid}).Count(projtab)
  88. if err != nil {
  89. return err
  90. }
  91. if affw > 0 {
  92. return errors.New("数据已经存在!")
  93. }
  94. _, err = e.Table("me_project").Insert(t)
  95. if err != nil {
  96. return err
  97. }
  98. return nil
  99. }
  100. //删
  101. func (t *Me_project) Del() bool {
  102. e := G_DbEngine
  103. _, err := e.ID(core.PK{G_FINR, t.Projectid}).Delete(&Me_project{})
  104. if err != nil {
  105. return false
  106. }
  107. return true
  108. }
  109. //改
  110. func (t *Me_project) Update() bool {
  111. e := G_DbEngine
  112. _, err := e.ID(core.PK{G_FINR, t.Projectid}).Update(t)
  113. if err != nil {
  114. return false
  115. }
  116. return true
  117. }
  118. //查
  119. func (t *Me_project) SelectOne() (data Me_project, err error) {
  120. e := G_DbEngine
  121. _, err = e.ID(core.PK{G_FINR, t.Projectid}).Get(&data)
  122. if err != nil {
  123. return data, err
  124. }
  125. return data, nil
  126. }
  127. //查
  128. func (t *Me_project) SelectOneBySession(session *xorm.Session, ) (data Me_project, err error) {
  129. _, err = session.ID(core.PK{G_FINR, t.Projectid}).Get(&data)
  130. if err != nil {
  131. return data, err
  132. }
  133. return data, nil
  134. }
  135. //获取所有激活的项目数据
  136. func (t *Me_project) GetAllActive() (datalst []Me_project, err error) {
  137. e := G_DbEngine
  138. if err = e.Where("finr = ? and enabled = ?", G_FINR, 1).OrderBy("projectid").Find(&datalst); err != nil {
  139. return
  140. }
  141. for i, _ := range datalst {
  142. datalst[i].Clipped()
  143. }
  144. return
  145. }
  146. // 获取项目未解析且客户订单解析状态为IT或RC的Landing数据
  147. func (t *Me_project) GetProjectUnparsedCOV() (datalist []VCustorderVer, err error) {
  148. e := G_DbEngine
  149. datalist = make([]VCustorderVer, 0)
  150. if err = e.Table("pln_custorder_ver").Alias("cov").Join("INNER", []string{"pln_custorder", "co"},
  151. "cov.finr = co.finr and cov.custordernr = co.custordernr").Where("cov.finr = ? and cov.parsed = ? and co.handlestatus != ? and co.projnr = ?",
  152. G_FINR, 0, common.CO_PARSE_STATUS_ERROR, t.Projectid).OrderBy("cov.custordernr, cov.version").Find(&datalist); err != nil {
  153. return
  154. }
  155. return
  156. }
  157. // 确认项目是否需要重载TOD/SEQ/REORDER/CALLOFF 解析用主数据
  158. //func (t *Me_project) NeedToReloadMasterData(ediMode string) (bReload bool, err error) {
  159. // var projecttab Me_project
  160. //
  161. // if projecttab, err = t.SelectOne(); err != nil {
  162. // return
  163. // }
  164. //
  165. // bReload = false
  166. //
  167. // switch ediMode {
  168. // case common.EDI_TOD:
  169. // if projecttab.Reload_tod_masterdata > 0 {
  170. // bReload = true
  171. // }
  172. // case common.EDI_SEQ:
  173. // if projecttab.Reload_seq_masterdata > 0 {
  174. // bReload = true
  175. // }
  176. // case common.EDI_REORDER:
  177. // if projecttab.Reload_reorder_masterdata > 0 {
  178. // bReload = true
  179. // }
  180. // case common.EDI_CALLOFF:
  181. // if projecttab.Reload_calloff_masterdata > 0 {
  182. // bReload = true
  183. // }
  184. // default:
  185. // return
  186. // }
  187. //
  188. // return
  189. //}
  190. // 重置项目重载TOD/SEQ/REORDER/CALLOFF 主数据标志
  191. func (t *Me_project) ResetReloadFlagBySession(session *xorm.Session, ediMode string) (err error) {
  192. var fields string
  193. switch ediMode {
  194. case common.EDI_TOD:
  195. fields = "reload_tod_masterdata, lastmodif"
  196. case common.EDI_SEQ:
  197. fields = "reload_seq_masterdata, lastmodif"
  198. case common.EDI_REORDER:
  199. fields = "reload_reorder_masterdata, lastmodif"
  200. case common.EDI_CALLOFF:
  201. fields = "reload_calloff_masterdata, lastmodif"
  202. default:
  203. return
  204. }
  205. if _, err = session.Table("jit_shiporder").ID(core.PK{G_FINR, t.Projectid}).Cols(fields).Update(t); err != nil {
  206. return
  207. }
  208. return
  209. }