智慧食堂
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

838 lignes
22 KiB

  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. enterpriseDb := db.EnterpriseDb{}
  77. enterpriseDb.Set()
  78. enterprise, err := enterpriseDb.GetEnterprise(utils.StrToInt(enterpriseId))
  79. if err != nil {
  80. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  81. return
  82. }
  83. if enterprise.Kind == enum.EnterprisePvdBySelfSupportForSchool {
  84. detail, err := svc.EnterpriseDetailV2(utils.StrToInt(enterpriseId))
  85. if err != nil {
  86. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  87. return
  88. }
  89. e.OutSuc(c, detail, nil)
  90. return
  91. }
  92. detail, err := svc.EnterpriseDetail(utils.StrToInt(enterpriseId))
  93. if err != nil {
  94. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  95. return
  96. }
  97. e.OutSuc(c, detail, nil)
  98. return
  99. }
  100. func SchoolBelowGrade(c *gin.Context) {
  101. enterpriseId := c.DefaultQuery("enterprise_id", "")
  102. gradeDb := db.GradeDb{}
  103. gradeDb.Set(utils.StrToInt(enterpriseId))
  104. gradeList, err := gradeDb.FindGrade()
  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": gradeList,
  111. }, nil)
  112. return
  113. }
  114. func PeriodBelowGrade(c *gin.Context) {
  115. periodId := c.DefaultQuery("period_id", "")
  116. periodDb := db.PeriodDb{}
  117. periodDb.Set(0)
  118. period, err1 := periodDb.GetPeriod(utils.StrToInt(periodId))
  119. if err1 != nil {
  120. e.OutErr(c, e.ERR_DB_ORM, err1.Error())
  121. return
  122. }
  123. if period == nil {
  124. e.OutErr(c, e.ERR_NO_DATA, "未查询到相关学段信息")
  125. return
  126. }
  127. gradeDb := db.GradeDb{}
  128. gradeDb.Set(period.EnterpriseId)
  129. gradeList, err := gradeDb.FindGradeByPeriodId(period.Id)
  130. if err != nil {
  131. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  132. return
  133. }
  134. e.OutSuc(c, map[string]interface{}{
  135. "list": gradeList,
  136. }, nil)
  137. return
  138. }
  139. func SchoolBelowPeriod(c *gin.Context) {
  140. enterpriseId := c.DefaultQuery("enterprise_id", "")
  141. periodDb := db.PeriodDb{}
  142. periodDb.Set(utils.StrToInt(enterpriseId))
  143. periodList, err := periodDb.FindPeriod()
  144. if err != nil {
  145. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  146. return
  147. }
  148. e.OutSuc(c, map[string]interface{}{
  149. "list": periodList,
  150. }, nil)
  151. return
  152. }
  153. func SchoolGradeBelowClass(c *gin.Context) {
  154. gradeId := c.DefaultQuery("grade_id", "")
  155. enterpriseId := c.DefaultQuery("enterprise_id", "")
  156. classDb := db.ClassDb{}
  157. if gradeId != "" {
  158. classDb.Set(utils.StrToInt(gradeId))
  159. classList, err := classDb.FindClass()
  160. if err != nil {
  161. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  162. return
  163. }
  164. e.OutSuc(c, map[string]interface{}{
  165. "list": classList,
  166. }, nil)
  167. } else {
  168. classDb.Set(0)
  169. classList, err := classDb.FindClassByEnterprise(enterpriseId)
  170. if err != nil {
  171. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  172. return
  173. }
  174. e.OutSuc(c, map[string]interface{}{
  175. "list": classList,
  176. }, nil)
  177. }
  178. return
  179. }
  180. func EnterpriseAdd(c *gin.Context) {
  181. var req md.EnterpriseAddReq
  182. err := c.ShouldBindJSON(&req)
  183. if err != nil {
  184. err = validate.HandleValidateErr(err)
  185. err1 := err.(e.E)
  186. e.OutErr(c, err1.Code, err1.Error())
  187. return
  188. }
  189. enterpriseDb := db.EnterpriseDb{}
  190. enterpriseDb.Set()
  191. now := time.Now()
  192. var pvd = 2
  193. if req.Kind == enum.EnterprisePvdByCentralKitchenForSchool || req.Kind == enum.EnterprisePvdByCentralKitchenForFactory {
  194. pvd = 1
  195. }
  196. enterprise := model.Enterprise{
  197. Name: req.Name,
  198. Pvd: int32(pvd),
  199. Kind: req.Kind,
  200. CompanyId: req.CompanyId,
  201. State: enum2.CompanyStateForNormal,
  202. Memo: req.Memo,
  203. CreateAt: now.Format("2006-01-02 15:04:05"),
  204. UpdateAt: now.Format("2006-01-02 15:04:05"),
  205. }
  206. enterpriseId, err := enterpriseDb.EnterpriseInsert(&enterprise)
  207. if err != nil {
  208. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  209. return
  210. }
  211. if req.Kind == enum.EnterprisePvdByCentralKitchenForSchool {
  212. //新增 `central_kitchen_for_school_set` && `central_kitchen_for_school_with_spec`
  213. centralKitchenForSchoolSetDb := db.CentralKitchenForSchoolSetDb{}
  214. centralKitchenForSchoolSetDb.Set(enterpriseId)
  215. centralKitchenForSchoolSetDb.CentralKitchenForSchoolSetInsert(&model.CentralKitchenForSchoolSet{
  216. EnterpriseId: enterpriseId,
  217. IsOpenTeacherReportMeal: 1,
  218. IsOpenReportMealForDay: 1,
  219. IsOpenReportMealForMonth: 1,
  220. IsOpenReportMealForSemester: 1,
  221. IsOpenTeacherReportMealForDay: 1,
  222. IsOpenTeacherReportMealForMonth: 1,
  223. IsOpenTeacherReportMealForSemester: 1,
  224. CreateAt: now.Format("2006-01-02 15:04:05"),
  225. UpdateAt: now.Format("2006-01-02 15:04:05"),
  226. })
  227. centralKitchenForSchoolWithSpec := db.CentralKitchenForSchoolWithSpec{}
  228. centralKitchenForSchoolWithSpec.Set(enterpriseId)
  229. centralKitchenForSchoolWithSpec.CentralKitchenForSchoolWithSpecInsert(&model.CentralKitchenForSchoolWithSpec{
  230. EnterpriseId: enterpriseId,
  231. IsOpenBreakfast: 1,
  232. IsOpenLunch: 1,
  233. IsOpenDinner: 1,
  234. BreakfastUnitPrice: "0.00",
  235. LunchUnitPrice: "0.00",
  236. DinnerUnitPrice: "0.00",
  237. BreakfastUnitPriceForTeacher: "0.00",
  238. LunchUnitPriceForTeacher: "0.00",
  239. DinnerUnitPriceForTeacher: "0.00",
  240. CreateAt: now.Format("2006-01-02 15:04:05"),
  241. UpdateAt: now.Format("2006-01-02 15:04:05"),
  242. })
  243. }
  244. if req.Kind == enum.EnterprisePvdByNursingHome {
  245. //新增 `nursing_home_set` && `nursing_home_with_spec`
  246. nursingHomeSetDb := db.NursingHomeSetDb{}
  247. nursingHomeSetDb.Set(enterpriseId)
  248. nursingHomeSetDb.NursingHomeSetInsert(&model.NursingHomeSet{
  249. EnterpriseId: enterpriseId,
  250. IsOpenReportMealForDay: 1,
  251. IsOpenReportMealForMonth: 1,
  252. IsOpenReportMealForYear: 1,
  253. CreateAt: now.Format("2006-01-02 15:04:05"),
  254. UpdateAt: now.Format("2006-01-02 15:04:05"),
  255. })
  256. nursingHomeWithSpec := db.NursingHomeWithSpec{}
  257. nursingHomeWithSpec.Set(enterpriseId)
  258. nursingHomeWithSpec.NursingHomeWithSpecInsert(&model.NursingHomeWithSpec{
  259. EnterpriseId: enterpriseId,
  260. IsOpenBreakfast: 1,
  261. IsOpenLunch: 1,
  262. IsOpenDinner: 1,
  263. BreakfastUnitPrice: "0.00",
  264. LunchUnitPrice: "0.00",
  265. DinnerUnitPrice: "0.00",
  266. CreateAt: now.Format("2006-01-02 15:04:05"),
  267. UpdateAt: now.Format("2006-01-02 15:04:05"),
  268. })
  269. }
  270. e.OutSuc(c, "success", nil)
  271. return
  272. }
  273. func EnterpriseDelete(c *gin.Context) {
  274. var req md.EnterpriseDeleteReq
  275. err := c.ShouldBindJSON(&req)
  276. if err != nil {
  277. err = validate.HandleValidateErr(err)
  278. err1 := err.(e.E)
  279. e.OutErr(c, err1.Code, err1.Error())
  280. return
  281. }
  282. err = svc.EnterpriseDelete(req.EnterpriseIds)
  283. if err != nil {
  284. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  285. return
  286. }
  287. e.OutSuc(c, "success", nil)
  288. return
  289. }
  290. func CentralKitchenForSchoolUpdate(c *gin.Context) {
  291. var req md.CentralKitchenForSchoolUpdateReq
  292. err := c.ShouldBindJSON(&req)
  293. if err != nil {
  294. err = validate.HandleValidateErr(err)
  295. err1 := err.(e.E)
  296. e.OutErr(c, err1.Code, err1.Error())
  297. return
  298. }
  299. //1、更新 enterprise
  300. enterpriseDb := db.EnterpriseDb{}
  301. enterpriseDb.Set()
  302. enterprise, err := enterpriseDb.GetEnterprise(req.Id)
  303. if err != nil {
  304. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  305. return
  306. }
  307. if enterprise == nil {
  308. e.OutErr(c, e.ERR_NO_DATA, "未查询到对应记录")
  309. return
  310. }
  311. var pvd = 2
  312. if req.Kind == enum.EnterprisePvdByCentralKitchenForSchool || req.Kind == enum.EnterprisePvdByCentralKitchenForFactory || req.Kind == enum.EnterprisePvdByNursingHome {
  313. pvd = 1
  314. }
  315. now := time.Now()
  316. enterprise.Name = req.Name
  317. enterprise.Memo = req.Memo
  318. enterprise.Pvd = int32(pvd)
  319. enterprise.Kind = req.Kind
  320. enterprise.CompanyId = req.CompanyId
  321. enterprise.UpdateAt = now.Format("2006-01-02 15:04:05")
  322. _, err = enterpriseDb.EnterpriseUpdate(enterprise, "name", "memo", "pvd", "kind", "company_id", "update_at")
  323. if err != nil {
  324. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  325. return
  326. }
  327. //2、更新 period && grade && class 数据
  328. periodDb := db.PeriodDb{}
  329. periodDb.Set(req.Id)
  330. gradeDb := db.GradeDb{}
  331. gradeDb.Set(req.Id)
  332. classDb := db.ClassDb{}
  333. classDb.Set(0)
  334. //新增 grade 数据 && class 数据
  335. var classes []*model.Class
  336. for _, v := range req.PeriodList {
  337. if v.Id == 0 {
  338. //TODO::新增
  339. insertId, err1 := periodDb.PeriodInsert(&model.Period{
  340. EnterpriseId: req.Id,
  341. Name: v.Name,
  342. BreakfastUnitPrice: "0.00",
  343. LunchUnitPrice: "0.00",
  344. DinnerUnitPrice: "0.00",
  345. CreateAt: now.Format("2006-01-02 15:04:05"),
  346. UpdateAt: now.Format("2006-01-02 15:04:05"),
  347. })
  348. if err1 != nil {
  349. e.OutErr(c, e.ERR_DB_ORM, err1.Error())
  350. return
  351. }
  352. for _, v1 := range v.GradeList {
  353. insertId1, err2 := gradeDb.GradeInsert(&model.Grade{
  354. Name: v1.Name,
  355. Memo: "",
  356. PeriodId: insertId,
  357. EnterpriseId: req.Id,
  358. CreateAt: now.Format("2006-01-02 15:04:05"),
  359. UpdateAt: now.Format("2006-01-02 15:04:05"),
  360. })
  361. if err2 != nil {
  362. e.OutErr(c, e.ERR_DB_ORM, err2.Error())
  363. return
  364. }
  365. for _, v2 := range v1.ClassList {
  366. classes = append(classes, &model.Class{
  367. Name: v2.Name,
  368. Memo: "",
  369. GradeId: insertId1,
  370. EnterpriseId: req.Id,
  371. CreateAt: now.Format("2006-01-02 15:04:05"),
  372. UpdateAt: now.Format("2006-01-02 15:04:05"),
  373. })
  374. }
  375. }
  376. } else {
  377. //TODO::编辑
  378. period, err1 := periodDb.GetPeriod(v.Id)
  379. if err1 != nil {
  380. e.OutErr(c, e.ERR_DB_ORM, err1.Error())
  381. return
  382. }
  383. if period == nil {
  384. e.OutErr(c, e.ERR_NO_DATA, "未查询到相关学段信息")
  385. return
  386. }
  387. period.Name = v.Name
  388. _, err2 := periodDb.PeriodUpdate(period, "name")
  389. if err2 != nil {
  390. e.OutErr(c, e.ERR_DB_ORM, err2.Error())
  391. return
  392. }
  393. for _, v1 := range v.GradeList {
  394. var gradeId int
  395. if v1.Id == 0 {
  396. gradeId, err2 = gradeDb.GradeInsert(&model.Grade{
  397. Name: v1.Name,
  398. Memo: "",
  399. PeriodId: period.Id,
  400. EnterpriseId: req.Id,
  401. CreateAt: now.Format("2006-01-02 15:04:05"),
  402. UpdateAt: now.Format("2006-01-02 15:04:05"),
  403. })
  404. if err2 != nil {
  405. e.OutErr(c, e.ERR_DB_ORM, err2.Error())
  406. return
  407. }
  408. } else {
  409. grade, err3 := gradeDb.GetGrade(v1.Id)
  410. if err3 != nil {
  411. e.OutErr(c, e.ERR_DB_ORM, err3.Error())
  412. return
  413. }
  414. if grade == nil {
  415. e.OutErr(c, e.ERR_NO_DATA, "未查询到相关年级信息")
  416. return
  417. }
  418. grade.Name = v1.Name
  419. _, err4 := gradeDb.GradeUpdate(grade, "name")
  420. if err4 != nil {
  421. e.OutErr(c, e.ERR_DB_ORM, err4.Error())
  422. return
  423. }
  424. gradeId = grade.Id
  425. }
  426. for _, v2 := range v1.ClassList {
  427. if v2.Id == 0 {
  428. //新增
  429. classes = append(classes, &model.Class{
  430. Name: v2.Name,
  431. Memo: "",
  432. GradeId: gradeId,
  433. EnterpriseId: req.Id,
  434. CreateAt: now.Format("2006-01-02 15:04:05"),
  435. UpdateAt: now.Format("2006-01-02 15:04:05"),
  436. })
  437. } else {
  438. //编辑
  439. class, err4 := classDb.GetClass(v2.Id)
  440. if err4 != nil {
  441. e.OutErr(c, e.ERR_DB_ORM, err4.Error())
  442. return
  443. }
  444. if class == nil {
  445. e.OutErr(c, e.ERR_NO_DATA, "未查询到相关班级信息")
  446. return
  447. }
  448. class.Name = v2.Name
  449. _, err6 := classDb.ClassUpdate(class, "name")
  450. if err6 != nil {
  451. e.OutErr(c, e.ERR_DB_ORM, err6.Error())
  452. return
  453. }
  454. }
  455. }
  456. }
  457. }
  458. }
  459. if len(classes) > 0 {
  460. _, err2 := classDb.BatchAddClass(classes)
  461. if err2 != nil {
  462. e.OutErr(c, e.ERR_DB_ORM, err2.Error())
  463. return
  464. }
  465. }
  466. e.OutSuc(c, "success", nil)
  467. return
  468. }
  469. func SelfSupportForSchoolUpdate(c *gin.Context) {
  470. var req md.SelfSupportForSchoolUpdateReq
  471. err := c.ShouldBindJSON(&req)
  472. if err != nil {
  473. err = validate.HandleValidateErr(err)
  474. err1 := err.(e.E)
  475. e.OutErr(c, err1.Code, err1.Error())
  476. return
  477. }
  478. //1、更新 enterprise
  479. enterpriseDb := db.EnterpriseDb{}
  480. enterpriseDb.Set()
  481. enterprise, err := enterpriseDb.GetEnterprise(req.Id)
  482. if err != nil {
  483. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  484. return
  485. }
  486. if enterprise == nil {
  487. e.OutErr(c, e.ERR_NO_DATA, "未查询到对应记录")
  488. return
  489. }
  490. var pvd = 2
  491. if req.Kind == enum.EnterprisePvdByCentralKitchenForSchool || req.Kind == enum.EnterprisePvdByCentralKitchenForFactory || req.Kind == enum.EnterprisePvdByNursingHome {
  492. pvd = 1
  493. }
  494. now := time.Now()
  495. enterprise.Name = req.Name
  496. enterprise.Memo = req.Memo
  497. enterprise.Pvd = int32(pvd)
  498. enterprise.Kind = req.Kind
  499. enterprise.CompanyId = req.CompanyId
  500. enterprise.UpdateAt = now.Format("2006-01-02 15:04:05")
  501. _, err = enterpriseDb.EnterpriseUpdate(enterprise, "name", "memo", "pvd", "kind", "company_id", "update_at")
  502. if err != nil {
  503. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  504. return
  505. }
  506. //2、更新 grade && class 数据
  507. //2、删除 grade && class 数据
  508. gradeDb := db.GradeDb{}
  509. gradeDb.Set(req.Id)
  510. //_, err = gradeDb.ClassDeleteBySessionForEnterprise(db.Db.NewSession(), req.Id)
  511. //if err != nil {
  512. // e.OutErr(c, e.ERR_DB_ORM, err.Error())
  513. // return
  514. //}
  515. classDb := db.ClassDb{}
  516. classDb.Set(0)
  517. //_, err = classDb.ClassDeleteBySessionForEnterprise(db.Db.NewSession(), req.Id)
  518. //if err != nil {
  519. // e.OutErr(c, e.ERR_DB_ORM, err.Error())
  520. // return
  521. //}
  522. //新增 grade 数据 && class 数据
  523. for _, v := range req.GradeList {
  524. var classes []*model.Class
  525. if v.Id == 0 {
  526. //TODO::新增
  527. insertId, err1 := gradeDb.GradeInsert(&model.Grade{
  528. EnterpriseId: req.Id,
  529. Name: v.Name,
  530. Memo: "",
  531. CreateAt: now.Format("2006-01-02 15:04:05"),
  532. UpdateAt: now.Format("2006-01-02 15:04:05"),
  533. })
  534. if err1 != nil {
  535. e.OutErr(c, e.ERR_DB_ORM, err1.Error())
  536. return
  537. }
  538. for _, v1 := range v.ClassList {
  539. classes = append(classes, &model.Class{
  540. Name: v1.Name,
  541. Memo: "",
  542. GradeId: insertId,
  543. EnterpriseId: req.Id,
  544. CreateAt: now.Format("2006-01-02 15:04:05"),
  545. UpdateAt: now.Format("2006-01-02 15:04:05"),
  546. })
  547. }
  548. } else {
  549. //TODO::编辑
  550. grade, err3 := gradeDb.GetGrade(v.Id)
  551. if err3 != nil {
  552. e.OutErr(c, e.ERR_DB_ORM, err3.Error())
  553. return
  554. }
  555. if grade == nil {
  556. e.OutErr(c, e.ERR_NO_DATA, "未查询到相关年级信息")
  557. return
  558. }
  559. grade.Name = v.Name
  560. _, err4 := gradeDb.GradeUpdate(grade, "name")
  561. if err4 != nil {
  562. e.OutErr(c, e.ERR_DB_ORM, err4.Error())
  563. return
  564. }
  565. for _, v1 := range v.ClassList {
  566. if v1.Id == 0 {
  567. //新增
  568. classes = append(classes, &model.Class{
  569. Name: v1.Name,
  570. Memo: "",
  571. GradeId: grade.Id,
  572. EnterpriseId: req.Id,
  573. CreateAt: now.Format("2006-01-02 15:04:05"),
  574. UpdateAt: now.Format("2006-01-02 15:04:05"),
  575. })
  576. } else {
  577. //编辑
  578. class, err5 := classDb.GetClass(v1.Id)
  579. if err5 != nil {
  580. e.OutErr(c, e.ERR_DB_ORM, err5.Error())
  581. return
  582. }
  583. if class == nil {
  584. e.OutErr(c, e.ERR_NO_DATA, "未查询到相关班级信息")
  585. return
  586. }
  587. class.Name = v1.Name
  588. _, err6 := classDb.ClassUpdate(class, "name")
  589. if err6 != nil {
  590. e.OutErr(c, e.ERR_DB_ORM, err6.Error())
  591. return
  592. }
  593. }
  594. }
  595. }
  596. if len(classes) > 0 {
  597. _, err2 := classDb.BatchAddClass(classes)
  598. if err2 != nil {
  599. e.OutErr(c, e.ERR_DB_ORM, err2.Error())
  600. return
  601. }
  602. }
  603. }
  604. e.OutSuc(c, "success", nil)
  605. return
  606. }
  607. func EnterpriseAddGrade(c *gin.Context) {
  608. var req md.EnterpriseUpdateStateReq
  609. err := c.ShouldBindJSON(&req)
  610. if err != nil {
  611. err = validate.HandleValidateErr(err)
  612. err1 := err.(e.E)
  613. e.OutErr(c, err1.Code, err1.Error())
  614. return
  615. }
  616. enterpriseDb := db.EnterpriseDb{}
  617. enterpriseDb.Set()
  618. enterprise, err := enterpriseDb.GetEnterprise(req.Id)
  619. if err != nil {
  620. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  621. return
  622. }
  623. if enterprise == nil {
  624. e.OutErr(c, e.ERR_NO_DATA, "未查询到对应记录")
  625. return
  626. }
  627. now := time.Now()
  628. enterprise.State = req.State
  629. enterprise.UpdateAt = now.Format("2006-01-02 15:04:05")
  630. _, err = enterpriseDb.EnterpriseUpdate(enterprise, "state", "update_at")
  631. if err != nil {
  632. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  633. return
  634. }
  635. e.OutSuc(c, "success", nil)
  636. return
  637. }
  638. func EnterpriseUpdateState(c *gin.Context) {
  639. var req md.EnterpriseUpdateStateReq
  640. err := c.ShouldBindJSON(&req)
  641. if err != nil {
  642. err = validate.HandleValidateErr(err)
  643. err1 := err.(e.E)
  644. e.OutErr(c, err1.Code, err1.Error())
  645. return
  646. }
  647. enterpriseDb := db.EnterpriseDb{}
  648. enterpriseDb.Set()
  649. enterprise, err := enterpriseDb.GetEnterprise(req.Id)
  650. if err != nil {
  651. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  652. return
  653. }
  654. if enterprise == nil {
  655. e.OutErr(c, e.ERR_NO_DATA, "未查询到对应记录")
  656. return
  657. }
  658. now := time.Now()
  659. enterprise.State = req.State
  660. enterprise.UpdateAt = now.Format("2006-01-02 15:04:05")
  661. _, err = enterpriseDb.EnterpriseUpdate(enterprise, "state", "update_at")
  662. if err != nil {
  663. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  664. return
  665. }
  666. e.OutSuc(c, "success", nil)
  667. return
  668. }
  669. func ListCentralKitchenForSchoolPackageForSystem(c *gin.Context) {
  670. var req md.ListCentralKitchenForSchoolPackageForSystemReq
  671. err := c.ShouldBindJSON(&req)
  672. if err != nil {
  673. err = validate.HandleValidateErr(err)
  674. err1 := err.(e.E)
  675. e.OutErr(c, err1.Code, err1.Error())
  676. return
  677. }
  678. centralKitchenForSchoolPackageForSystemDb := db.CentralKitchenForSchoolPackageForSystemDb{}
  679. centralKitchenForSchoolPackageForSystemDb.Set()
  680. list, total, err := centralKitchenForSchoolPackageForSystemDb.CentralKitchenForSchoolPackageForSystemList(req)
  681. if err != nil {
  682. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  683. return
  684. }
  685. e.OutSuc(c, map[string]interface{}{
  686. "list": list,
  687. "total": total,
  688. }, nil)
  689. return
  690. }
  691. func SetCentralKitchenForSchoolWithSpecForSystem(c *gin.Context) {
  692. var req md.SetCentralKitchenForSchoolWithSpecForSystemReq
  693. err := c.ShouldBindJSON(&req)
  694. if err != nil {
  695. err = validate.HandleValidateErr(err)
  696. err1 := err.(e.E)
  697. e.OutErr(c, err1.Code, err1.Error())
  698. return
  699. }
  700. centralKitchenForSchoolWithSpecForSystemDb := db.CentralKitchenForSchoolWithSpecForSystem{}
  701. centralKitchenForSchoolWithSpecForSystemDb.Set()
  702. system, err := centralKitchenForSchoolWithSpecForSystemDb.GetCentralKitchenForSchoolWithSpecForSystem()
  703. if err != nil {
  704. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  705. return
  706. }
  707. system.BreakfastUnitPrice = req.BreakfastUnitPrice
  708. system.LunchUnitPrice = req.LunchUnitPrice
  709. system.DinnerUnitPrice = req.DinnerUnitPrice
  710. system.BreakfastUnitPriceForTeacher = req.BreakfastUnitPriceForTeacher
  711. system.LunchUnitPriceForTeacher = req.LunchUnitPriceForTeacher
  712. system.DinnerUnitPriceForTeacher = req.DinnerUnitPriceForTeacher
  713. system.UpdateAt = time.Now().Format("2006-01-02 15:04:05")
  714. updateAffected, err := centralKitchenForSchoolWithSpecForSystemDb.CentralKitchenForSchoolWithSpecForSystemUpdate(system.Id, system)
  715. if err != nil {
  716. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  717. return
  718. }
  719. if updateAffected <= 0 {
  720. e.OutErr(c, e.ERR, "更新数据失败")
  721. return
  722. }
  723. e.OutSuc(c, "success", nil)
  724. return
  725. }
  726. func GetCentralKitchenForSchoolWithSpecForSystem(c *gin.Context) {
  727. centralKitchenForSchoolWithSpecForSystemDb := db.CentralKitchenForSchoolWithSpecForSystem{}
  728. centralKitchenForSchoolWithSpecForSystemDb.Set()
  729. system, err := centralKitchenForSchoolWithSpecForSystemDb.GetCentralKitchenForSchoolWithSpecForSystem()
  730. if err != nil {
  731. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  732. return
  733. }
  734. e.OutSuc(c, map[string]interface{}{
  735. "data": system,
  736. }, nil)
  737. return
  738. }
  739. func SaveCentralKitchenForSchoolPackageForSystem(c *gin.Context) {
  740. var req md.SaveCentralKitchenForSchoolPackageForSystemReq
  741. err := c.ShouldBindJSON(&req)
  742. if err != nil {
  743. err = validate.HandleValidateErr(err)
  744. err1 := err.(e.E)
  745. e.OutErr(c, err1.Code, err1.Error())
  746. return
  747. }
  748. //判断是新增 / 编辑
  749. if req.Id > 0 {
  750. err = svc.UpdateCentralKitchenForSchoolPackageForSystem(req)
  751. if err != nil {
  752. e.OutErr(c, e.ERR, err.Error())
  753. return
  754. }
  755. } else {
  756. err = svc.AddCentralKitchenForSchoolPackageForSystem(req)
  757. if err != nil {
  758. e.OutErr(c, e.ERR, err.Error())
  759. return
  760. }
  761. }
  762. e.OutSuc(c, "success", nil)
  763. return
  764. }
  765. func SyncCentralKitchenForSchoolPackageForSystem(c *gin.Context) {
  766. var req md.SyncCentralKitchenForSchoolPackageForSystemReq
  767. err := c.ShouldBindJSON(&req)
  768. if err != nil {
  769. err = validate.HandleValidateErr(err)
  770. err1 := err.(e.E)
  771. e.OutErr(c, err1.Code, err1.Error())
  772. return
  773. }
  774. err = svc.SyncCentralKitchenForSchoolPackageForSystem(req)
  775. if err != nil {
  776. e.OutErr(c, e.ERR, err.Error())
  777. return
  778. }
  779. e.OutSuc(c, "success", nil)
  780. return
  781. }
  782. func DeleteCentralKitchenForSchoolPackageForSystem(c *gin.Context) {
  783. id := c.Param("id")
  784. err := svc.DeleteCentralKitchenForSchoolPackageForSystem(utils.StrToInt(id))
  785. if err != nil {
  786. e.OutErr(c, e.ERR, err.Error())
  787. return
  788. }
  789. e.OutSuc(c, "success", nil)
  790. return
  791. }