智慧食堂
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

hdl_enterprise.go 16 KiB

pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 1 gada
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588
  1. package hdl
  2. import (
  3. enum2 "applet/app/admin/enum"
  4. "applet/app/admin/lib/validate"
  5. "applet/app/admin/md"
  6. "applet/app/admin/svc"
  7. "applet/app/db"
  8. "applet/app/db/model"
  9. "applet/app/e"
  10. "applet/app/enum"
  11. "applet/app/utils"
  12. "github.com/gin-gonic/gin"
  13. "time"
  14. )
  15. func EnterpriseList(c *gin.Context) {
  16. var req md.EnterpriseListReq
  17. err := c.ShouldBindJSON(&req)
  18. if err != nil {
  19. err = validate.HandleValidateErr(err)
  20. err1 := err.(e.E)
  21. e.OutErr(c, err1.Code, err1.Error())
  22. return
  23. }
  24. if req.Limit == 0 {
  25. req.Limit = 10
  26. }
  27. if req.Page == 0 {
  28. req.Page = 10
  29. }
  30. admin := svc.GetUser(c)
  31. enterprises, total, err := svc.EnterpriseList(*admin, req)
  32. if err != nil {
  33. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  34. return
  35. }
  36. e.OutSuc(c, map[string]interface{}{
  37. "list": enterprises,
  38. "total": total,
  39. "state": []map[string]interface{}{
  40. {
  41. "name": enum.EnterpriseState(enum.EnterpriseStateForNormal).String(),
  42. "value": enum.EnterpriseStateForNormal,
  43. },
  44. {
  45. "name": enum.EnterpriseState(enum.EnterpriseStateForFreeze).String(),
  46. "value": enum.EnterpriseStateForFreeze,
  47. },
  48. },
  49. "kind": []map[string]interface{}{
  50. {
  51. "name": enum.EnterprisePvd(enum.EnterprisePvdByCentralKitchenForSchool).String(),
  52. "value": enum.EnterprisePvdByCentralKitchenForSchool,
  53. },
  54. {
  55. "name": enum.EnterprisePvd(enum.EnterprisePvdByCentralKitchenForFactory).String(),
  56. "value": enum.EnterprisePvdByCentralKitchenForFactory,
  57. },
  58. {
  59. "name": enum.EnterprisePvd(enum.EnterprisePvdBySelfSupportForSchool).String(),
  60. "value": enum.EnterprisePvdBySelfSupportForSchool,
  61. },
  62. {
  63. "name": enum.EnterprisePvd(enum.EnterprisePvdBySelfSupportForFactory).String(),
  64. "value": enum.EnterprisePvdBySelfSupportForFactory,
  65. },
  66. {
  67. "name": enum.EnterprisePvd(enum.EnterprisePvdByNursingHome).String(),
  68. "value": enum.EnterprisePvdByNursingHome,
  69. },
  70. },
  71. }, nil)
  72. return
  73. }
  74. func Detail(c *gin.Context) {
  75. enterpriseId := c.DefaultQuery("id", "")
  76. detail, err := svc.EnterpriseDetail(utils.StrToInt(enterpriseId))
  77. if err != nil {
  78. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  79. return
  80. }
  81. e.OutSuc(c, detail, nil)
  82. return
  83. }
  84. func SchoolBelowGrade(c *gin.Context) {
  85. enterpriseId := c.DefaultQuery("enterprise_id", "")
  86. gradeDb := db.GradeDb{}
  87. gradeDb.Set(utils.StrToInt(enterpriseId))
  88. gradeList, err := gradeDb.FindGrade()
  89. if err != nil {
  90. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  91. return
  92. }
  93. e.OutSuc(c, map[string]interface{}{
  94. "list": gradeList,
  95. }, nil)
  96. return
  97. }
  98. func SchoolGradeBelowClass(c *gin.Context) {
  99. gradeId := c.DefaultQuery("grade_id", "")
  100. enterpriseId := c.DefaultQuery("enterprise_id", "")
  101. classDb := db.ClassDb{}
  102. if gradeId != "" {
  103. classDb.Set(utils.StrToInt(gradeId))
  104. classList, err := classDb.FindClass()
  105. if err != nil {
  106. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  107. return
  108. }
  109. e.OutSuc(c, map[string]interface{}{
  110. "list": classList,
  111. }, nil)
  112. } else {
  113. classDb.Set(0)
  114. classList, err := classDb.FindClassByEnterprise(enterpriseId)
  115. if err != nil {
  116. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  117. return
  118. }
  119. e.OutSuc(c, map[string]interface{}{
  120. "list": classList,
  121. }, nil)
  122. }
  123. return
  124. }
  125. func EnterpriseAdd(c *gin.Context) {
  126. var req md.EnterpriseAddReq
  127. err := c.ShouldBindJSON(&req)
  128. if err != nil {
  129. err = validate.HandleValidateErr(err)
  130. err1 := err.(e.E)
  131. e.OutErr(c, err1.Code, err1.Error())
  132. return
  133. }
  134. enterpriseDb := db.EnterpriseDb{}
  135. enterpriseDb.Set()
  136. now := time.Now()
  137. var pvd = 2
  138. if req.Kind == enum.EnterprisePvdByCentralKitchenForSchool || req.Kind == enum.EnterprisePvdByCentralKitchenForFactory {
  139. pvd = 1
  140. }
  141. enterprise := model.Enterprise{
  142. Name: req.Name,
  143. Pvd: int32(pvd),
  144. Kind: req.Kind,
  145. CompanyId: req.CompanyId,
  146. State: enum2.CompanyStateForNormal,
  147. Memo: req.Memo,
  148. CreateAt: now.Format("2006-01-02 15:04:05"),
  149. UpdateAt: now.Format("2006-01-02 15:04:05"),
  150. }
  151. enterpriseId, err := enterpriseDb.EnterpriseInsert(&enterprise)
  152. if err != nil {
  153. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  154. return
  155. }
  156. if req.Kind == enum.EnterprisePvdByCentralKitchenForSchool {
  157. //新增 `central_kitchen_for_school_set` && `central_kitchen_for_school_with_spec`
  158. centralKitchenForSchoolSetDb := db.CentralKitchenForSchoolSetDb{}
  159. centralKitchenForSchoolSetDb.Set(enterpriseId)
  160. centralKitchenForSchoolSetDb.CentralKitchenForSchoolSetInsert(&model.CentralKitchenForSchoolSet{
  161. EnterpriseId: enterpriseId,
  162. IsOpenTeacherReportMeal: 1,
  163. IsOpenReportMealForDay: 1,
  164. IsOpenReportMealForMonth: 1,
  165. IsOpenReportMealForSemester: 1,
  166. CreateAt: now.Format("2006-01-02 15:04:05"),
  167. UpdateAt: now.Format("2006-01-02 15:04:05"),
  168. })
  169. centralKitchenForSchoolWithSpec := db.CentralKitchenForSchoolWithSpec{}
  170. centralKitchenForSchoolWithSpec.Set(enterpriseId)
  171. centralKitchenForSchoolWithSpec.CentralKitchenForSchoolWithSpecInsert(&model.CentralKitchenForSchoolWithSpec{
  172. EnterpriseId: enterpriseId,
  173. IsOpenBreakfast: 1,
  174. IsOpenLunch: 1,
  175. IsOpenDinner: 1,
  176. BreakfastUnitPrice: "0.00",
  177. LunchUnitPrice: "0.00",
  178. DinnerUnitPrice: "0.00",
  179. BreakfastUnitPriceForTeacher: "0.00",
  180. LunchUnitPriceForTeacher: "0.00",
  181. DinnerUnitPriceForTeacher: "0.00",
  182. CreateAt: now.Format("2006-01-02 15:04:05"),
  183. UpdateAt: now.Format("2006-01-02 15:04:05"),
  184. })
  185. }
  186. if req.Kind == enum.EnterprisePvdByNursingHome {
  187. //新增 `nursing_home_set` && `nursing_home_with_spec`
  188. nursingHomeSetDb := db.NursingHomeSetDb{}
  189. nursingHomeSetDb.Set(enterpriseId)
  190. nursingHomeSetDb.NursingHomeSetInsert(&model.NursingHomeSet{
  191. EnterpriseId: enterpriseId,
  192. IsOpenReportMealForDay: 1,
  193. IsOpenReportMealForMonth: 1,
  194. IsOpenReportMealForYear: 1,
  195. CreateAt: now.Format("2006-01-02 15:04:05"),
  196. UpdateAt: now.Format("2006-01-02 15:04:05"),
  197. })
  198. nursingHomeWithSpec := db.NursingHomeWithSpec{}
  199. nursingHomeWithSpec.Set(enterpriseId)
  200. nursingHomeWithSpec.NursingHomeWithSpecInsert(&model.NursingHomeWithSpec{
  201. EnterpriseId: enterpriseId,
  202. IsOpenBreakfast: 1,
  203. IsOpenLunch: 1,
  204. IsOpenDinner: 1,
  205. BreakfastUnitPrice: "0.00",
  206. LunchUnitPrice: "0.00",
  207. DinnerUnitPrice: "0.00",
  208. CreateAt: now.Format("2006-01-02 15:04:05"),
  209. UpdateAt: now.Format("2006-01-02 15:04:05"),
  210. })
  211. }
  212. e.OutSuc(c, "success", nil)
  213. return
  214. }
  215. func EnterpriseDelete(c *gin.Context) {
  216. var req md.EnterpriseDeleteReq
  217. err := c.ShouldBindJSON(&req)
  218. if err != nil {
  219. err = validate.HandleValidateErr(err)
  220. err1 := err.(e.E)
  221. e.OutErr(c, err1.Code, err1.Error())
  222. return
  223. }
  224. err = svc.EnterpriseDelete(req.EnterpriseIds)
  225. if err != nil {
  226. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  227. return
  228. }
  229. e.OutSuc(c, "success", nil)
  230. return
  231. }
  232. func EnterpriseUpdate(c *gin.Context) {
  233. var req md.EnterpriseUpdateReq
  234. err := c.ShouldBindJSON(&req)
  235. if err != nil {
  236. err = validate.HandleValidateErr(err)
  237. err1 := err.(e.E)
  238. e.OutErr(c, err1.Code, err1.Error())
  239. return
  240. }
  241. //1、更新 enterprise
  242. enterpriseDb := db.EnterpriseDb{}
  243. enterpriseDb.Set()
  244. enterprise, err := enterpriseDb.GetEnterprise(req.Id)
  245. if err != nil {
  246. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  247. return
  248. }
  249. if enterprise == nil {
  250. e.OutErr(c, e.ERR_NO_DATA, "未查询到对应记录")
  251. return
  252. }
  253. var pvd = 2
  254. if req.Kind == enum.EnterprisePvdByCentralKitchenForSchool || req.Kind == enum.EnterprisePvdByCentralKitchenForFactory || req.Kind == enum.EnterprisePvdByNursingHome {
  255. pvd = 1
  256. }
  257. now := time.Now()
  258. enterprise.Name = req.Name
  259. enterprise.Memo = req.Memo
  260. enterprise.Pvd = int32(pvd)
  261. enterprise.Kind = req.Kind
  262. enterprise.CompanyId = req.CompanyId
  263. enterprise.UpdateAt = now.Format("2006-01-02 15:04:05")
  264. _, err = enterpriseDb.EnterpriseUpdate(enterprise, "name", "memo", "pvd", "kind", "company_id", "update_at")
  265. if err != nil {
  266. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  267. return
  268. }
  269. //2、更新 grade && class 数据
  270. //2、删除 grade && class 数据
  271. gradeDb := db.GradeDb{}
  272. gradeDb.Set(req.Id)
  273. //_, err = gradeDb.ClassDeleteBySessionForEnterprise(db.Db.NewSession(), req.Id)
  274. //if err != nil {
  275. // e.OutErr(c, e.ERR_DB_ORM, err.Error())
  276. // return
  277. //}
  278. classDb := db.ClassDb{}
  279. classDb.Set(0)
  280. //_, err = classDb.ClassDeleteBySessionForEnterprise(db.Db.NewSession(), req.Id)
  281. //if err != nil {
  282. // e.OutErr(c, e.ERR_DB_ORM, err.Error())
  283. // return
  284. //}
  285. //新增 grade 数据 && class 数据
  286. for _, v := range req.GradeList {
  287. var classes []*model.Class
  288. if v.Id == 0 {
  289. //TODO::新增
  290. insertId, err1 := gradeDb.GradeInsert(&model.Grade{
  291. EnterpriseId: req.Id,
  292. Name: v.Name,
  293. Memo: "",
  294. CreateAt: now.Format("2006-01-02 15:04:05"),
  295. UpdateAt: now.Format("2006-01-02 15:04:05"),
  296. })
  297. if err1 != nil {
  298. e.OutErr(c, e.ERR_DB_ORM, err1.Error())
  299. return
  300. }
  301. for _, v1 := range v.ClassList {
  302. classes = append(classes, &model.Class{
  303. Name: v1.Name,
  304. Memo: "",
  305. GradeId: insertId,
  306. EnterpriseId: req.Id,
  307. CreateAt: now.Format("2006-01-02 15:04:05"),
  308. UpdateAt: now.Format("2006-01-02 15:04:05"),
  309. })
  310. }
  311. } else {
  312. //TODO::编辑
  313. grade, err3 := gradeDb.GetGrade(v.Id)
  314. if err3 != nil {
  315. e.OutErr(c, e.ERR_DB_ORM, err3.Error())
  316. return
  317. }
  318. if grade == nil {
  319. e.OutErr(c, e.ERR_NO_DATA, "未查询到相关年级信息")
  320. return
  321. }
  322. grade.Name = v.Name
  323. _, err4 := gradeDb.GradeUpdate(grade, "name")
  324. if err4 != nil {
  325. e.OutErr(c, e.ERR_DB_ORM, err4.Error())
  326. return
  327. }
  328. for _, v1 := range v.ClassList {
  329. if v1.Id == 0 {
  330. //新增
  331. classes = append(classes, &model.Class{
  332. Name: v1.Name,
  333. Memo: "",
  334. GradeId: grade.Id,
  335. EnterpriseId: req.Id,
  336. CreateAt: now.Format("2006-01-02 15:04:05"),
  337. UpdateAt: now.Format("2006-01-02 15:04:05"),
  338. })
  339. } else {
  340. //编辑
  341. class, err5 := classDb.GetClass(v1.Id)
  342. if err5 != nil {
  343. e.OutErr(c, e.ERR_DB_ORM, err5.Error())
  344. return
  345. }
  346. if class == nil {
  347. e.OutErr(c, e.ERR_NO_DATA, "未查询到相关班级信息")
  348. return
  349. }
  350. class.Name = v1.Name
  351. _, err6 := classDb.ClassUpdate(class, "name")
  352. if err6 != nil {
  353. e.OutErr(c, e.ERR_DB_ORM, err6.Error())
  354. return
  355. }
  356. }
  357. }
  358. }
  359. if len(classes) > 0 {
  360. _, err2 := classDb.BatchAddClass(classes)
  361. if err2 != nil {
  362. e.OutErr(c, e.ERR_DB_ORM, err2.Error())
  363. return
  364. }
  365. }
  366. }
  367. e.OutSuc(c, "success", nil)
  368. return
  369. }
  370. func EnterpriseAddGrade(c *gin.Context) {
  371. var req md.EnterpriseUpdateStateReq
  372. err := c.ShouldBindJSON(&req)
  373. if err != nil {
  374. err = validate.HandleValidateErr(err)
  375. err1 := err.(e.E)
  376. e.OutErr(c, err1.Code, err1.Error())
  377. return
  378. }
  379. enterpriseDb := db.EnterpriseDb{}
  380. enterpriseDb.Set()
  381. enterprise, err := enterpriseDb.GetEnterprise(req.Id)
  382. if err != nil {
  383. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  384. return
  385. }
  386. if enterprise == nil {
  387. e.OutErr(c, e.ERR_NO_DATA, "未查询到对应记录")
  388. return
  389. }
  390. now := time.Now()
  391. enterprise.State = req.State
  392. enterprise.UpdateAt = now.Format("2006-01-02 15:04:05")
  393. _, err = enterpriseDb.EnterpriseUpdate(enterprise, "state", "update_at")
  394. if err != nil {
  395. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  396. return
  397. }
  398. e.OutSuc(c, "success", nil)
  399. return
  400. }
  401. func EnterpriseUpdateState(c *gin.Context) {
  402. var req md.EnterpriseUpdateStateReq
  403. err := c.ShouldBindJSON(&req)
  404. if err != nil {
  405. err = validate.HandleValidateErr(err)
  406. err1 := err.(e.E)
  407. e.OutErr(c, err1.Code, err1.Error())
  408. return
  409. }
  410. enterpriseDb := db.EnterpriseDb{}
  411. enterpriseDb.Set()
  412. enterprise, err := enterpriseDb.GetEnterprise(req.Id)
  413. if err != nil {
  414. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  415. return
  416. }
  417. if enterprise == nil {
  418. e.OutErr(c, e.ERR_NO_DATA, "未查询到对应记录")
  419. return
  420. }
  421. now := time.Now()
  422. enterprise.State = req.State
  423. enterprise.UpdateAt = now.Format("2006-01-02 15:04:05")
  424. _, err = enterpriseDb.EnterpriseUpdate(enterprise, "state", "update_at")
  425. if err != nil {
  426. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  427. return
  428. }
  429. e.OutSuc(c, "success", nil)
  430. return
  431. }
  432. func ListCentralKitchenForSchoolPackageForSystem(c *gin.Context) {
  433. var req md.ListCentralKitchenForSchoolPackageForSystemReq
  434. err := c.ShouldBindJSON(&req)
  435. if err != nil {
  436. err = validate.HandleValidateErr(err)
  437. err1 := err.(e.E)
  438. e.OutErr(c, err1.Code, err1.Error())
  439. return
  440. }
  441. centralKitchenForSchoolPackageForSystemDb := db.CentralKitchenForSchoolPackageForSystemDb{}
  442. centralKitchenForSchoolPackageForSystemDb.Set()
  443. list, total, err := centralKitchenForSchoolPackageForSystemDb.CentralKitchenForSchoolPackageForSystemList(req)
  444. if err != nil {
  445. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  446. return
  447. }
  448. e.OutSuc(c, map[string]interface{}{
  449. "list": list,
  450. "total": total,
  451. }, nil)
  452. return
  453. }
  454. func SetCentralKitchenForSchoolWithSpecForSystem(c *gin.Context) {
  455. var req md.SetCentralKitchenForSchoolWithSpecForSystemReq
  456. err := c.ShouldBindJSON(&req)
  457. if err != nil {
  458. err = validate.HandleValidateErr(err)
  459. err1 := err.(e.E)
  460. e.OutErr(c, err1.Code, err1.Error())
  461. return
  462. }
  463. centralKitchenForSchoolWithSpecForSystemDb := db.CentralKitchenForSchoolWithSpecForSystem{}
  464. centralKitchenForSchoolWithSpecForSystemDb.Set()
  465. system, err := centralKitchenForSchoolWithSpecForSystemDb.GetCentralKitchenForSchoolWithSpecForSystem()
  466. if err != nil {
  467. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  468. return
  469. }
  470. system.BreakfastUnitPrice = req.BreakfastUnitPrice
  471. system.LunchUnitPrice = req.LunchUnitPrice
  472. system.DinnerUnitPrice = req.DinnerUnitPrice
  473. system.BreakfastUnitPriceForTeacher = req.BreakfastUnitPriceForTeacher
  474. system.LunchUnitPriceForTeacher = req.LunchUnitPriceForTeacher
  475. system.DinnerUnitPriceForTeacher = req.DinnerUnitPriceForTeacher
  476. system.UpdateAt = time.Now().Format("2006-01-02 15:04:05")
  477. updateAffected, err := centralKitchenForSchoolWithSpecForSystemDb.CentralKitchenForSchoolWithSpecForSystemUpdate(system.Id, system)
  478. if err != nil {
  479. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  480. return
  481. }
  482. if updateAffected <= 0 {
  483. e.OutErr(c, e.ERR, "更新数据失败")
  484. return
  485. }
  486. e.OutSuc(c, "success", nil)
  487. return
  488. }
  489. func GetCentralKitchenForSchoolWithSpecForSystem(c *gin.Context) {
  490. centralKitchenForSchoolWithSpecForSystemDb := db.CentralKitchenForSchoolWithSpecForSystem{}
  491. centralKitchenForSchoolWithSpecForSystemDb.Set()
  492. system, err := centralKitchenForSchoolWithSpecForSystemDb.GetCentralKitchenForSchoolWithSpecForSystem()
  493. if err != nil {
  494. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  495. return
  496. }
  497. e.OutSuc(c, map[string]interface{}{
  498. "data": system,
  499. }, nil)
  500. return
  501. }
  502. func SaveCentralKitchenForSchoolPackageForSystem(c *gin.Context) {
  503. var req md.SaveCentralKitchenForSchoolPackageForSystemReq
  504. err := c.ShouldBindJSON(&req)
  505. if err != nil {
  506. err = validate.HandleValidateErr(err)
  507. err1 := err.(e.E)
  508. e.OutErr(c, err1.Code, err1.Error())
  509. return
  510. }
  511. //判断是新增 / 编辑
  512. if req.Id > 0 {
  513. err = svc.UpdateCentralKitchenForSchoolPackageForSystem(req)
  514. if err != nil {
  515. e.OutErr(c, e.ERR, err.Error())
  516. return
  517. }
  518. } else {
  519. err = svc.AddCentralKitchenForSchoolPackageForSystem(req)
  520. if err != nil {
  521. e.OutErr(c, e.ERR, err.Error())
  522. return
  523. }
  524. }
  525. e.OutSuc(c, "success", nil)
  526. return
  527. }
  528. func SyncCentralKitchenForSchoolPackageForSystem(c *gin.Context) {
  529. var req md.SyncCentralKitchenForSchoolPackageForSystemReq
  530. err := c.ShouldBindJSON(&req)
  531. if err != nil {
  532. err = validate.HandleValidateErr(err)
  533. err1 := err.(e.E)
  534. e.OutErr(c, err1.Code, err1.Error())
  535. return
  536. }
  537. err = svc.SyncCentralKitchenForSchoolPackageForSystem(req)
  538. if err != nil {
  539. e.OutErr(c, e.ERR, err.Error())
  540. return
  541. }
  542. e.OutSuc(c, "success", nil)
  543. return
  544. }
  545. func DeleteCentralKitchenForSchoolPackageForSystem(c *gin.Context) {
  546. id := c.Param("id")
  547. err := svc.DeleteCentralKitchenForSchoolPackageForSystem(utils.StrToInt(id))
  548. if err != nil {
  549. e.OutErr(c, e.ERR, err.Error())
  550. return
  551. }
  552. e.OutSuc(c, "success", nil)
  553. return
  554. }