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.

328 lines
10 KiB

  1. package service
  2. import (
  3. "errors"
  4. "fmt"
  5. "leit.com/leit_seat_aps/common"
  6. "leit.com/leit_seat_aps/db"
  7. "strconv"
  8. "strings"
  9. )
  10. // 用于TOD解析的项目主数据对象
  11. type TodProject struct {
  12. Projectid string
  13. Projecttab db.Me_project // 项目表
  14. Mesprojtab db.Prod_project // 生产项目表
  15. Attrdict map[int]BL_Attribute // 所有的用于解析的产品属性
  16. Partdict map[string]BL_Part // 所有的用于解析的零件清单
  17. Partfamdict map[string]BL_PartFamily // 所有的用于解析的零件族
  18. Supplygrpdict map[string]BL_SupplyGroup // 所有的用于解析的供应组
  19. Partruledict map[string]BL_PartAssignRule // Key = 零件号+零件族+待分配数量
  20. Carmodeldict map[string]BL_Carmodel // 车型字典
  21. }
  22. // 获取项目指定属性类型的属性主数据字典
  23. func (tp *TodProject) GetAttributeList(attrtype int) (err error) {
  24. var (
  25. attrtab db.Me_attribute
  26. attrtablist []db.Me_attribute
  27. bl_attr BL_Attribute
  28. i int
  29. )
  30. // 初始化项目的属性字典
  31. tp.Attrdict = make(map[int]BL_Attribute)
  32. attrtab = db.Me_attribute{}
  33. if attrtablist, err = attrtab.GetTypeAttributes(attrtype); err != nil {
  34. return
  35. }
  36. // 遍历属性列表并写入属性字典
  37. for i = 0; i < len(attrtablist); i++ {
  38. attrtablist[i].Clipped()
  39. bl_attr = BL_Attribute{}
  40. bl_attr.Attrcode = attrtablist[i].Attrcode
  41. bl_attr.Attrname = attrtablist[i].Attrname
  42. bl_attr.Descr = attrtablist[i].Descr
  43. bl_attr.Attrtype = attrtablist[i].Attrtype
  44. bl_attr.Attrtab = attrtablist[i]
  45. bl_attr.Atvaltablst = attrtablist[i].Valst
  46. tp.Attrdict[bl_attr.Attrcode] = bl_attr
  47. }
  48. return
  49. }
  50. // 获取项目的零件字典
  51. func (tp *TodProject) GetPartList() (err error) {
  52. var (
  53. partab db.Me_part
  54. partablst []db.Me_part
  55. i, j int
  56. bl_pt BL_Part
  57. bl_ptattr BL_PartAttribute
  58. )
  59. // 初始化项目的零件字典
  60. tp.Partdict = make(map[string]BL_Part)
  61. partab = db.Me_part{}
  62. if partablst, err = partab.GetProjectAll(tp.Projectid); err != nil {
  63. return
  64. }
  65. // 遍历零件列表并写入字典
  66. for i = 0; i < len(partablst); i++ {
  67. bl_pt = BL_Part{}
  68. bl_pt.Partid = partablst[i].Partid
  69. bl_pt.Projnr = partablst[i].Projnr
  70. bl_pt.AtcodDict = make(map[int]BL_PartAttribute)
  71. for j = 0; j < len(partablst[i].Attrlst); j++ {
  72. bl_ptattr = BL_PartAttribute{}
  73. bl_ptattr.Attrcode = partablst[i].Attrlst[j].Attrcode
  74. bl_ptattr.Attrvalue = partablst[i].Attrlst[j].Attrvalue
  75. bl_ptattr.Partattrtab = partablst[i].Attrlst[j]
  76. bl_pt.AtcodDict[bl_ptattr.Attrcode] = bl_ptattr
  77. }
  78. tp.Partdict[bl_pt.Partid] = bl_pt
  79. }
  80. return
  81. }
  82. // 获取项目的零件族字典
  83. func (tp *TodProject) GetPartFamilyList() (err error) {
  84. var (
  85. pftab db.Me_partfamily
  86. pftablst []db.Me_partfamily
  87. i, j int
  88. bl_pf BL_PartFamily
  89. bl_pfattr BL_PartFamily_Atcod
  90. )
  91. // 初始化项目的零件族字典
  92. tp.Partfamdict = make(map[string]BL_PartFamily)
  93. pftab = db.Me_partfamily{}
  94. if pftablst, err = pftab.GetProjectAll(tp.Projectid); err != nil {
  95. return
  96. }
  97. // 遍历零件族列表并写入字典
  98. for i = 0; i < len(pftablst); i++ {
  99. bl_pf = BL_PartFamily{}
  100. bl_pf.Partfamilyid = pftablst[i].Partfamilyid
  101. bl_pf.Pf_attr_dict = make(map[int]BL_PartFamily_Atcod)
  102. for j = 0; j < len(pftablst[i].Atcodlst); j++ {
  103. bl_pfattr = BL_PartFamily_Atcod{}
  104. bl_pfattr.Attrcode = pftablst[i].Atcodlst[j].Attrcode
  105. bl_pfattr.Mandatory = pftablst[i].Atcodlst[j].Mandatory
  106. bl_pfattr.Verifyrule = pftablst[i].Atcodlst[j].Verifyrule
  107. bl_pfattr.Partfamily_attrtab = pftablst[i].Atcodlst[j]
  108. bl_pf.Pf_attr_dict[bl_pfattr.Attrcode] = bl_pfattr
  109. }
  110. tp.Partfamdict[bl_pf.Partfamilyid] = bl_pf
  111. }
  112. return
  113. }
  114. // 获取项目的供应组字典
  115. func (tp *TodProject) GetSupplyGroupList() (err error) {
  116. var (
  117. sgtab db.Me_supplygroup
  118. sgtablst []db.Me_supplygroup
  119. i, j, k int
  120. bl_sg BL_SupplyGroup
  121. bl_csg BL_SupplyGroup
  122. bl_sgattr BL_SupplyGroup_Atcod
  123. ok bool
  124. )
  125. // 初始化项目的供应组字典
  126. tp.Supplygrpdict = make(map[string]BL_SupplyGroup)
  127. sgtab = db.Me_supplygroup{}
  128. if sgtablst, err = sgtab.GetProjectAll(tp.Projectid); err != nil {
  129. return
  130. }
  131. // 遍历供应组列表并写入字典
  132. for i = 0; i < len(sgtablst); i++ {
  133. bl_sg = BL_SupplyGroup{}
  134. bl_sg.Supplygroupid = sgtablst[i].Supplygroupid
  135. bl_sg.Partfamilyid = sgtablst[i].Partfamilyid
  136. bl_sg.Worklineid = sgtablst[i].Worklineid
  137. bl_sg.Sgtype = strings.ToUpper(sgtablst[i].Sgtype)
  138. if bl_sg.Sgtype == common.SG_TYPE_NORMAL {
  139. bl_sg.Sgchildrendict = make(map[string]string)
  140. }
  141. if sgtablst[i].Multioutput > 0 {
  142. bl_sg.Multioutput = true
  143. } else {
  144. bl_sg.Multioutput = false
  145. }
  146. bl_sg.SgAssigndict = make(map[string]db.Me_supplygroup_assignment)
  147. bl_sg.Modfactor = sgtablst[i].Modfactor
  148. bl_sg.Shippablesg = sgtablst[i].Shippablesg
  149. bl_sg.Supplygrouptab = sgtablst[i]
  150. bl_sg.Sg_attr_dict = make(map[int]BL_SupplyGroup_Atcod)
  151. // 加载供应组的属性信息
  152. for j = 0; j < len(sgtablst[i].Atcodlst); j++ {
  153. bl_sgattr = BL_SupplyGroup_Atcod{}
  154. bl_sgattr.Attrcode = sgtablst[i].Atcodlst[j].Attrcode
  155. bl_sgattr.Mandatory = sgtablst[i].Atcodlst[j].Mandatory
  156. bl_sgattr.Verifyrule = sgtablst[i].Atcodlst[j].Verifyrule
  157. bl_sgattr.Supplygroup_attrtab = sgtablst[i].Atcodlst[j]
  158. bl_sg.Sg_attr_dict[bl_sgattr.Attrcode] = bl_sgattr
  159. }
  160. // 加载供应组的分配信息
  161. if bl_sg.Sgtype == common.SG_TYPE_NORMAL && bl_sg.Shippablesg == 0 {
  162. for k = 0; k < len(sgtablst[i].Asnsglst); k++ {
  163. bl_sg.SgAssigndict[sgtablst[i].Asnsglst[k].Fsupplygroupid] = sgtablst[i].Asnsglst[k]
  164. }
  165. }
  166. tp.Supplygrpdict[bl_sg.Supplygroupid] = bl_sg
  167. }
  168. // 遍历子供应组
  169. for _, bl_csg = range tp.Supplygrpdict {
  170. if bl_csg.Sgtype == common.SG_TYPE_CHILD {
  171. if bl_sg, ok = tp.Supplygrpdict[strings.TrimSpace(bl_csg.Supplygrouptab.Fsupplygroupid)]; !ok {
  172. err = errors.New(fmt.Sprintf("Child supplygroup %s parent supplygroup %s is not existing!", bl_csg.Supplygroupid, bl_csg.Supplygrouptab.Fsupplygroupid))
  173. }
  174. bl_sg.Sgchildrendict[bl_csg.Supplygroupid] = bl_csg.Supplygroupid
  175. //tp.Supplygrpdict[bl_sg.Supplygroupid] = bl_sg
  176. }
  177. }
  178. return
  179. }
  180. // 获取项目的供应组字典
  181. func (tp *TodProject) CopySupplyGroup(sgid string) (bl_sg BL_SupplyGroup, err error) {
  182. var (
  183. bl_sgfrom BL_SupplyGroup
  184. bl_sgpt, bl_sgptfrom BL_SgPart
  185. bl_sgat, bl_sgatfrom BL_SupplyGroup_Atcod
  186. ok bool
  187. )
  188. if bl_sgfrom, ok = tp.Supplygrpdict[sgid]; !ok {
  189. return
  190. }
  191. bl_sg = BL_SupplyGroup{}
  192. bl_sg.Supplygroupid = bl_sgfrom.Supplygroupid
  193. bl_sg.Partfamilyid = bl_sgfrom.Partfamilyid
  194. bl_sg.Worklineid = bl_sgfrom.Worklineid
  195. bl_sg.Sgtype = bl_sgfrom.Sgtype
  196. bl_sg.Sg_attr_dict = bl_sgfrom.Sg_attr_dict
  197. bl_sg.Supplygrouptab = bl_sgfrom.Supplygrouptab
  198. bl_sg.Bl_sgpartDict = make(map[string]BL_SgPart)
  199. for _, bl_sgptfrom = range bl_sgfrom.Bl_sgpartDict {
  200. bl_sgpt = BL_SgPart{}
  201. bl_sgpt.Supplygroupid = bl_sgptfrom.Supplygroupid
  202. bl_sgpt.Partid = bl_sgptfrom.Partid
  203. bl_sgpt.Qty = bl_sgptfrom.Qty
  204. bl_sgpt.Originalsgid = bl_sgptfrom.Originalsgid
  205. bl_sgpt.AtcodDict = bl_sgptfrom.AtcodDict
  206. bl_sg.Bl_sgpartDict[bl_sgpt.Partid] = bl_sgpt
  207. }
  208. bl_sg.Sg_attr_dict = make(map[int]BL_SupplyGroup_Atcod)
  209. for _, bl_sgatfrom = range bl_sgfrom.Sg_attr_dict {
  210. bl_sgat = BL_SupplyGroup_Atcod{}
  211. bl_sgat.Supplygroupid = bl_sgatfrom.Supplygroupid
  212. bl_sgat.Attrcode = bl_sgatfrom.Attrcode
  213. bl_sgat.Mandatory = bl_sgatfrom.Mandatory
  214. bl_sgat.Verifyrule = bl_sgatfrom.Verifyrule
  215. bl_sgat.Supplygroup_attrtab = bl_sgatfrom.Supplygroup_attrtab
  216. bl_sg.Sg_attr_dict[bl_sgat.Attrcode] = bl_sgat
  217. }
  218. return
  219. }
  220. // 获取项目的零件分配规则字典
  221. func (tp *TodProject) GetPartRuleList() (err error) {
  222. var (
  223. ptruletab db.Me_partrule
  224. ptruletablst []db.Me_partrule
  225. i, j int
  226. key string
  227. bl_ptrule BL_PartAssignRule
  228. )
  229. // 初始化项目的零件规则字典
  230. tp.Partruledict = make(map[string]BL_PartAssignRule)
  231. ptruletab = db.Me_partrule{}
  232. if ptruletablst, err = ptruletab.GetProjectAll(tp.Projectid); err != nil {
  233. return
  234. }
  235. // 遍历零件数量分配规则列表并写入字典
  236. for i = 0; i < len(ptruletablst); i++ {
  237. bl_ptrule = BL_PartAssignRule{}
  238. bl_ptrule.Ruleid = ptruletablst[i].Ruleid
  239. bl_ptrule.Partid = ptruletablst[i].Partid
  240. bl_ptrule.Partfamilyid = ptruletablst[i].Partrule_cprecond
  241. bl_ptrule.Qty = ptruletablst[i].Partrule_iprecond
  242. bl_ptrule.Partruletab = ptruletablst[i]
  243. bl_ptrule.Assignnruledict = make(map[string]db.Me_partrule_qtyassign)
  244. for j = 0; j < len(ptruletablst[i].Qtyasnlst); j++ {
  245. ptruletablst[i].Qtyasnlst[j].Clipped()
  246. key = ptruletablst[i].Qtyasnlst[j].Supplygroupid
  247. bl_ptrule.Assignnruledict[key] = ptruletablst[i].Qtyasnlst[j]
  248. }
  249. // 项目零件分配规则Key = 零件ID+数量
  250. key = bl_ptrule.Partid + "+" + strconv.Itoa(bl_ptrule.Qty)
  251. tp.Partruledict[key] = bl_ptrule
  252. }
  253. return
  254. }
  255. // 获取项目的车型字典
  256. func (tp *TodProject) GetCarModelList() (err error) {
  257. var (
  258. cmtab db.Me_carmodel
  259. cmtablst []db.Me_carmodel
  260. i, j int
  261. key string
  262. bl_cm BL_Carmodel
  263. bl_cmattr BL_Carmodel_Atcod
  264. )
  265. // 初始化项目的车型字典
  266. tp.Carmodeldict = make(map[string]BL_Carmodel)
  267. cmtab = db.Me_carmodel{}
  268. if cmtablst, err = cmtab.GetProjectAll(tp.Projectid); err != nil {
  269. return
  270. }
  271. // 遍历车型列表并写入字典
  272. for i = 0; i < len(cmtablst); i++ {
  273. bl_cm = BL_Carmodel{}
  274. bl_cm.Carmodelid = cmtablst[i].Carmodelid
  275. bl_cm.Carmodeltab = cmtablst[i]
  276. bl_cm.Cm_pf_dict = make(map[string]string)
  277. bl_cm.Cm_attr_dict = make(map[int]BL_Carmodel_Atcod)
  278. // 存储零件族ID
  279. for j = 0; j < len(cmtablst[i].Pflst); j++ {
  280. key = cmtablst[i].Pflst[j].Partfamilyid
  281. bl_cm.Cm_pf_dict[key] = key
  282. }
  283. // 存储车型分配的属性列表
  284. for j = 0; j < len(cmtablst[i].Atcodlst); j++ {
  285. bl_cmattr = BL_Carmodel_Atcod{}
  286. bl_cmattr.Carmodelid = cmtablst[i].Atcodlst[j].Carmodelid
  287. bl_cmattr.Attrcode = cmtablst[i].Atcodlst[j].Attrcode
  288. bl_cmattr.Mandatory = cmtablst[i].Atcodlst[j].Mandatory
  289. bl_cmattr.Verifyrule = cmtablst[i].Atcodlst[j].Verifyrule
  290. bl_cmattr.Carmodel_attrtab = cmtablst[i].Atcodlst[j]
  291. bl_cm.Cm_attr_dict[bl_cmattr.Attrcode] = bl_cmattr
  292. }
  293. tp.Carmodeldict[bl_cm.Carmodelid] = bl_cm
  294. }
  295. return
  296. }