pasture.go 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410
  1. package pasture
  2. import (
  3. "kpt-pasture/http/middleware"
  4. "net/http"
  5. "strconv"
  6. "gitee.com/xuyiping_admin/pkg/xerr"
  7. pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
  8. operationPb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/operation"
  9. "gitee.com/xuyiping_admin/pkg/apierr"
  10. "gitee.com/xuyiping_admin/pkg/ginutil"
  11. "gitee.com/xuyiping_admin/pkg/valid"
  12. "github.com/gin-gonic/gin"
  13. )
  14. func SearchDiseaseList(c *gin.Context) {
  15. var req pasturePb.SearchDiseaseRequest
  16. if err := ginutil.BindProto(c, &req); err != nil {
  17. apierr.AbortBadRequest(c, http.StatusBadRequest, err)
  18. return
  19. }
  20. pagination := &pasturePb.PaginationModel{
  21. Page: int32(c.GetInt(middleware.Page)),
  22. PageSize: int32(c.GetInt(middleware.PageSize)),
  23. PageOffset: int32(c.GetInt(middleware.PageOffset)),
  24. }
  25. res, err := middleware.Dependency(c).StoreEventHub.OpsService.SearchDiseaseList(c, &req, pagination)
  26. if err != nil {
  27. apierr.ClassifiedAbort(c, err)
  28. return
  29. }
  30. ginutil.JSONResp(c, res)
  31. }
  32. func CreatedOrUpdateDisease(c *gin.Context) {
  33. var req pasturePb.SearchDiseaseList
  34. if err := ginutil.BindProto(c, &req); err != nil {
  35. apierr.AbortBadRequest(c, http.StatusBadRequest, err)
  36. return
  37. }
  38. if err := valid.ValidateStruct(&req,
  39. valid.Field(&req.Name, valid.Required),
  40. valid.Field(&req.DiseaseTypeId, valid.Required),
  41. ); err != nil {
  42. apierr.AbortBadRequest(c, http.StatusBadRequest, err)
  43. return
  44. }
  45. if err := middleware.BackendOperation(c).OpsService.CreateOrUpdateDisease(c, &req); err != nil {
  46. apierr.ClassifiedAbort(c, err)
  47. return
  48. }
  49. ginutil.JSONResp(c, &operationPb.CommonOK{
  50. Code: http.StatusOK,
  51. Msg: "ok",
  52. Data: &operationPb.Success{Success: true},
  53. })
  54. }
  55. func SearchDiseaseTypeList(c *gin.Context) {
  56. var req pasturePb.SearchNameRequest
  57. if err := ginutil.BindProto(c, &req); err != nil {
  58. apierr.AbortBadRequest(c, http.StatusBadRequest, err)
  59. return
  60. }
  61. pagination := &pasturePb.PaginationModel{
  62. Page: int32(c.GetInt(middleware.Page)),
  63. PageSize: int32(c.GetInt(middleware.PageSize)),
  64. PageOffset: int32(c.GetInt(middleware.PageOffset)),
  65. }
  66. res, err := middleware.Dependency(c).StoreEventHub.OpsService.SearchDiseaseTypeList(c, &req, pagination)
  67. if err != nil {
  68. apierr.ClassifiedAbort(c, err)
  69. return
  70. }
  71. ginutil.JSONResp(c, res)
  72. }
  73. func CreatedOrUpdateDiseaseType(c *gin.Context) {
  74. var req pasturePb.SearchBaseConfigList
  75. if err := ginutil.BindProto(c, &req); err != nil {
  76. apierr.AbortBadRequest(c, http.StatusBadRequest, err)
  77. return
  78. }
  79. if err := valid.ValidateStruct(&req,
  80. valid.Field(&req.Name, valid.Required),
  81. ); err != nil {
  82. apierr.AbortBadRequest(c, http.StatusBadRequest, err)
  83. return
  84. }
  85. if err := middleware.BackendOperation(c).OpsService.CreateOrUpdateDiseaseType(c, &req); err != nil {
  86. apierr.ClassifiedAbort(c, err)
  87. return
  88. }
  89. ginutil.JSONResp(c, &operationPb.CommonOK{
  90. Code: http.StatusOK,
  91. Msg: "ok",
  92. Data: &operationPb.Success{Success: true},
  93. })
  94. }
  95. func SearchPrescriptionList(c *gin.Context) {
  96. var req pasturePb.SearchPrescriptionRequest
  97. if err := ginutil.BindProto(c, &req); err != nil {
  98. apierr.AbortBadRequest(c, http.StatusBadRequest, err)
  99. return
  100. }
  101. pagination := &pasturePb.PaginationModel{
  102. Page: int32(c.GetInt(middleware.Page)),
  103. PageSize: int32(c.GetInt(middleware.PageSize)),
  104. PageOffset: int32(c.GetInt(middleware.PageOffset)),
  105. }
  106. res, err := middleware.Dependency(c).StoreEventHub.OpsService.SearchPrescriptionList(c, &req, pagination)
  107. if err != nil {
  108. apierr.ClassifiedAbort(c, err)
  109. return
  110. }
  111. ginutil.JSONResp(c, res)
  112. }
  113. func CreatedOrUpdatePrescription(c *gin.Context) {
  114. var req pasturePb.PrescriptionRequest
  115. if err := ginutil.BindProto(c, &req); err != nil {
  116. apierr.AbortBadRequest(c, http.StatusBadRequest, err)
  117. return
  118. }
  119. if err := valid.ValidateStruct(&req,
  120. valid.Field(&req.Name, valid.Required),
  121. valid.Field(&req.DrugsList, valid.Required),
  122. ); err != nil {
  123. apierr.AbortBadRequest(c, http.StatusBadRequest, err)
  124. return
  125. }
  126. if err := middleware.BackendOperation(c).OpsService.CreateOrUpdatePrescription(c, &req); err != nil {
  127. apierr.ClassifiedAbort(c, err)
  128. return
  129. }
  130. ginutil.JSONResp(c, &operationPb.CommonOK{
  131. Code: http.StatusOK,
  132. Msg: "ok",
  133. Data: &operationPb.Success{Success: true},
  134. })
  135. }
  136. func PrescriptionDetail(c *gin.Context) {
  137. idStr := c.Param("id")
  138. id, _ := strconv.ParseInt(idStr, 10, 64)
  139. if err := valid.Validate(id, valid.Required); err != nil {
  140. apierr.AbortBadRequest(c, http.StatusBadRequest, err)
  141. return
  142. }
  143. res, err := middleware.BackendOperation(c).OpsService.PrescriptionDetail(c, id)
  144. if err != nil {
  145. apierr.ClassifiedAbort(c, err)
  146. return
  147. }
  148. ginutil.JSONResp(c, res)
  149. }
  150. func SearchImmunizationList(c *gin.Context) {
  151. var req pasturePb.ImmunizationRequest
  152. if err := ginutil.BindProto(c, &req); err != nil {
  153. apierr.AbortBadRequest(c, http.StatusBadRequest, err)
  154. return
  155. }
  156. pagination := &pasturePb.PaginationModel{
  157. Page: int32(c.GetInt(middleware.Page)),
  158. PageSize: int32(c.GetInt(middleware.PageSize)),
  159. PageOffset: int32(c.GetInt(middleware.PageOffset)),
  160. }
  161. res, err := middleware.Dependency(c).StoreEventHub.OpsService.ImmunizationSetList(c, &req, pagination)
  162. if err != nil {
  163. apierr.ClassifiedAbort(c, err)
  164. return
  165. }
  166. ginutil.JSONResp(c, res)
  167. }
  168. func CreatedOrUpdateImmunization(c *gin.Context) {
  169. var req pasturePb.ImmunizationRequest
  170. if err := ginutil.BindProto(c, &req); err != nil {
  171. apierr.AbortBadRequest(c, http.StatusBadRequest, err)
  172. return
  173. }
  174. if err := valid.ValidateStruct(&req,
  175. valid.Field(&req.Name, valid.Required),
  176. valid.Field(&req.Conditions, valid.Required),
  177. valid.Field(&req.Value, valid.Required),
  178. ); err != nil {
  179. apierr.AbortBadRequest(c, http.StatusBadRequest, err)
  180. return
  181. }
  182. if err := middleware.BackendOperation(c).OpsService.CreatedOrUpdateImmunization(c, &req); err != nil {
  183. apierr.ClassifiedAbort(c, err)
  184. return
  185. }
  186. ginutil.JSONResp(c, &operationPb.CommonOK{
  187. Code: http.StatusOK,
  188. Msg: "ok",
  189. Data: &operationPb.Success{Success: true},
  190. })
  191. }
  192. func ImmunizationIsShow(c *gin.Context) {
  193. immunizationIdStr := c.Param("id")
  194. immunizationId, _ := strconv.Atoi(immunizationIdStr)
  195. if err := valid.Validate(immunizationId, valid.Required, valid.Min(1)); err != nil {
  196. apierr.ClassifiedAbort(c, err)
  197. return
  198. }
  199. if err := middleware.Dependency(c).StoreEventHub.OpsService.ImmunizationIsShow(c, int64(immunizationId)); err != nil {
  200. apierr.ClassifiedAbort(c, err)
  201. return
  202. }
  203. ginutil.JSONResp(c, &operationPb.CommonOK{
  204. Code: http.StatusOK,
  205. Msg: "ok",
  206. Data: &operationPb.Success{Success: true},
  207. })
  208. }
  209. // SameTimeCreatedOrUpdate 同期策略添加或者更新
  210. func SameTimeCreatedOrUpdate(c *gin.Context) {
  211. var req pasturePb.SearchSameTimeList
  212. if err := ginutil.BindProto(c, &req); err != nil {
  213. apierr.AbortBadRequest(c, http.StatusBadRequest, err)
  214. return
  215. }
  216. if err := valid.ValidateStruct(&req,
  217. valid.Field(&req.Name, valid.Required),
  218. valid.Field(&req.CowType, valid.Required),
  219. valid.Field(&req.WeekType, valid.Required),
  220. valid.Field(&req.PostpartumDaysStart, valid.Required),
  221. valid.Field(&req.PostpartumDaysEnd, valid.Required),
  222. valid.Field(&req.CollateNodes, valid.Required),
  223. ); err != nil {
  224. apierr.AbortBadRequest(c, http.StatusBadRequest, err)
  225. return
  226. }
  227. if req.PostpartumDaysStart > req.PostpartumDaysEnd {
  228. apierr.AbortBadRequest(c, http.StatusBadRequest, xerr.New("开始天数不能大于结束天数"))
  229. return
  230. }
  231. if len(req.CollateNodes) < 0 {
  232. apierr.AbortBadRequest(c, http.StatusBadRequest, xerr.New("错误的同期策略数据"))
  233. return
  234. }
  235. if err := middleware.BackendOperation(c).OpsService.CreateOrUpdateSameTime(c, &req); err != nil {
  236. apierr.ClassifiedAbort(c, err)
  237. return
  238. }
  239. ginutil.JSONResp(c, &operationPb.CommonOK{
  240. Code: http.StatusOK,
  241. Msg: "ok",
  242. Data: &operationPb.Success{Success: true},
  243. })
  244. }
  245. // SameTimeList 同步策略列表
  246. func SameTimeList(c *gin.Context) {
  247. var req pasturePb.SearchNameRequest
  248. if err := ginutil.BindProto(c, &req); err != nil {
  249. apierr.AbortBadRequest(c, http.StatusBadRequest, err)
  250. return
  251. }
  252. pagination := &pasturePb.PaginationModel{
  253. Page: int32(c.GetInt(middleware.Page)),
  254. PageSize: int32(c.GetInt(middleware.PageSize)),
  255. PageOffset: int32(c.GetInt(middleware.PageOffset)),
  256. }
  257. res, err := middleware.BackendOperation(c).OpsService.SearchSameTimeList(c, &req, pagination)
  258. if err != nil {
  259. apierr.ClassifiedAbort(c, err)
  260. return
  261. }
  262. ginutil.JSONResp(c, res)
  263. }
  264. func SameTimeIsShow(c *gin.Context) {
  265. sameTimeIdStr := c.Param("id")
  266. sameTimeId, _ := strconv.Atoi(sameTimeIdStr)
  267. if err := valid.Validate(sameTimeId, valid.Required, valid.Min(1)); err != nil {
  268. apierr.ClassifiedAbort(c, err)
  269. return
  270. }
  271. if err := middleware.BackendOperation(c).OpsService.SameTimeIsShow(c, int64(sameTimeId)); err != nil {
  272. apierr.ClassifiedAbort(c, err)
  273. return
  274. }
  275. ginutil.JSONResp(c, &operationPb.CommonOK{
  276. Code: http.StatusOK,
  277. Msg: "ok",
  278. Data: &operationPb.Success{Success: true},
  279. })
  280. }
  281. func SystemBasicList(c *gin.Context) {
  282. res, err := middleware.BackendOperation(c).OpsService.SystemBasicList(c)
  283. if err != nil {
  284. apierr.ClassifiedAbort(c, err)
  285. return
  286. }
  287. ginutil.JSONResp(c, res)
  288. }
  289. func SystemBasicEdit(c *gin.Context) {
  290. var req pasturePb.BaseDataConfigBatch
  291. if err := ginutil.BindProto(c, &req); err != nil {
  292. apierr.AbortBadRequest(c, http.StatusBadRequest, err)
  293. return
  294. }
  295. if err := valid.ValidateStruct(&req,
  296. valid.Field(&req.Item, valid.Required, valid.Each(valid.By(func(value interface{}) error {
  297. s := value.(pasturePb.BaseDataConfig)
  298. return valid.ValidateStruct(&s,
  299. valid.Field(&s.Id, valid.Required),
  300. valid.Field(&s.Name, valid.Required),
  301. )
  302. }))),
  303. ); err != nil {
  304. apierr.AbortBadRequest(c, http.StatusBadRequest, err)
  305. return
  306. }
  307. err := middleware.BackendOperation(c).OpsService.SystemBasicEdit(c, &req)
  308. if err != nil {
  309. apierr.ClassifiedAbort(c, err)
  310. return
  311. }
  312. ginutil.JSONResp(c, &operationPb.CommonOK{
  313. Code: http.StatusOK,
  314. Msg: "ok",
  315. Data: &operationPb.Success{Success: true},
  316. })
  317. }
  318. func SaleDealerCreateOrUpdate(c *gin.Context) {
  319. var req pasturePb.DealerItem
  320. if err := ginutil.BindProto(c, &req); err != nil {
  321. apierr.AbortBadRequest(c, http.StatusBadRequest, err)
  322. return
  323. }
  324. if err := valid.ValidateStruct(&req,
  325. valid.Field(&req.Name, valid.Required),
  326. valid.Field(&req.Phone, valid.Required),
  327. valid.Field(&req.Contacts, valid.Required),
  328. ); err != nil {
  329. apierr.ClassifiedAbort(c, err)
  330. return
  331. }
  332. if err := middleware.BackendOperation(c).OpsService.CreateOrUpdateDealer(c, &req); err != nil {
  333. apierr.ClassifiedAbort(c, err)
  334. return
  335. }
  336. ginutil.JSONResp(c, &operationPb.CommonOK{
  337. Code: http.StatusOK,
  338. Msg: "ok",
  339. Data: &operationPb.Success{Success: true},
  340. })
  341. }
  342. func SaleDealerList(c *gin.Context) {
  343. var req pasturePb.SearchNameRequest
  344. if err := ginutil.BindProto(c, &req); err != nil {
  345. apierr.AbortBadRequest(c, http.StatusBadRequest, err)
  346. return
  347. }
  348. res, err := middleware.BackendOperation(c).OpsService.SearchDealerList(c, &req)
  349. if err != nil {
  350. apierr.ClassifiedAbort(c, err)
  351. return
  352. }
  353. ginutil.JSONResp(c, res)
  354. }