智慧食堂
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

584 行
17 KiB

  1. package hdl
  2. import (
  3. "applet/app/customer/lib/validate"
  4. "applet/app/customer/md"
  5. "applet/app/customer/svc"
  6. "applet/app/db"
  7. "applet/app/db/model"
  8. "applet/app/e"
  9. "applet/app/enum"
  10. "applet/app/utils"
  11. "github.com/gin-gonic/gin"
  12. "time"
  13. )
  14. func SaveCentralKitchenForSchoolUserIdentity(c *gin.Context) {
  15. var req md.SaveCentralKitchenForSchoolUserIdentityReq
  16. err := c.ShouldBindJSON(&req)
  17. if err != nil {
  18. err = validate.HandleValidateErr(err)
  19. err1 := err.(e.E)
  20. e.OutErr(c, err1.Code, err1.Error())
  21. return
  22. }
  23. user := svc.GetUser(c)
  24. var identity = enum.UserIdentityForCentralKitchenForStudent
  25. if req.IsTeacher {
  26. identity = enum.UserIdentityForCentralKitchenForTeacher
  27. }
  28. //1、判断当前身份是否已绑定
  29. userIdentityDb := db.UserIdentityDb{}
  30. userIdentityDb.Set(user.Id)
  31. isHasUserIdentity, err := userIdentityDb.UserIdentityExistV1(req.EnterpriseId, req.Name)
  32. if err != nil {
  33. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  34. return
  35. }
  36. now := time.Now()
  37. if isHasUserIdentity == nil {
  38. //2、新增身份信息
  39. userIdentity := &model.UserIdentity{
  40. Uid: user.Id,
  41. Name: req.Name,
  42. IdNo: req.IdNo,
  43. CertType: enum.UserIdentityCertTypeForIdCard,
  44. Kind: enum.UserIdentityKindForCommon,
  45. Identity: identity,
  46. EnterpriseId: req.EnterpriseId,
  47. State: enum.UserIdentityStateForNormal,
  48. Memo: "",
  49. CreateAt: now.Format("2006-01-02 15:04:05"),
  50. UpdateAt: now.Format("2006-01-02 15:04:05"),
  51. }
  52. insertAffected, err := userIdentityDb.UserIdentityInsert(userIdentity)
  53. if err != nil {
  54. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  55. return
  56. }
  57. if insertAffected <= 0 {
  58. e.OutErr(c, e.ERR_DB_ORM, "新增身份数据失败")
  59. return
  60. }
  61. //3、新增 class_with_user 记录
  62. if !req.IsTeacher {
  63. classWithUserDb := db.ClassWithUserDb{}
  64. classWithUserDb.Set()
  65. _, err = classWithUserDb.ClassWithUserInsert(&model.ClassWithUser{
  66. UserIdentityId: insertAffected,
  67. ClassId: req.ClassId,
  68. CreateAt: now.Format("2006-01-02 15:04:05"),
  69. UpdateAt: now.Format("2006-01-02 15:04:05"),
  70. })
  71. if err != nil {
  72. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  73. return
  74. }
  75. }
  76. } else {
  77. //4、修改身份信息
  78. isHasUserIdentity.Uid = user.Id
  79. isHasUserIdentity.Name = req.Name
  80. isHasUserIdentity.State = enum.UserIdentityStateForNormal
  81. _, err = userIdentityDb.UserIdentityUpdate(isHasUserIdentity.Id, isHasUserIdentity, "uid", "name", "state")
  82. if err != nil {
  83. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  84. return
  85. }
  86. //5、修改 class_with_user 记录
  87. if !req.IsTeacher {
  88. classWithUserDb := db.ClassWithUserDb{}
  89. classWithUserDb.Set()
  90. classWithUser, err1 := classWithUserDb.GetClassWithUserByUserIdentityId(isHasUserIdentity.Id)
  91. if err1 != nil {
  92. e.OutErr(c, e.ERR_DB_ORM, err1.Error())
  93. return
  94. }
  95. if classWithUser == nil {
  96. _, err2 := classWithUserDb.ClassWithUserInsert(&model.ClassWithUser{
  97. UserIdentityId: isHasUserIdentity.Id,
  98. ClassId: req.ClassId,
  99. CreateAt: now.Format("2006-01-02 15:04:05"),
  100. UpdateAt: now.Format("2006-01-02 15:04:05"),
  101. })
  102. if err2 != nil {
  103. e.OutErr(c, e.ERR_DB_ORM, err2.Error())
  104. return
  105. }
  106. } else {
  107. classWithUser.ClassId = req.ClassId
  108. _, err2 := classWithUserDb.ClassWithUserUpdateByUserIdentity(isHasUserIdentity.Id, classWithUser, "class_id")
  109. if err2 != nil {
  110. e.OutErr(c, e.ERR_DB_ORM, err2.Error())
  111. return
  112. }
  113. }
  114. }
  115. }
  116. e.OutSuc(c, "success", nil)
  117. return
  118. }
  119. func SaveSelfSupportForSchoolUserIdentity(c *gin.Context) {
  120. var req md.SaveSelfSupportForSchoolUserIdentityReq
  121. err := c.ShouldBindJSON(&req)
  122. if err != nil {
  123. err = validate.HandleValidateErr(err)
  124. err1 := err.(e.E)
  125. e.OutErr(c, err1.Code, err1.Error())
  126. return
  127. }
  128. user := svc.GetUser(c)
  129. now := time.Now()
  130. var identity = enum.UserIdentityForSelfSupportForStudent
  131. var kind = enum.UserIdentityKindForCommon
  132. if req.Kind == enum.UserIdentityKindForWorker {
  133. kind = enum.UserIdentityKindForWorker
  134. identity = enum.UserIdentityForSelfSupportForWorker
  135. req.CertType = enum.UserIdentityCertTypeForIdCard
  136. } else {
  137. if req.IsTeacher {
  138. identity = enum.UserIdentityForCentralKitchenForTeacher
  139. }
  140. }
  141. //1、判断当前身份是否已绑定
  142. userIdentityDb := db.UserIdentityDb{}
  143. userIdentityDb.Set(user.Id)
  144. isHasUserIdentity, err := userIdentityDb.UserIdentityExist(req.EnterpriseId, req.IdNo, req.CertType)
  145. if err != nil {
  146. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  147. return
  148. }
  149. if isHasUserIdentity == nil {
  150. if identity != enum.UserIdentityForSelfSupportForStudent {
  151. e.OutErr(c, e.ERR_NO_DATA, "当前身份信息不存在")
  152. return
  153. }
  154. //2、新增身份信息
  155. userIdentity := &model.UserIdentity{
  156. Uid: user.Id,
  157. Name: req.Name,
  158. IdNo: req.IdNo,
  159. CertType: req.CertType,
  160. Kind: kind,
  161. Identity: identity,
  162. EnterpriseId: req.EnterpriseId,
  163. State: enum.UserIdentityStateForNormal,
  164. Memo: "",
  165. CreateAt: now.Format("2006-01-02 15:04:05"),
  166. UpdateAt: now.Format("2006-01-02 15:04:05"),
  167. }
  168. insertAffected, err := userIdentityDb.UserIdentityInsert(userIdentity)
  169. if err != nil {
  170. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  171. return
  172. }
  173. if insertAffected <= 0 {
  174. e.OutErr(c, e.ERR_DB_ORM, "新增身份数据失败")
  175. return
  176. }
  177. //3、新增 class_with_user 记录
  178. if !req.IsTeacher {
  179. classWithUserDb := db.ClassWithUserDb{}
  180. classWithUserDb.Set()
  181. _, err1 := classWithUserDb.ClassWithUserInsert(&model.ClassWithUser{
  182. UserIdentityId: insertAffected,
  183. ClassId: req.ClassId,
  184. CreateAt: now.Format("2006-01-02 15:04:05"),
  185. UpdateAt: now.Format("2006-01-02 15:04:05"),
  186. })
  187. if err1 != nil {
  188. e.OutErr(c, e.ERR_DB_ORM, err1.Error())
  189. return
  190. }
  191. }
  192. //4、新增 self_support_for_user_face_info 记录
  193. selfSupportForSchoolInfoDb := db.SelfSupportForSchoolInfoDb{}
  194. selfSupportForSchoolInfoDb.Set(req.EnterpriseId)
  195. selfSupportForSchoolInfo, err := selfSupportForSchoolInfoDb.GetSelfSupportForSchoolInfo()
  196. if err != nil {
  197. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  198. return
  199. }
  200. if selfSupportForSchoolInfo == nil {
  201. e.OutErr(c, e.ERR_NO_DATA, "当前学校暂未完成《一脸通行入驻》")
  202. return
  203. }
  204. selfSupportForUserFaceInfoDb := db.SelfSupportForUserFaceInfoDb{}
  205. selfSupportForUserFaceInfoDb.Set(insertAffected)
  206. _, err2 := selfSupportForUserFaceInfoDb.SelfSupportForUserFaceInfoInsert(&model.SelfSupportForUserFaceInfo{
  207. EnterpriseId: req.EnterpriseId,
  208. UserIdentityId: insertAffected,
  209. CollectFaceType: 1,
  210. SchoolCode: selfSupportForSchoolInfo.SchoolCode,
  211. SchoolStdCode: selfSupportForSchoolInfo.SchoolStdCode,
  212. ParentUserId: "",
  213. ParentLogonId: "",
  214. UserId: "",
  215. SchoolFacePassStatus: "CLOSE",
  216. SchoolFacePaymentStatus: "CLOSE",
  217. ConcentrateSchoolFacePassStatus: 1,
  218. CreateAt: now.Format("2006-01-02 15:04:05"),
  219. UpdateAt: now.Format("2006-01-02 15:04:05"),
  220. })
  221. if err2 != nil {
  222. e.OutErr(c, e.ERR_DB_ORM, err2.Error())
  223. return
  224. }
  225. } else {
  226. if isHasUserIdentity.Uid != 0 && isHasUserIdentity.Uid != user.Id {
  227. e.OutErr(c, e.ERR, "当前身份信息已被绑定使用")
  228. return
  229. }
  230. //4、修改身份信息
  231. isHasUserIdentity.Uid = user.Id
  232. isHasUserIdentity.Name = req.Name
  233. isHasUserIdentity.State = enum.UserIdentityStateForNormal
  234. _, err = userIdentityDb.UserIdentityUpdate(isHasUserIdentity.Id, isHasUserIdentity, "uid", "name", "state")
  235. if err != nil {
  236. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  237. return
  238. }
  239. if identity == enum.UserIdentityForSelfSupportForStudent {
  240. //5、修改 class_with_user 记录
  241. classWithUserDb := db.ClassWithUserDb{}
  242. classWithUserDb.Set()
  243. classWithUser, err1 := classWithUserDb.GetClassWithUserByUserIdentityId(isHasUserIdentity.Id)
  244. if err1 != nil {
  245. e.OutErr(c, e.ERR_DB_ORM, err1.Error())
  246. return
  247. }
  248. if classWithUser == nil {
  249. _, err2 := classWithUserDb.ClassWithUserInsert(&model.ClassWithUser{
  250. UserIdentityId: isHasUserIdentity.Id,
  251. ClassId: req.ClassId,
  252. CreateAt: now.Format("2006-01-02 15:04:05"),
  253. UpdateAt: now.Format("2006-01-02 15:04:05"),
  254. })
  255. if err2 != nil {
  256. e.OutErr(c, e.ERR_DB_ORM, err2.Error())
  257. return
  258. }
  259. } else {
  260. classWithUser.ClassId = req.ClassId
  261. _, err2 := classWithUserDb.ClassWithUserUpdateByUserIdentity(isHasUserIdentity.Id, classWithUser, "class_id")
  262. if err2 != nil {
  263. e.OutErr(c, e.ERR_DB_ORM, err2.Error())
  264. return
  265. }
  266. }
  267. }
  268. }
  269. e.OutSuc(c, "success", nil)
  270. return
  271. }
  272. func SaveNursingHomeUserIdentity(c *gin.Context) {
  273. var req md.SaveNursingHomeUserIdentityReq
  274. err := c.ShouldBindJSON(&req)
  275. if err != nil {
  276. err = validate.HandleValidateErr(err)
  277. err1 := err.(e.E)
  278. e.OutErr(c, err1.Code, err1.Error())
  279. return
  280. }
  281. user := svc.GetUser(c)
  282. var identity = enum.UserIdentityForNursingHome
  283. //1、判断当前身份是否已绑定
  284. userIdentityDb := db.UserIdentityDb{}
  285. userIdentityDb.Set(user.Id)
  286. isHasUserIdentity, err := userIdentityDb.UserIdentityExist(req.EnterpriseId, req.IdNo, enum.UserIdentityCertTypeForIdCard)
  287. if err != nil {
  288. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  289. return
  290. }
  291. now := time.Now()
  292. if isHasUserIdentity == nil {
  293. //2、新增身份信息
  294. userIdentity := &model.UserIdentity{
  295. Uid: user.Id,
  296. Name: req.Name,
  297. IdNo: req.IdNo,
  298. Kind: enum.UserIdentityKindForCommon,
  299. Identity: identity,
  300. EnterpriseId: req.EnterpriseId,
  301. State: enum.UserIdentityStateForNormal,
  302. Memo: "",
  303. CreateAt: now.Format("2006-01-02 15:04:05"),
  304. UpdateAt: now.Format("2006-01-02 15:04:05"),
  305. }
  306. insertAffected, err := userIdentityDb.UserIdentityInsert(userIdentity)
  307. if err != nil {
  308. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  309. return
  310. }
  311. if insertAffected <= 0 {
  312. e.OutErr(c, e.ERR_DB_ORM, "新增身份数据失败")
  313. return
  314. }
  315. } else {
  316. //4、修改身份信息
  317. isHasUserIdentity.Uid = user.Id
  318. isHasUserIdentity.Name = req.Name
  319. isHasUserIdentity.State = enum.UserIdentityStateForNormal
  320. _, err = userIdentityDb.UserIdentityUpdate(isHasUserIdentity.Id, isHasUserIdentity, "uid", "name", "state")
  321. if err != nil {
  322. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  323. return
  324. }
  325. }
  326. e.OutSuc(c, "success", nil)
  327. return
  328. }
  329. func UpdateCentralKitchenForSchoolUserIdentity(c *gin.Context) {
  330. var req md.UpdateCentralKitchenForSchoolUserIdentityReq
  331. err := c.ShouldBindJSON(&req)
  332. if err != nil {
  333. err = validate.HandleValidateErr(err)
  334. err1 := err.(e.E)
  335. e.OutErr(c, err1.Code, err1.Error())
  336. return
  337. }
  338. user := svc.GetUser(c)
  339. now := time.Now()
  340. //1、查询当前身份是否存在
  341. userIdentityDb := db.UserIdentityDb{}
  342. userIdentityDb.Set(user.Id)
  343. userIdentity, err := userIdentityDb.GetUserIdentity(req.UserIdentityId)
  344. if err != nil {
  345. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  346. return
  347. }
  348. if userIdentity == nil {
  349. e.OutErr(c, e.ERR_NO_DATA, "当前身份信息不存在")
  350. return
  351. }
  352. //2、修改身份信息
  353. userIdentity.Name = req.Name
  354. userIdentity.IdNo = req.IdNo
  355. _, err = userIdentityDb.UserIdentityUpdate(userIdentity.Id, userIdentity, "id_no", "name")
  356. if err != nil {
  357. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  358. return
  359. }
  360. //3、修改 class_with_user 记录
  361. if userIdentity.Identity == enum.UserIdentityForCentralKitchenForStudent {
  362. classWithUserDb := db.ClassWithUserDb{}
  363. classWithUserDb.Set()
  364. classWithUser, err1 := classWithUserDb.GetClassWithUserByUserIdentityId(userIdentity.Id)
  365. if err1 != nil {
  366. e.OutErr(c, e.ERR_DB_ORM, err1.Error())
  367. return
  368. }
  369. if classWithUser == nil {
  370. _, err2 := classWithUserDb.ClassWithUserInsert(&model.ClassWithUser{
  371. UserIdentityId: userIdentity.Id,
  372. ClassId: req.ClassId,
  373. CreateAt: now.Format("2006-01-02 15:04:05"),
  374. UpdateAt: now.Format("2006-01-02 15:04:05"),
  375. })
  376. if err2 != nil {
  377. e.OutErr(c, e.ERR_DB_ORM, err2.Error())
  378. return
  379. }
  380. } else {
  381. classWithUser.ClassId = req.ClassId
  382. _, err2 := classWithUserDb.ClassWithUserUpdateByUserIdentity(userIdentity.Id, classWithUser, "class_id")
  383. if err2 != nil {
  384. e.OutErr(c, e.ERR_DB_ORM, err2.Error())
  385. return
  386. }
  387. }
  388. }
  389. e.OutSuc(c, "success", nil)
  390. return
  391. }
  392. func UpdateSelfSupportForSchoolUserIdentity(c *gin.Context) {
  393. var req md.UpdateSelfSupportForSchoolUserIdentityReq
  394. err := c.ShouldBindJSON(&req)
  395. if err != nil {
  396. err = validate.HandleValidateErr(err)
  397. err1 := err.(e.E)
  398. e.OutErr(c, err1.Code, err1.Error())
  399. return
  400. }
  401. user := svc.GetUser(c)
  402. now := time.Now()
  403. //1、查询当前身份是否存在
  404. userIdentityDb := db.UserIdentityDb{}
  405. userIdentityDb.Set(user.Id)
  406. userIdentity, err := userIdentityDb.GetUserIdentity(req.UserIdentityId)
  407. if err != nil {
  408. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  409. return
  410. }
  411. if userIdentity == nil {
  412. e.OutErr(c, e.ERR_NO_DATA, "当前身份信息不存在")
  413. return
  414. }
  415. //2、修改身份信息
  416. userIdentity.Name = req.Name
  417. userIdentity.IdNo = req.IdNo
  418. _, err = userIdentityDb.UserIdentityUpdate(userIdentity.Id, userIdentity, "id_no", "name")
  419. if err != nil {
  420. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  421. return
  422. }
  423. //3、修改 class_with_user 记录
  424. if userIdentity.Identity == enum.UserIdentityForSelfSupportForStudent {
  425. classWithUserDb := db.ClassWithUserDb{}
  426. classWithUserDb.Set()
  427. classWithUser, err1 := classWithUserDb.GetClassWithUserByUserIdentityId(userIdentity.Id)
  428. if err1 != nil {
  429. e.OutErr(c, e.ERR_DB_ORM, err1.Error())
  430. return
  431. }
  432. if classWithUser == nil {
  433. _, err2 := classWithUserDb.ClassWithUserInsert(&model.ClassWithUser{
  434. UserIdentityId: userIdentity.Id,
  435. ClassId: req.ClassId,
  436. CreateAt: now.Format("2006-01-02 15:04:05"),
  437. UpdateAt: now.Format("2006-01-02 15:04:05"),
  438. })
  439. if err2 != nil {
  440. e.OutErr(c, e.ERR_DB_ORM, err2.Error())
  441. return
  442. }
  443. } else {
  444. classWithUser.ClassId = req.ClassId
  445. _, err2 := classWithUserDb.ClassWithUserUpdateByUserIdentity(userIdentity.Id, classWithUser, "class_id")
  446. if err2 != nil {
  447. e.OutErr(c, e.ERR_DB_ORM, err2.Error())
  448. return
  449. }
  450. }
  451. }
  452. e.OutSuc(c, "success", nil)
  453. return
  454. }
  455. func UpdateNursingHomeUserIdentity(c *gin.Context) {
  456. var req md.UpdateNursingHomeUserIdentityReq
  457. err := c.ShouldBindJSON(&req)
  458. if err != nil {
  459. err = validate.HandleValidateErr(err)
  460. err1 := err.(e.E)
  461. e.OutErr(c, err1.Code, err1.Error())
  462. return
  463. }
  464. user := svc.GetUser(c)
  465. //1、查询当前身份是否存在
  466. userIdentityDb := db.UserIdentityDb{}
  467. userIdentityDb.Set(user.Id)
  468. userIdentity, err := userIdentityDb.GetUserIdentity(req.UserIdentityId)
  469. if err != nil {
  470. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  471. return
  472. }
  473. if userIdentity == nil {
  474. e.OutErr(c, e.ERR_NO_DATA, "当前身份信息不存在")
  475. return
  476. }
  477. //2、修改身份信息
  478. userIdentity.Name = req.Name
  479. userIdentity.IdNo = req.IdNo
  480. _, err = userIdentityDb.UserIdentityUpdate(userIdentity.Id, userIdentity, "id_no", "name")
  481. if err != nil {
  482. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  483. return
  484. }
  485. e.OutSuc(c, "success", nil)
  486. return
  487. }
  488. func DeleteUserIdentity(c *gin.Context) {
  489. userIdentityId := utils.StrToInt(c.Param("id"))
  490. user := svc.GetUser(c)
  491. //1、查询当前身份是否存在
  492. userIdentityDb := db.UserIdentityDb{}
  493. userIdentityDb.Set(user.Id)
  494. userIdentity, err := userIdentityDb.GetUserIdentity(userIdentityId)
  495. if err != nil {
  496. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  497. return
  498. }
  499. if userIdentity == nil {
  500. e.OutErr(c, e.ERR_NO_DATA, "当前身份信息不存在")
  501. return
  502. }
  503. switch userIdentity.Identity {
  504. case enum.UserIdentityForCentralKitchenForStudent:
  505. err1 := svc.DeleteUserIdentityForCentralKitchenForStudent(userIdentity.Id)
  506. if err1 != nil {
  507. e.OutErr(c, e.ERR, err1.Error())
  508. return
  509. }
  510. break
  511. case enum.UserIdentityForCentralKitchenForTeacher:
  512. err1 := svc.DeleteUserIdentityForCentralKitchenForTeacher(userIdentity.Id)
  513. if err1 != nil {
  514. e.OutErr(c, e.ERR, err1.Error())
  515. return
  516. }
  517. break
  518. case enum.UserIdentityForCentralKitchenForWorker:
  519. break
  520. case enum.UserIdentityForSelfSupportForStudent:
  521. err1 := svc.DeleteUserIdentityForSelfSupportForStudent(userIdentity.Id)
  522. if err1 != nil {
  523. e.OutErr(c, e.ERR, err1.Error())
  524. return
  525. }
  526. break
  527. case enum.UserIdentityForSelfSupportForTeacher:
  528. err1 := svc.DeleteUserIdentityForSelfSupportForTeacher(userIdentity.Id)
  529. if err1 != nil {
  530. e.OutErr(c, e.ERR, err1.Error())
  531. return
  532. }
  533. break
  534. case enum.UserIdentityForSelfSupportForWorker:
  535. err1 := svc.DeleteUserIdentityForSelfSupportForWorker(userIdentity.Id)
  536. if err1 != nil {
  537. e.OutErr(c, e.ERR, err1.Error())
  538. return
  539. }
  540. break
  541. case enum.UserIdentityForNursingHome:
  542. err1 := svc.DeleteUserIdentityForNursingHome(userIdentity.Id)
  543. if err1 != nil {
  544. e.OutErr(c, e.ERR, err1.Error())
  545. return
  546. }
  547. break
  548. }
  549. e.OutSuc(c, "success", nil)
  550. return
  551. }