product_preplan.go 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555
  1. package handlers
  2. import (
  3. "net/http"
  4. "easydo-echo_win7/models"
  5. "easydo-echo_win7/services"
  6. "easydo-echo_win7/utils"
  7. "easydo-echo_win7/middleware"
  8. "github.com/labstack/echo-contrib/session"
  9. "github.com/labstack/echo/v4"
  10. )
  11. func Add_product_pre_plan_to_routes(e *echo.Echo) {
  12. group := e.Group("/productPrePlan")
  13. group.Use(middleware.AuthMiddleware)
  14. group.POST("/getPage", productPrePlanGetPage)
  15. group.POST("/save", productPrePlanSave)
  16. }
  17. func productPrePlanGetPage(c echo.Context) error {
  18. var paramMap map[string]interface{}
  19. if err := c.Bind(&paramMap); err != nil {
  20. return c.JSON(http.StatusInternalServerError, utils.ErrorResponse("参数解析失败", err.Error()))
  21. }
  22. result, err := services.JdbcClient.GetJdbcPage(paramMap, models.SaleOrder{})
  23. if err != nil {
  24. utils.PrintSqlErr(err)
  25. return c.JSON(http.StatusInternalServerError, utils.ErrorResponse("系统错误", err.Error()))
  26. }
  27. list := utils.ConvertInterface[[]models.SaleOrder](result.Records)
  28. if len(list) == 0 {
  29. list = []models.SaleOrder{}
  30. }
  31. for i := range list {
  32. model := list[i]
  33. minioList, err := services.JdbcClient.GetMinioFile(model)
  34. if err != nil {
  35. utils.PrintSearchFileErr(err)
  36. }
  37. model.FileList = &minioList
  38. detailParam := new(models.SaleOrderDetail)
  39. detailParam.OrderId = model.ID
  40. result, err := services.JdbcClient.GetJdbcListByObject(detailParam)
  41. if err != nil {
  42. utils.PrintSqlErr(err)
  43. return c.JSON(http.StatusInternalServerError, utils.ErrorResponse("系统错误", err.Error()))
  44. }
  45. detail_list := utils.ConvertInterface[[]models.SaleOrderDetail](result)
  46. for j := range detail_list {
  47. detail := detail_list[j]
  48. material := new(models.ProductMaterial)
  49. material.Code = detail.MaterialCode
  50. material.TenantId = model.TenantId
  51. err = services.JdbcClient.GetJdbcModel(material)
  52. if err != nil {
  53. utils.PrintSqlErr(err)
  54. return c.JSON(http.StatusInternalServerError, utils.ErrorResponse("系统错误", err.Error()))
  55. }
  56. detail.Material = material
  57. bom := new(models.ProductBom)
  58. parentId := models.Common_Value_Zero_String
  59. bom.ParentId = &parentId
  60. bom.MaterialCode = material.Code
  61. bom.TenantId = model.TenantId
  62. status := models.Status_Enable
  63. bom.Status = &status
  64. err = services.JdbcClient.GetJdbcModel(bom)
  65. if err != nil {
  66. utils.PrintSqlErr(err)
  67. return c.JSON(http.StatusInternalServerError, utils.ErrorResponse("系统错误", err.Error()))
  68. }
  69. if bom.ID != nil && len(*bom.ID) > 0 {
  70. //对于有bom的物料,查询出bom下所有组成(bom_list)和库存
  71. bomParam := new(models.ProductBom)
  72. bomParam.BomCode = bom.BomCode
  73. bomParam.TenantId = model.TenantId
  74. result, err := services.JdbcClient.GetJdbcListByObject(bomParam)
  75. if err != nil {
  76. utils.PrintSqlErr(err)
  77. return c.JSON(http.StatusInternalServerError, utils.ErrorResponse("系统错误", err.Error()))
  78. }
  79. bom_list := utils.ConvertInterface[[]models.ProductBom](result)
  80. for k := range bom_list {
  81. bom_model := bom_list[k]
  82. material := new(models.ProductMaterial)
  83. material.Code = bom_model.MaterialCode
  84. material.TenantId = model.TenantId
  85. err = services.JdbcClient.GetJdbcModel(material)
  86. if err != nil {
  87. utils.PrintSqlErr(err)
  88. return c.JSON(http.StatusInternalServerError, utils.ErrorResponse("系统错误", err.Error()))
  89. }
  90. bom_model.Material = material
  91. warehouseMaterial := new(models.WarehouseMaterial)
  92. warehouseMaterial.MaterialCode = material.Code
  93. warehouseMaterial.TenantId = model.TenantId
  94. warehouse_material_status := models.Status_Enable
  95. warehouseMaterial.Status = &warehouse_material_status
  96. warehouse_material_result, err := services.JdbcClient.GetJdbcListByObject(warehouseMaterial)
  97. if err != nil {
  98. utils.PrintSqlErr(err)
  99. return c.JSON(http.StatusInternalServerError, utils.ErrorResponse("系统错误", err.Error()))
  100. }
  101. warehouse_material_list := utils.ConvertInterface[[]models.WarehouseMaterial](warehouse_material_result)
  102. if warehouse_material_list != nil {
  103. for l := range warehouse_material_list {
  104. warehouse_material_model := warehouse_material_list[l]
  105. warehouse := new(models.Warehouse)
  106. warehouse.ID = warehouse_material_model.WarehouseId
  107. err = services.JdbcClient.GetJdbcModelById(warehouse)
  108. if err != nil {
  109. utils.PrintSqlErr(err)
  110. return c.JSON(http.StatusInternalServerError, utils.ErrorResponse("系统错误", err.Error()))
  111. }
  112. warehouse_material_model.Warehouse = warehouse
  113. warehouse_material_list[l] = warehouse_material_model
  114. }
  115. bom_model.WarehouseMaterialList = &warehouse_material_list
  116. }
  117. bom_list[k] = bom_model
  118. }
  119. detail.BomList = &bom_list
  120. } else {
  121. //对于没有bom的物料,只需要查询出库存
  122. warehouseMaterial := new(models.WarehouseMaterial)
  123. warehouseMaterial.MaterialCode = material.Code
  124. warehouseMaterial.TenantId = model.TenantId
  125. warehouse_material_status := models.Status_Enable
  126. warehouseMaterial.Status = &warehouse_material_status
  127. warehouse_material_result, err := services.JdbcClient.GetJdbcListByObject(warehouseMaterial)
  128. if err != nil {
  129. utils.PrintSqlErr(err)
  130. return c.JSON(http.StatusInternalServerError, utils.ErrorResponse("系统错误", err.Error()))
  131. }
  132. warehouse_material_list := utils.ConvertInterface[[]models.WarehouseMaterial](warehouse_material_result)
  133. if warehouse_material_list != nil {
  134. for k := range warehouse_material_list {
  135. warehouse_material_model := warehouse_material_list[k]
  136. warehouse := new(models.Warehouse)
  137. warehouse.ID = warehouse_material_model.WarehouseId
  138. err = services.JdbcClient.GetJdbcModelById(warehouse)
  139. if err != nil {
  140. utils.PrintSqlErr(err)
  141. return c.JSON(http.StatusInternalServerError, utils.ErrorResponse("系统错误", err.Error()))
  142. }
  143. warehouse_material_model.Warehouse = warehouse
  144. warehouse_material_list[k] = warehouse_material_model
  145. }
  146. detail.WarehouseMaterialList = &warehouse_material_list
  147. }
  148. }
  149. detail_list[j] = detail
  150. }
  151. model.ChildrenList = &detail_list
  152. if model.ManagerId != nil && *model.ManagerId != 0 {
  153. manager := new(models.SysUser)
  154. manager.ID = model.ManagerId
  155. err = services.JdbcClient.GetJdbcModelById(manager)
  156. if err != nil {
  157. utils.PrintSqlErr(err)
  158. return c.JSON(http.StatusInternalServerError, utils.ErrorResponse("系统错误", err.Error()))
  159. }
  160. model.ManagerName = manager.NickName
  161. }
  162. if model.CustomerId != nil && *model.CustomerId != "" {
  163. customer := new(models.Customer)
  164. customer.ID = model.CustomerId
  165. err = services.JdbcClient.GetJdbcModelById(customer)
  166. if err != nil {
  167. utils.PrintSqlErr(err)
  168. return c.JSON(http.StatusInternalServerError, utils.ErrorResponse("系统错误", err.Error()))
  169. }
  170. model.CustomerName = customer.Name
  171. }
  172. list[i] = model
  173. }
  174. result.Records = list
  175. return c.JSON(http.StatusOK, result)
  176. }
  177. func productPrePlanSave(c echo.Context) error {
  178. tx, _ := services.MYSQL_DB.Beginx()
  179. sess, _ := session.Get("auth_session", c)
  180. user_id, ok := sess.Values["user_id"].(int64)
  181. if !ok {
  182. return c.JSON(http.StatusInternalServerError, utils.ErrorResponse("用户请先登录", ""))
  183. }
  184. planVo := new(models.ProductPrePlanVo)
  185. if err := c.Bind(planVo); err != nil {
  186. return c.JSON(http.StatusInternalServerError, utils.ErrorResponse("参数解析失败", err.Error()))
  187. }
  188. sale_order := new(models.SaleOrder)
  189. sale_order.ID = planVo.SaleOrderId
  190. err := services.JdbcClient.GetJdbcModelById(sale_order, tx)
  191. if err != nil {
  192. utils.PrintSqlErr(err)
  193. tx.Rollback()
  194. return c.JSON(http.StatusInternalServerError, utils.ErrorResponse("系统错误", ""))
  195. }
  196. saleOrderStatus := models.Sale_Order_Status_Processing
  197. sale_order.Status = &saleOrderStatus
  198. err = services.JdbcClient.JdbcUpdateById(sale_order, tx)
  199. if err != nil {
  200. utils.PrintSqlErr(err)
  201. tx.Rollback()
  202. return c.JSON(http.StatusInternalServerError, utils.ErrorResponse("系统错误", ""))
  203. }
  204. product_plan_vo_list := *planVo.ProductPlanVoList
  205. if len(product_plan_vo_list) > 0 {
  206. plan_filter_list := utils.Filter(product_plan_vo_list, func(item models.ProductPlanVo) bool {
  207. return *item.PlanProductNumber > 0
  208. })
  209. plan_warehouse_filter_list := utils.Filter(product_plan_vo_list, func(item models.ProductPlanVo) bool {
  210. return len(*item.WarehouseMaterialVoList) > 0
  211. })
  212. product_plan := new(models.ProductPlan)
  213. if len(plan_filter_list) > 0 {
  214. product_plan.TenantId = sale_order.TenantId
  215. product_plan.SaleOrderId = sale_order.ID
  216. err_msg := productPlan_generateCode(product_plan, tx)
  217. if err_msg != "" {
  218. tx.Rollback()
  219. return c.JSON(http.StatusBadRequest, utils.ErrorResponse(err_msg, ""))
  220. }
  221. if planVo.ProductPlanName != nil && len(*planVo.ProductPlanName) > 0 {
  222. product_plan.Name = planVo.ProductPlanName
  223. } else {
  224. product_plan.Name = product_plan.Code
  225. }
  226. status := models.Product_Plan_Status_Pending
  227. product_plan.Status = &status
  228. product_plan.CreateId = &user_id
  229. product_plan.BeginDate = planVo.PlanBeginDate
  230. product_plan.EndDate = planVo.PlanEndDate
  231. err = services.JdbcClient.JdbcInsert(product_plan, tx)
  232. if err != nil {
  233. utils.PrintSqlErr(err)
  234. tx.Rollback()
  235. return c.JSON(http.StatusInternalServerError, utils.ErrorResponse("系统错误", ""))
  236. }
  237. }
  238. for _, detail := range plan_filter_list {
  239. product_plan_bom := new(models.ProductPlanBom)
  240. product_plan_bom.BomId = detail.BomId
  241. product_plan_bom.PlanId = product_plan.ID
  242. product_plan_bom.Number = detail.PlanProductNumber
  243. bom := new(models.ProductBom)
  244. bom.ID = detail.BomId
  245. err = services.JdbcClient.GetJdbcModelById(bom, tx)
  246. if err != nil {
  247. utils.PrintSqlErr(err)
  248. tx.Rollback()
  249. return c.JSON(http.StatusInternalServerError, utils.ErrorResponse("系统错误", ""))
  250. }
  251. product_plan_bom.RouteId = bom.RouteId
  252. route := new(models.ProcessRoute)
  253. route.ID = bom.RouteId
  254. err = services.JdbcClient.GetJdbcModelById(route, tx)
  255. if err != nil {
  256. utils.PrintSqlErr(err)
  257. tx.Rollback()
  258. return c.JSON(http.StatusInternalServerError, utils.ErrorResponse("系统错误", ""))
  259. }
  260. product_plan_bom.InspectProgramId = route.InspectProgramId
  261. err := services.JdbcClient.JdbcInsert(product_plan_bom, tx)
  262. if err != nil {
  263. utils.PrintSqlErr(err)
  264. tx.Rollback()
  265. return c.JSON(http.StatusInternalServerError, utils.ErrorResponse("系统错误", ""))
  266. }
  267. }
  268. for _, detail := range plan_warehouse_filter_list {
  269. warehouseMaterialVoList := *detail.WarehouseMaterialVoList
  270. for _, warehouseMaterial := range warehouseMaterialVoList {
  271. warehouse_record_model := new(models.WarehouseRecord)
  272. recordType := models.Warehouse_Record_Type_Lock
  273. warehouse_record_model.Type = &recordType
  274. warehouse_record_model.MaterialCode = detail.MaterialCode
  275. warehouse_record_model.Number = warehouseMaterial.LockedNumber
  276. warehouse_record_model.FromWarehouseId = warehouseMaterial.WarehouseId
  277. warehouse_record_model.TenantId = sale_order.TenantId
  278. warehouse_record_model.CreateId = &user_id
  279. recordRefType := models.Warehouse_Record_Ref_Type_Product
  280. warehouse_record_model.RefType = &recordRefType
  281. warehouse_record_model.RefId = product_plan.ID
  282. warehouse_record_model.SaleOrderId = sale_order.ID
  283. err := services.JdbcClient.JdbcInsert(warehouse_record_model, tx)
  284. if err != nil {
  285. utils.PrintSqlErr(err)
  286. tx.Rollback()
  287. return c.JSON(http.StatusInternalServerError, utils.ErrorResponse("系统错误", ""))
  288. }
  289. warehouse_material_model := new(models.WarehouseMaterial)
  290. warehouse_material_model.WarehouseId = warehouseMaterial.WarehouseId
  291. warehouse_material_model.MaterialCode = detail.MaterialCode
  292. err = services.JdbcClient.GetJdbcModel(warehouse_material_model, tx)
  293. if err != nil {
  294. utils.PrintSqlErr(err)
  295. tx.Rollback()
  296. return c.JSON(http.StatusInternalServerError, utils.ErrorResponse("系统错误", ""))
  297. }
  298. warehouseMaterialNumber := *warehouse_material_model.Number - *warehouseMaterial.LockedNumber
  299. warehouse_material_model.Number = &warehouseMaterialNumber
  300. warehouseMaterialLockedNumber := *warehouse_material_model.LockedNumber + *warehouseMaterial.LockedNumber
  301. warehouse_material_model.LockedNumber = &warehouseMaterialLockedNumber
  302. warehouse_material_model.UpdateId = &user_id
  303. err = services.JdbcClient.JdbcUpdateById(warehouse_material_model, tx)
  304. if err != nil {
  305. utils.PrintSqlErr(err)
  306. tx.Rollback()
  307. return c.JSON(http.StatusInternalServerError, utils.ErrorResponse("系统错误", ""))
  308. }
  309. }
  310. }
  311. }
  312. purchase_plan_vo_list := *planVo.PurchasePlanVoList
  313. if len(purchase_plan_vo_list) > 0 {
  314. plan_filter_list := utils.Filter(purchase_plan_vo_list, func(item models.PurchasePlanVo) bool {
  315. return *item.PlanPurchaseNumber > 0
  316. })
  317. warehouse_filter_list := utils.Filter(purchase_plan_vo_list, func(item models.PurchasePlanVo) bool {
  318. return len(*item.WarehouseMaterialVoList) > 0
  319. })
  320. purchase_plan := new(models.PurchasePlan)
  321. if len(plan_filter_list) > 0 {
  322. purchase_plan.TenantId = sale_order.TenantId
  323. err_msg := purchasePlan_generateCode(purchase_plan, tx)
  324. if err_msg != "" {
  325. tx.Rollback()
  326. return c.JSON(http.StatusBadRequest, utils.ErrorResponse(err_msg, ""))
  327. }
  328. if planVo.PurchasePlanName != nil && len(*planVo.PurchasePlanName) > 0 {
  329. purchase_plan.Name = planVo.PurchasePlanName
  330. } else {
  331. purchase_plan.Name = purchase_plan.Code
  332. }
  333. purchase_plan.SaleOrderId = planVo.SaleOrderId
  334. purchasePlanStatus := models.Purchase_Plan_Status_Pending
  335. purchase_plan.Status = &purchasePlanStatus
  336. purchase_plan.TenantId = sale_order.TenantId
  337. purchase_plan.BeginDate = planVo.PlanBeginDate
  338. purchase_plan.EndDate = planVo.PlanEndDate
  339. purchase_plan.CreateId = &user_id
  340. err := services.JdbcClient.JdbcInsert(purchase_plan, tx)
  341. if err != nil {
  342. utils.PrintSqlErr(err)
  343. tx.Rollback()
  344. return c.JSON(http.StatusInternalServerError, utils.ErrorResponse("系统错误", ""))
  345. }
  346. }
  347. for _, detail := range plan_filter_list {
  348. purchase_plan_detail := new(models.PurchasePlanDetail)
  349. purchase_plan_detail.MaterialCode = detail.MaterialCode
  350. purchase_plan_detail.PlanId = purchase_plan.ID
  351. purchase_plan_detail.Number = detail.PlanPurchaseNumber
  352. err := services.JdbcClient.JdbcInsert(purchase_plan_detail, tx)
  353. if err != nil {
  354. utils.PrintSqlErr(err)
  355. tx.Rollback()
  356. return c.JSON(http.StatusInternalServerError, utils.ErrorResponse("系统错误", ""))
  357. }
  358. }
  359. for _, detail := range warehouse_filter_list {
  360. warehouseMaterialVoList := *detail.WarehouseMaterialVoList
  361. for _, warehouseMaterial := range warehouseMaterialVoList {
  362. warehouse_record_model := new(models.WarehouseRecord)
  363. recordType := models.Warehouse_Record_Type_Lock
  364. warehouse_record_model.Type = &recordType
  365. warehouse_record_model.MaterialCode = detail.MaterialCode
  366. warehouse_record_model.Number = warehouseMaterial.LockedNumber
  367. warehouse_record_model.FromWarehouseId = warehouseMaterial.WarehouseId
  368. warehouse_record_model.TenantId = sale_order.TenantId
  369. warehouse_record_model.CreateId = &user_id
  370. recordRefType := models.Warehouse_Record_Ref_Type_Purchase
  371. warehouse_record_model.RefType = &recordRefType
  372. warehouse_record_model.RefId = purchase_plan.ID
  373. warehouse_record_model.SaleOrderId = sale_order.ID
  374. err := services.JdbcClient.JdbcInsert(warehouse_record_model, tx)
  375. if err != nil {
  376. utils.PrintSqlErr(err)
  377. tx.Rollback()
  378. return c.JSON(http.StatusInternalServerError, utils.ErrorResponse("系统错误", ""))
  379. }
  380. warehouse_material_model := new(models.WarehouseMaterial)
  381. warehouse_material_model.WarehouseId = warehouseMaterial.WarehouseId
  382. warehouse_material_model.MaterialCode = detail.MaterialCode
  383. err = services.JdbcClient.GetJdbcModel(warehouse_material_model, tx)
  384. if err != nil {
  385. utils.PrintSqlErr(err)
  386. tx.Rollback()
  387. return c.JSON(http.StatusInternalServerError, utils.ErrorResponse("系统错误", ""))
  388. }
  389. warehouseMaterialNumber := *warehouse_material_model.Number - *warehouseMaterial.LockedNumber
  390. warehouse_material_model.Number = &warehouseMaterialNumber
  391. warehouseMaterialLockedNumber := *warehouse_material_model.LockedNumber + *warehouseMaterial.LockedNumber
  392. warehouse_material_model.LockedNumber = &warehouseMaterialLockedNumber
  393. warehouse_material_model.UpdateId = &user_id
  394. err = services.JdbcClient.JdbcUpdateById(warehouse_material_model, tx)
  395. if err != nil {
  396. utils.PrintSqlErr(err)
  397. tx.Rollback()
  398. return c.JSON(http.StatusInternalServerError, utils.ErrorResponse("系统错误", ""))
  399. }
  400. }
  401. }
  402. }
  403. outsourcing_plan_vo_list := *planVo.OutsourcingPlanVoList
  404. if len(outsourcing_plan_vo_list) > 0 {
  405. plan_filter_list := utils.Filter(outsourcing_plan_vo_list, func(item models.OutsourcingPlanVo) bool {
  406. return *item.PlanOutsourcingNumber > 0
  407. })
  408. warehouse_filter_list := utils.Filter(outsourcing_plan_vo_list, func(item models.OutsourcingPlanVo) bool {
  409. return len(*item.WarehouseMaterialVoList) > 0
  410. })
  411. outsourcing_plan := new(models.OutsourcingPlan)
  412. if len(plan_filter_list) > 0 {
  413. outsourcing_plan.TenantId = sale_order.TenantId
  414. err_msg := outsourcingPlan_generateCode(outsourcing_plan, tx)
  415. if err_msg != "" {
  416. tx.Rollback()
  417. return c.JSON(http.StatusBadRequest, utils.ErrorResponse(err_msg, ""))
  418. }
  419. if planVo.OutsourcingPlanName != nil && len(*planVo.OutsourcingPlanName) > 0 {
  420. outsourcing_plan.Name = planVo.OutsourcingPlanName
  421. } else {
  422. outsourcing_plan.Name = outsourcing_plan.Code
  423. }
  424. outsourcing_plan.SaleOrderId = planVo.SaleOrderId
  425. purchasePlanStatus := models.Outsourcing_Plan_Status_Pending
  426. outsourcing_plan.Status = &purchasePlanStatus
  427. outsourcing_plan.TenantId = sale_order.TenantId
  428. outsourcing_plan.BeginDate = planVo.PlanBeginDate
  429. outsourcing_plan.EndDate = planVo.PlanEndDate
  430. outsourcing_plan.CreateId = &user_id
  431. err := services.JdbcClient.JdbcInsert(outsourcing_plan, tx)
  432. if err != nil {
  433. utils.PrintSqlErr(err)
  434. tx.Rollback()
  435. return c.JSON(http.StatusInternalServerError, utils.ErrorResponse("系统错误", ""))
  436. }
  437. }
  438. for _, detail := range plan_filter_list {
  439. outsourcing_plan_detail := new(models.OutsourcingPlanDetail)
  440. outsourcing_plan_detail.MaterialCode = detail.MaterialCode
  441. outsourcing_plan_detail.PlanId = outsourcing_plan.ID
  442. outsourcing_plan_detail.Number = detail.PlanOutsourcingNumber
  443. err := services.JdbcClient.JdbcInsert(outsourcing_plan_detail, tx)
  444. if err != nil {
  445. utils.PrintSqlErr(err)
  446. tx.Rollback()
  447. return c.JSON(http.StatusInternalServerError, utils.ErrorResponse("系统错误", ""))
  448. }
  449. }
  450. for _, detail := range warehouse_filter_list {
  451. warehouseMaterialVoList := *detail.WarehouseMaterialVoList
  452. for _, warehouseMaterial := range warehouseMaterialVoList {
  453. warehouse_record_model := new(models.WarehouseRecord)
  454. recordType := models.Warehouse_Record_Type_Lock
  455. warehouse_record_model.Type = &recordType
  456. warehouse_record_model.MaterialCode = detail.MaterialCode
  457. warehouse_record_model.Number = warehouseMaterial.LockedNumber
  458. warehouse_record_model.FromWarehouseId = warehouseMaterial.WarehouseId
  459. warehouse_record_model.TenantId = sale_order.TenantId
  460. warehouse_record_model.CreateId = &user_id
  461. recordRefType := models.Warehouse_Record_Ref_Type_Outsourcing
  462. warehouse_record_model.RefType = &recordRefType
  463. warehouse_record_model.RefId = outsourcing_plan.ID
  464. warehouse_record_model.SaleOrderId = sale_order.ID
  465. err := services.JdbcClient.JdbcInsert(warehouse_record_model, tx)
  466. if err != nil {
  467. utils.PrintSqlErr(err)
  468. tx.Rollback()
  469. return c.JSON(http.StatusInternalServerError, utils.ErrorResponse("系统错误", ""))
  470. }
  471. warehouse_material_model := new(models.WarehouseMaterial)
  472. warehouse_material_model.WarehouseId = warehouseMaterial.WarehouseId
  473. warehouse_material_model.MaterialCode = detail.MaterialCode
  474. err = services.JdbcClient.GetJdbcModel(warehouse_material_model, tx)
  475. if err != nil {
  476. utils.PrintSqlErr(err)
  477. tx.Rollback()
  478. return c.JSON(http.StatusInternalServerError, utils.ErrorResponse("系统错误", ""))
  479. }
  480. warehouseMaterialNumber := *warehouse_material_model.Number - *warehouseMaterial.LockedNumber
  481. warehouse_material_model.Number = &warehouseMaterialNumber
  482. warehouseMaterialLockedNumber := *warehouse_material_model.LockedNumber + *warehouseMaterial.LockedNumber
  483. warehouse_material_model.LockedNumber = &warehouseMaterialLockedNumber
  484. warehouse_material_model.UpdateId = &user_id
  485. err = services.JdbcClient.JdbcUpdateById(warehouse_material_model, tx)
  486. if err != nil {
  487. utils.PrintSqlErr(err)
  488. tx.Rollback()
  489. return c.JSON(http.StatusInternalServerError, utils.ErrorResponse("系统错误", ""))
  490. }
  491. }
  492. }
  493. }
  494. tx.Commit()
  495. return c.JSON(http.StatusOK, planVo)
  496. }