智慧食堂
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

hdl_enterprise.go 22 KiB

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