garden.go 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250
  1. package v1
  2. import (
  3. "git.getensh.com/common/gopkgs/logger"
  4. "git.getensh.com/common/gopkgs/tasker/httptasker"
  5. "git.getensh.com/common/gopkgs/util"
  6. "github.com/gin-gonic/gin"
  7. "go.uber.org/zap"
  8. "net/http"
  9. "property-applete-gateway/errors"
  10. param_v1 "property-applete-gateway/param/v1"
  11. "property-applete-gateway/pb"
  12. "property-applete-gateway/pb/v1"
  13. "property-applete-gateway/utils"
  14. )
  15. //
  16. // @Summary 添加楼栋
  17. // @Description 添加楼栋
  18. // @Tags 楼盘管理
  19. // @Accept json
  20. // @Produce json
  21. // @Param token header string true "token"
  22. // @Param body body v1.BuildingAddBody true "信息"
  23. // @Success 200 {object} v1.BuildingAddResponse
  24. // @Failure 500 {object} base.HTTPError
  25. // @Router /api/v1/buildings/building [post]
  26. func (c *Controller) BuildingAdd(ctx *gin.Context) {
  27. // 解析参数
  28. req := &param_v1.BuildingAddRequest{}
  29. parseParamTask := func() error {
  30. err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.BuildingAddBody)
  31. if err != nil {
  32. logger.Error("func",
  33. zap.String("call", "util.ShouldBind"),
  34. zap.String("error", err.Error()))
  35. return errors.ParamsError
  36. }
  37. return nil
  38. }
  39. // 业务处理
  40. handleServiceTask := func() error {
  41. tokenInfo, err := utils.GetSubjectValue(ctx)
  42. if err != nil {
  43. return err
  44. }
  45. // 响应数据
  46. resp := param_v1.BuildingAddResponse{}
  47. rpcReq := &v1.BuildingAddRequest{
  48. GardenId:tokenInfo.GardenId,
  49. BuildingNumber:req.BuildingNumber,
  50. BuildingName:req.BuildingName,
  51. BuildingArea:req.BuildingArea,
  52. BuildingUsedArea:req.BuildingUsedArea,
  53. Comment:req.Comment,
  54. }
  55. rpcRsp, err := pb.Garden.BuildingAdd(ctx, rpcReq)
  56. if err != nil {
  57. s, _ := json.MarshalToString(req)
  58. logger.Error("func",
  59. zap.String("call", "pb.Garden.BuildingAdd"),
  60. zap.String("params", s),
  61. zap.String("error", err.Error()))
  62. return errors.ErrorTransForm(err)
  63. }
  64. resp.Data = *rpcRsp
  65. ctx.JSON(http.StatusOK, resp)
  66. logReq := OperationLogRequest{
  67. Module:ModuleGarden,
  68. Action:ActionGardenAddBuilding,
  69. Origin:nil,
  70. Target:req.BuildingAddBody,
  71. UserName:tokenInfo.UserName,
  72. Uid:tokenInfo.Uid,
  73. Cid:tokenInfo.Cid,
  74. GardenId:tokenInfo.GardenId,
  75. }
  76. go OperationLogAdd(&logReq)
  77. return nil
  78. }
  79. // 执行任务
  80. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  81. }
  82. //
  83. // @Summary 更改楼栋
  84. // @Description 更改楼栋
  85. // @Tags 楼盘管理
  86. // @Accept json
  87. // @Produce json
  88. // @Param token header string true "token"
  89. // @Param body body v1.BuildingUpdateBody true "信息"
  90. // @Success 200 {object} v1.BuildingUpdateResponse
  91. // @Failure 500 {object} base.HTTPError
  92. // @Router /api/v1/buildings/building [put]
  93. func (c *Controller) BuildingUpdate(ctx *gin.Context) {
  94. // 解析参数
  95. req := &param_v1.BuildingUpdateRequest{}
  96. parseParamTask := func() error {
  97. err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.BuildingUpdateBody)
  98. if err != nil {
  99. logger.Error("func",
  100. zap.String("call", "util.ShouldBind"),
  101. zap.String("error", err.Error()))
  102. return errors.ParamsError
  103. }
  104. return nil
  105. }
  106. // 业务处理
  107. handleServiceTask := func() error {
  108. tokenInfo, err := utils.GetSubjectValue(ctx)
  109. if err != nil {
  110. return err
  111. }
  112. // 响应数据
  113. resp := param_v1.BuildingUpdateResponse{}
  114. rpcReq := &v1.BuildingUpdateRequest{
  115. GardenId:tokenInfo.GardenId,
  116. BuildingNumber:req.BuildingNumber,
  117. BuildingName:req.BuildingName,
  118. BuildingArea:req.BuildingArea,
  119. BuildingUsedArea:req.BuildingUsedArea,
  120. Comment:req.Comment,
  121. Id:req.Id,
  122. }
  123. rpcRsp, err := pb.Garden.BuildingUpdate(ctx, rpcReq)
  124. if err != nil {
  125. s, _ := json.MarshalToString(req)
  126. logger.Error("func",
  127. zap.String("call", "pb.Garden.BuildingUpdate"),
  128. zap.String("params", s),
  129. zap.String("error", err.Error()))
  130. return errors.ErrorTransForm(err)
  131. }
  132. ctx.JSON(http.StatusOK, resp)
  133. logReq := OperationLogRequest{
  134. Module:ModuleGarden,
  135. Action:ActionGardenUpdateBuilding,
  136. Origin:rpcRsp.Origin,
  137. Target:req.BuildingUpdateBody,
  138. UserName:tokenInfo.UserName,
  139. Uid:tokenInfo.Uid,
  140. Cid:tokenInfo.Cid,
  141. GardenId:tokenInfo.GardenId,
  142. }
  143. go OperationLogAdd(&logReq)
  144. return nil
  145. }
  146. // 执行任务
  147. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  148. }
  149. //
  150. // @Summary 删除楼栋
  151. // @Description 删除楼栋
  152. // @Tags 楼盘管理
  153. // @Accept json
  154. // @Produce json
  155. // @Param token header string true "token"
  156. // @Param id query int true "id"
  157. // @Success 200 {object} v1.BuildingDelResponse
  158. // @Failure 500 {object} base.HTTPError
  159. // @Router /api/v1/buildings/building [delete]
  160. func (c *Controller) BuildingDel(ctx *gin.Context) {
  161. // 解析参数
  162. req := &param_v1.BuildingDelRequest{}
  163. parseParamTask := func() error {
  164. err := util.ShouldBind(ctx, &req.Header, nil, &req.BuildingDelQuery, nil)
  165. if err != nil {
  166. logger.Error("func",
  167. zap.String("call", "util.ShouldBind"),
  168. zap.String("error", err.Error()))
  169. return errors.ParamsError
  170. }
  171. return nil
  172. }
  173. // 业务处理
  174. handleServiceTask := func() error {
  175. tokenInfo, err := utils.GetSubjectValue(ctx)
  176. if err != nil {
  177. return err
  178. }
  179. // 响应数据
  180. resp := param_v1.BuildingDelResponse{}
  181. rpcReq := &v1.BuildingDelRequest{
  182. GardenId:tokenInfo.GardenId,
  183. Id:req.Id,
  184. }
  185. rpcRsp, err := pb.Garden.BuildingDel(ctx, rpcReq)
  186. if err != nil {
  187. s, _ := json.MarshalToString(req)
  188. logger.Error("func",
  189. zap.String("call", "pb.Garden.BuildingDel"),
  190. zap.String("params", s),
  191. zap.String("error", err.Error()))
  192. return errors.ErrorTransForm(err)
  193. }
  194. ctx.JSON(http.StatusOK, resp)
  195. logReq := OperationLogRequest{
  196. Module:ModuleGarden,
  197. Action:ActionGardenDelBuilding,
  198. Origin:rpcRsp.Origin,
  199. Target:nil,
  200. UserName:tokenInfo.UserName,
  201. Uid:tokenInfo.Uid,
  202. Cid:tokenInfo.Cid,
  203. GardenId:tokenInfo.GardenId,
  204. }
  205. go OperationLogAdd(&logReq)
  206. return nil
  207. }
  208. // 执行任务
  209. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  210. }
  211. //
  212. // @Summary 楼栋列表
  213. // @Description 楼栋列表
  214. // @Tags 楼盘管理
  215. // @Accept json
  216. // @Produce json
  217. // @Param token header string true "token"
  218. // @Param page query int false " "
  219. // @Param page_size query int false " "
  220. // @Param building_number query string false "楼栋编号"
  221. // @Success 200 {object} v1.BuildingListResponse
  222. // @Failure 500 {object} base.HTTPError
  223. // @Router /api/v1/buildings/building [get]
  224. func (c *Controller) BuildingList(ctx *gin.Context) {
  225. // 解析参数
  226. req := &param_v1.BuildingListRequest{}
  227. parseParamTask := func() error {
  228. err := util.ShouldBind(ctx, &req.Header, nil, &req.BuildingListQuery, nil)
  229. if err != nil {
  230. logger.Error("func",
  231. zap.String("call", "util.ShouldBind"),
  232. zap.String("error", err.Error()))
  233. return errors.ParamsError
  234. }
  235. return nil
  236. }
  237. // 业务处理
  238. handleServiceTask := func() error {
  239. tokenInfo, err := utils.GetSubjectValue(ctx)
  240. if err != nil {
  241. return err
  242. }
  243. // 响应数据
  244. resp := param_v1.BuildingListResponse{}
  245. rpcReq := &v1.BuildingListRequest{
  246. GardenId:tokenInfo.GardenId,
  247. BuildingNumber:req.BuildingNumber,
  248. Page:req.Page,
  249. PageSize:req.PageSize,
  250. }
  251. rpcRsp, err := pb.Garden.BuildingList(ctx, rpcReq)
  252. if err != nil {
  253. s, _ := json.MarshalToString(req)
  254. logger.Error("func",
  255. zap.String("call", "pb.Garden.BuildingList"),
  256. zap.String("params", s),
  257. zap.String("error", err.Error()))
  258. return errors.ErrorTransForm(err)
  259. }
  260. if rpcRsp.List == nil {
  261. rpcRsp.List = make([]*v1.BuildingItem, 0)
  262. }
  263. resp.Data = *rpcRsp
  264. ctx.JSON(http.StatusOK, resp)
  265. return nil
  266. }
  267. // 执行任务
  268. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  269. }
  270. //
  271. // @Summary 添加单元
  272. // @Description 添加单元
  273. // @Tags 楼盘管理
  274. // @Accept json
  275. // @Produce json
  276. // @Param token header string true "token"
  277. // @Param body body v1.UnitAddBody true "信息"
  278. // @Success 200 {object} v1.UnitAddResponse
  279. // @Failure 500 {object} base.HTTPError
  280. // @Router /api/v1/buildings/unit [post]
  281. func (c *Controller) UnitAdd(ctx *gin.Context) {
  282. // 解析参数
  283. req := &param_v1.UnitAddRequest{}
  284. parseParamTask := func() error {
  285. err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.UnitAddBody)
  286. if err != nil {
  287. logger.Error("func",
  288. zap.String("call", "util.ShouldBind"),
  289. zap.String("error", err.Error()))
  290. return errors.ParamsError
  291. }
  292. return nil
  293. }
  294. // 业务处理
  295. handleServiceTask := func() error {
  296. tokenInfo, err := utils.GetSubjectValue(ctx)
  297. if err != nil {
  298. return err
  299. }
  300. // 响应数据
  301. resp := param_v1.UnitAddResponse{}
  302. rpcReq := &v1.UnitAddRequest{
  303. GardenId:tokenInfo.GardenId,
  304. UnitNumber:req.UnitNumber,
  305. UnitName:req.UnitName,
  306. UnitLayers:req.UnitLayers,
  307. BuildingId:req.BuildingId,
  308. HasLift:req.HasLift,
  309. }
  310. rpcRsp, err := pb.Garden.UnitAdd(ctx, rpcReq)
  311. if err != nil {
  312. s, _ := json.MarshalToString(req)
  313. logger.Error("func",
  314. zap.String("call", "pb.Garden.UnitAdd"),
  315. zap.String("params", s),
  316. zap.String("error", err.Error()))
  317. return errors.ErrorTransForm(err)
  318. }
  319. resp.Data = *rpcRsp
  320. ctx.JSON(http.StatusOK, resp)
  321. logReq := OperationLogRequest{
  322. Module:ModuleGarden,
  323. Action:ActionGardenAddUnit,
  324. Origin:nil,
  325. Target:req.UnitAddBody,
  326. UserName:tokenInfo.UserName,
  327. Uid:tokenInfo.Uid,
  328. Cid:tokenInfo.Cid,
  329. GardenId:tokenInfo.GardenId,
  330. }
  331. go OperationLogAdd(&logReq)
  332. return nil
  333. }
  334. // 执行任务
  335. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  336. }
  337. //
  338. // @Summary 更改单元
  339. // @Description 更改单元
  340. // @Tags 楼盘管理
  341. // @Accept json
  342. // @Produce json
  343. // @Param token header string true "token"
  344. // @Param body body v1.UnitUpdateBody true "信息"
  345. // @Success 200 {object} v1.UnitUpdateResponse
  346. // @Failure 500 {object} base.HTTPError
  347. // @Router /api/v1/buildings/unit [put]
  348. func (c *Controller) UnitUpdate(ctx *gin.Context) {
  349. // 解析参数
  350. req := &param_v1.UnitUpdateRequest{}
  351. parseParamTask := func() error {
  352. err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.UnitUpdateBody)
  353. if err != nil {
  354. logger.Error("func",
  355. zap.String("call", "util.ShouldBind"),
  356. zap.String("error", err.Error()))
  357. return errors.ParamsError
  358. }
  359. return nil
  360. }
  361. // 业务处理
  362. handleServiceTask := func() error {
  363. tokenInfo, err := utils.GetSubjectValue(ctx)
  364. if err != nil {
  365. return err
  366. }
  367. // 响应数据
  368. resp := param_v1.UnitUpdateResponse{}
  369. rpcReq := &v1.UnitUpdateRequest{
  370. GardenId:tokenInfo.GardenId,
  371. UnitNumber:req.UnitNumber,
  372. UnitName:req.UnitName,
  373. UnitLayers:req.UnitLayers,
  374. BuildingId:req.BuildingId,
  375. HasLift:req.HasLift,
  376. Id:req.Id,
  377. }
  378. rpcRsp, err := pb.Garden.UnitUpdate(ctx, rpcReq)
  379. if err != nil {
  380. s, _ := json.MarshalToString(req)
  381. logger.Error("func",
  382. zap.String("call", "pb.Garden.UnitUpdate"),
  383. zap.String("params", s),
  384. zap.String("error", err.Error()))
  385. return errors.ErrorTransForm(err)
  386. }
  387. ctx.JSON(http.StatusOK, resp)
  388. logReq := OperationLogRequest{
  389. Module:ModuleGarden,
  390. Action:ActionGardenUpdateUnit,
  391. Origin:rpcRsp.Origin,
  392. Target:req.UnitUpdateBody,
  393. UserName:tokenInfo.UserName,
  394. Uid:tokenInfo.Uid,
  395. Cid:tokenInfo.Cid,
  396. GardenId:tokenInfo.GardenId,
  397. }
  398. go OperationLogAdd(&logReq)
  399. return nil
  400. }
  401. // 执行任务
  402. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  403. }
  404. //
  405. // @Summary 删除单元
  406. // @Description 删除单元
  407. // @Tags 楼盘管理
  408. // @Accept json
  409. // @Produce json
  410. // @Param token header string true "token"
  411. // @Param id query int true "id"
  412. // @Success 200 {object} v1.UnitDelResponse
  413. // @Failure 500 {object} base.HTTPError
  414. // @Router /api/v1/buildings/unit [delete]
  415. func (c *Controller) UnitDel(ctx *gin.Context) {
  416. // 解析参数
  417. req := &param_v1.UnitDelRequest{}
  418. parseParamTask := func() error {
  419. err := util.ShouldBind(ctx, &req.Header, nil, &req.UnitDelQuery, nil)
  420. if err != nil {
  421. logger.Error("func",
  422. zap.String("call", "util.ShouldBind"),
  423. zap.String("error", err.Error()))
  424. return errors.ParamsError
  425. }
  426. return nil
  427. }
  428. // 业务处理
  429. handleServiceTask := func() error {
  430. tokenInfo, err := utils.GetSubjectValue(ctx)
  431. if err != nil {
  432. return err
  433. }
  434. // 响应数据
  435. resp := param_v1.UnitDelResponse{}
  436. rpcReq := &v1.UnitDelRequest{
  437. GardenId:tokenInfo.GardenId,
  438. Id:req.Id,
  439. }
  440. rpcRsp, err := pb.Garden.UnitDel(ctx, rpcReq)
  441. if err != nil {
  442. s, _ := json.MarshalToString(req)
  443. logger.Error("func",
  444. zap.String("call", "pb.Garden.UnitDel"),
  445. zap.String("params", s),
  446. zap.String("error", err.Error()))
  447. return errors.ErrorTransForm(err)
  448. }
  449. ctx.JSON(http.StatusOK, resp)
  450. logReq := OperationLogRequest{
  451. Module:ModuleGarden,
  452. Action:ActionGardenDelUnit,
  453. Origin:rpcRsp.Origin,
  454. Target:nil,
  455. UserName:tokenInfo.UserName,
  456. Uid:tokenInfo.Uid,
  457. Cid:tokenInfo.Cid,
  458. GardenId:tokenInfo.GardenId,
  459. }
  460. go OperationLogAdd(&logReq)
  461. return nil
  462. }
  463. // 执行任务
  464. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  465. }
  466. //
  467. // @Summary 单元列表
  468. // @Description 单元列表
  469. // @Tags 楼盘管理
  470. // @Accept json
  471. // @Produce json
  472. // @Param token header string true "token"
  473. // @Param page query int false " "
  474. // @Param page_size query int false " "
  475. // @Param unit_number query int false "单元编号"
  476. // @Param building_id query int false "楼栋id"
  477. // @Success 200 {object} v1.UnitListResponse
  478. // @Failure 500 {object} base.HTTPError
  479. // @Router /api/v1/buildings/unit [get]
  480. func (c *Controller) UnitList(ctx *gin.Context) {
  481. // 解析参数
  482. req := &param_v1.UnitListRequest{}
  483. parseParamTask := func() error {
  484. err := util.ShouldBind(ctx, &req.Header, nil, &req.UnitListQuery, nil)
  485. if err != nil {
  486. logger.Error("func",
  487. zap.String("call", "util.ShouldBind"),
  488. zap.String("error", err.Error()))
  489. return errors.ParamsError
  490. }
  491. return nil
  492. }
  493. // 业务处理
  494. handleServiceTask := func() error {
  495. tokenInfo, err := utils.GetSubjectValue(ctx)
  496. if err != nil {
  497. return err
  498. }
  499. // 响应数据
  500. resp := param_v1.UnitListResponse{}
  501. rpcReq := &v1.UnitListRequest{
  502. GardenId:tokenInfo.GardenId,
  503. UnitNumber:req.UnitNumber,
  504. BuildingId:req.BuildingId,
  505. Page:req.Page,
  506. PageSize:req.PageSize,
  507. }
  508. rpcRsp, err := pb.Garden.UnitList(ctx, rpcReq)
  509. if err != nil {
  510. s, _ := json.MarshalToString(req)
  511. logger.Error("func",
  512. zap.String("call", "pb.Garden.UnitList"),
  513. zap.String("params", s),
  514. zap.String("error", err.Error()))
  515. return errors.ErrorTransForm(err)
  516. }
  517. if rpcRsp.List == nil {
  518. rpcRsp.List = make([]*v1.UnitItem, 0)
  519. }
  520. resp.Data = *rpcRsp
  521. ctx.JSON(http.StatusOK, resp)
  522. return nil
  523. }
  524. // 执行任务
  525. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  526. }
  527. //
  528. // @Summary 添加房屋
  529. // @Description 添加房屋
  530. // @Tags 楼盘管理
  531. // @Accept json
  532. // @Produce json
  533. // @Param token header string true "token"
  534. // @Param body body v1.HouseAddBody true "信息"
  535. // @Success 200 {object} v1.HouseAddResponse
  536. // @Failure 500 {object} base.HTTPError
  537. // @Router /api/v1/buildings/house [post]
  538. func (c *Controller) HouseAdd(ctx *gin.Context) {
  539. // 解析参数
  540. req := &param_v1.HouseAddRequest{}
  541. parseParamTask := func() error {
  542. err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.HouseAddBody)
  543. if err != nil {
  544. logger.Error("func",
  545. zap.String("call", "util.ShouldBind"),
  546. zap.String("error", err.Error()))
  547. return errors.ParamsError
  548. }
  549. return nil
  550. }
  551. // 业务处理
  552. handleServiceTask := func() error {
  553. tokenInfo, err := utils.GetSubjectValue(ctx)
  554. if err != nil {
  555. return err
  556. }
  557. // 响应数据
  558. resp := param_v1.HouseAddResponse{}
  559. rpcReq := &v1.HouseAddRequest{
  560. GardenId:tokenInfo.GardenId,
  561. UnitId:req.UnitId,
  562. HouseNumber:req.HouseNumber,
  563. HouseType:req.HouseType,
  564. HouseUsedArea:req.HouseUsedArea,
  565. HouseArea:req.HouseArea,
  566. Layer:req.Layer,
  567. RoomCount:req.RoomCount,
  568. HallCount:req.HallCount,
  569. }
  570. rpcRsp, err := pb.Garden.HouseAdd(ctx, rpcReq)
  571. if err != nil {
  572. s, _ := json.MarshalToString(req)
  573. logger.Error("func",
  574. zap.String("call", "pb.Garden.HouseAdd"),
  575. zap.String("params", s),
  576. zap.String("error", err.Error()))
  577. return errors.ErrorTransForm(err)
  578. }
  579. resp.Data = *rpcRsp
  580. ctx.JSON(http.StatusOK, resp)
  581. logReq := OperationLogRequest{
  582. Module:ModuleGarden,
  583. Action:ActionGardenAddHouse,
  584. Origin:nil,
  585. Target:req.HouseAddBody,
  586. UserName:tokenInfo.UserName,
  587. Uid:tokenInfo.Uid,
  588. Cid:tokenInfo.Cid,
  589. GardenId:tokenInfo.GardenId,
  590. }
  591. go OperationLogAdd(&logReq)
  592. return nil
  593. }
  594. // 执行任务
  595. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  596. }
  597. //
  598. // @Summary 更改房屋
  599. // @Description 更改房屋
  600. // @Tags 楼盘管理
  601. // @Accept json
  602. // @Produce json
  603. // @Param token header string true "token"
  604. // @Param body body v1.HouseUpdateBody true "信息"
  605. // @Success 200 {object} v1.HouseUpdateResponse
  606. // @Failure 500 {object} base.HTTPError
  607. // @Router /api/v1/buildings/house [put]
  608. func (c *Controller) HouseUpdate(ctx *gin.Context) {
  609. // 解析参数
  610. req := &param_v1.HouseUpdateRequest{}
  611. parseParamTask := func() error {
  612. err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.HouseUpdateBody)
  613. if err != nil {
  614. logger.Error("func",
  615. zap.String("call", "util.ShouldBind"),
  616. zap.String("error", err.Error()))
  617. return errors.ParamsError
  618. }
  619. return nil
  620. }
  621. // 业务处理
  622. handleServiceTask := func() error {
  623. tokenInfo, err := utils.GetSubjectValue(ctx)
  624. if err != nil {
  625. return err
  626. }
  627. // 响应数据
  628. resp := param_v1.HouseUpdateResponse{}
  629. rpcReq := &v1.HouseUpdateRequest{
  630. GardenId:tokenInfo.GardenId,
  631. UnitId:req.UnitId,
  632. HouseNumber:req.HouseNumber,
  633. HouseType:req.HouseType,
  634. HouseUsedArea:req.HouseUsedArea,
  635. HouseArea:req.HouseArea,
  636. Layer:req.Layer,
  637. RoomCount:req.RoomCount,
  638. HallCount:req.HallCount,
  639. Id:req.Id,
  640. }
  641. rpcRsp, err := pb.Garden.HouseUpdate(ctx, rpcReq)
  642. if err != nil {
  643. s, _ := json.MarshalToString(req)
  644. logger.Error("func",
  645. zap.String("call", "pb.Garden.HouseUpdate"),
  646. zap.String("params", s),
  647. zap.String("error", err.Error()))
  648. return errors.ErrorTransForm(err)
  649. }
  650. ctx.JSON(http.StatusOK, resp)
  651. logReq := OperationLogRequest{
  652. Module:ModuleGarden,
  653. Action:ActionGardenUpdateHouse,
  654. Origin:rpcRsp.Origin,
  655. Target:req.HouseUpdateBody,
  656. UserName:tokenInfo.UserName,
  657. Uid:tokenInfo.Uid,
  658. Cid:tokenInfo.Cid,
  659. GardenId:tokenInfo.GardenId,
  660. }
  661. go OperationLogAdd(&logReq)
  662. return nil
  663. }
  664. // 执行任务
  665. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  666. }
  667. //
  668. // @Summary 删除房屋
  669. // @Description 删除房屋
  670. // @Tags 楼盘管理
  671. // @Accept json
  672. // @Produce json
  673. // @Param token header string true "token"
  674. // @Param id query int true "id"
  675. // @Success 200 {object} v1.HouseDelResponse
  676. // @Failure 500 {object} base.HTTPError
  677. // @Router /api/v1/buildings/house [delete]
  678. func (c *Controller) HouseDel(ctx *gin.Context) {
  679. // 解析参数
  680. req := &param_v1.HouseDelRequest{}
  681. parseParamTask := func() error {
  682. err := util.ShouldBind(ctx, &req.Header, nil, &req.HouseDelQuery, nil)
  683. if err != nil {
  684. logger.Error("func",
  685. zap.String("call", "util.ShouldBind"),
  686. zap.String("error", err.Error()))
  687. return errors.ParamsError
  688. }
  689. return nil
  690. }
  691. // 业务处理
  692. handleServiceTask := func() error {
  693. tokenInfo, err := utils.GetSubjectValue(ctx)
  694. if err != nil {
  695. return err
  696. }
  697. // 响应数据
  698. resp := param_v1.HouseDelResponse{}
  699. rpcReq := &v1.HouseDelRequest{
  700. GardenId:tokenInfo.GardenId,
  701. Id:req.Id,
  702. }
  703. rpcRsp, err := pb.Garden.HouseDel(ctx, rpcReq)
  704. if err != nil {
  705. s, _ := json.MarshalToString(req)
  706. logger.Error("func",
  707. zap.String("call", "pb.Garden.HouseDel"),
  708. zap.String("params", s),
  709. zap.String("error", err.Error()))
  710. return errors.ErrorTransForm(err)
  711. }
  712. ctx.JSON(http.StatusOK, resp)
  713. logReq := OperationLogRequest{
  714. Module:ModuleGarden,
  715. Action:ActionGardenDelHouse,
  716. Origin:rpcRsp.Origin,
  717. Target:nil,
  718. UserName:tokenInfo.UserName,
  719. Uid:tokenInfo.Uid,
  720. Cid:tokenInfo.Cid,
  721. GardenId:tokenInfo.GardenId,
  722. }
  723. go OperationLogAdd(&logReq)
  724. return nil
  725. }
  726. // 执行任务
  727. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  728. }
  729. //
  730. // @Summary 房屋列表
  731. // @Description 房屋列表
  732. // @Tags 楼盘管理
  733. // @Accept json
  734. // @Produce json
  735. // @Param token header string true "token"
  736. // @Param page query int false " "
  737. // @Param page_size query int false " "
  738. // @Param house_number query int false "门牌号"
  739. // @Param building_id query int false "楼栋id"
  740. // @Param unit_id query int false "单元id"
  741. // @Param household_id query int false "住户uid"
  742. // @Param house_type query int false "房屋类型 1 住宅 2 商铺 3 办公"
  743. // @Param house_rent query bool false "是否用于房屋租赁 true 是 false 否"
  744. // @Success 200 {object} v1.HouseListResponse
  745. // @Failure 500 {object} base.HTTPError
  746. // @Router /api/v1/buildings/house [get]
  747. func (c *Controller) HouseList(ctx *gin.Context) {
  748. // 解析参数
  749. req := &param_v1.HouseListRequest{}
  750. parseParamTask := func() error {
  751. err := util.ShouldBind(ctx, &req.Header, nil, &req.HouseListQuery, nil)
  752. if err != nil {
  753. logger.Error("func",
  754. zap.String("call", "util.ShouldBind"),
  755. zap.String("error", err.Error()))
  756. return errors.ParamsError
  757. }
  758. return nil
  759. }
  760. // 业务处理
  761. handleServiceTask := func() error {
  762. tokenInfo, err := utils.GetSubjectValue(ctx)
  763. if err != nil {
  764. return err
  765. }
  766. // 响应数据
  767. resp := param_v1.HouseListResponse{}
  768. rpcReq := &v1.HouseListRequest{
  769. GardenId:tokenInfo.GardenId,
  770. HouseNumber:req.HouseNumber,
  771. HouseType:req.HouseType,
  772. BuildingId:req.BuildingId,
  773. UnitId:req.UnitId,
  774. Page:req.Page,
  775. PageSize:req.PageSize,
  776. Uid:req.HouseholdUid,
  777. HouseRent:req.HouseRent,
  778. }
  779. rpcRsp, err := pb.Garden.HouseList(ctx, rpcReq)
  780. if err != nil {
  781. s, _ := json.MarshalToString(req)
  782. logger.Error("func",
  783. zap.String("call", "pb.Garden.HouseList"),
  784. zap.String("params", s),
  785. zap.String("error", err.Error()))
  786. return errors.ErrorTransForm(err)
  787. }
  788. if rpcRsp.List == nil {
  789. rpcRsp.List = make([]*v1.HouseItem, 0)
  790. }
  791. resp.Data = *rpcRsp
  792. ctx.JSON(http.StatusOK, resp)
  793. return nil
  794. }
  795. // 执行任务
  796. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  797. }
  798. //
  799. // @Summary 批量添加
  800. // @Description 批量添加
  801. // @Tags 楼盘管理
  802. // @Accept json
  803. // @Produce json
  804. // @Param token header string true "token"
  805. // @Param body body v1.BatchHouseAddBody true "信息"
  806. // @Success 200 {object} v1.HouseAddResponse
  807. // @Failure 500 {object} base.HTTPError
  808. // @Router /api/v1/buildings/batch [post]
  809. func (c *Controller) BatchHouseAdd(ctx *gin.Context) {
  810. // 解析参数
  811. req := &param_v1.BatchHouseAddRequest{}
  812. parseParamTask := func() error {
  813. err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.BatchHouseAddBody)
  814. if err != nil {
  815. logger.Error("func",
  816. zap.String("call", "util.ShouldBind"),
  817. zap.String("error", err.Error()))
  818. return errors.ParamsError
  819. }
  820. return nil
  821. }
  822. // 业务处理
  823. handleServiceTask := func() error {
  824. tokenInfo, err := utils.GetSubjectValue(ctx)
  825. if err != nil {
  826. return err
  827. }
  828. // 响应数据
  829. resp := param_v1.BatchHouseAddResponse{}
  830. rpcReq := &v1.BatchHouseAddRequest{
  831. GardenId:tokenInfo.GardenId,
  832. }
  833. rpcReq.Buildings = make([]*v1.BatchBuildingItem, len(req.Buildings))
  834. for i, _ := range req.Buildings {
  835. rpcReq.Buildings[i] = &req.Buildings[i]
  836. }
  837. rpcReq.Units = make([]*v1.BatchUnitItem, len(req.Units))
  838. for i, _ := range req.Units {
  839. rpcReq.Units[i] = &req.Units[i]
  840. }
  841. rpcReq.Houses = make([]*v1.BatchHouseItem, len(req.Houses))
  842. for i, _ := range req.Houses {
  843. rpcReq.Houses[i] = &req.Houses[i]
  844. }
  845. _, err = pb.Garden.BatchHouseAdd(ctx, rpcReq)
  846. if err != nil {
  847. s, _ := json.MarshalToString(req)
  848. logger.Error("func",
  849. zap.String("call", "pb.Garden.BatchHouseAdd"),
  850. zap.String("params", s),
  851. zap.String("error", err.Error()))
  852. return errors.ErrorTransForm(err)
  853. }
  854. ctx.JSON(http.StatusOK, resp)
  855. return nil
  856. }
  857. // 执行任务
  858. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  859. }
  860. //
  861. // @Summary 小区信息
  862. // @Description 小区信息
  863. // @Tags 小区
  864. // @Accept json
  865. // @Produce json
  866. // @Param token header string true " "
  867. // @Success 200 {object} v1.GardenInfoResponse
  868. // @Failure 500 {object} base.HTTPError
  869. // @Router /api/v1/garden [get]
  870. func (c *Controller) GardenInfo(ctx *gin.Context) {
  871. // 解析参数
  872. req := &param_v1.GardenInfoRequest{}
  873. parseParamTask := func() error {
  874. err := util.ShouldBind(ctx, &req.Header, nil, nil, nil)
  875. if err != nil {
  876. logger.Error("func",
  877. zap.String("call", "util.ShouldBind"),
  878. zap.String("error", err.Error()))
  879. return errors.ParamsError
  880. }
  881. return nil
  882. }
  883. // 业务处理
  884. handleServiceTask := func() error {
  885. tokenInfo, err := utils.GetSubjectValue(ctx)
  886. if err != nil {
  887. return err
  888. }
  889. // 响应数据
  890. resp := param_v1.GardenInfoResponse{}
  891. rpcReq := &v1.GardenInfosRequest{
  892. Ids:[]int64{tokenInfo.GardenId},
  893. }
  894. rpcRsp, err := pb.System.GardenInfos(ctx, rpcReq)
  895. if err != nil {
  896. s, _ := json.MarshalToString(req)
  897. logger.Error("func",
  898. zap.String("call", "Garden.GardenInfos"),
  899. zap.String("params", s),
  900. zap.String("error", err.Error()))
  901. return errors.ErrorTransForm(err)
  902. }
  903. if rpcRsp.List == nil {
  904. return errors.ErrRecordNotFound
  905. }
  906. resp.Data = *rpcRsp.List[0]
  907. ctx.JSON(http.StatusOK, resp)
  908. return nil
  909. }
  910. // 执行任务
  911. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  912. }
  913. //
  914. // @Summary 修改小区普通信息
  915. // @Description 修改小区普通信息
  916. // @Tags 小区
  917. // @Accept json
  918. // @Produce json
  919. // @Param token header string true " "
  920. // @Param body body v1.GardenUpdateBody true "小区信息"
  921. // @Success 200 {object} v1.GardenUpdateResponse
  922. // @Failure 500 {object} base.HTTPError
  923. // @Router /api/v1/garden [put]
  924. func (c *Controller) GardenUpdate(ctx *gin.Context) {
  925. // 解析参数
  926. req := &param_v1.GardenUpdateRequest{}
  927. parseParamTask := func() error {
  928. err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.GardenUpdateBody)
  929. if err != nil {
  930. logger.Error("func",
  931. zap.String("call", "util.ShouldBind"),
  932. zap.String("error", err.Error()))
  933. return errors.ParamsError
  934. }
  935. return nil
  936. }
  937. // 业务处理
  938. handleServiceTask := func() error {
  939. tokenInfo, err := utils.GetSubjectValue(ctx)
  940. if err != nil {
  941. return err
  942. }
  943. // 响应数据
  944. resp := param_v1.GardenUpdateResponse{}
  945. rpcReq := &v1.GardenUpdateRequest{
  946. //Province: req.Province,
  947. //ProvinceCode: req.ProvinceCode,
  948. //City: req.City,
  949. //CityCode: req.CityCode,
  950. //Area: req.Area,
  951. //AreaCode: req.AreaCode,
  952. //Street: req.Street,
  953. //StreetCode: req.StreetCode,
  954. //Committee: req.Committee,
  955. //CommitteeCode: req.CommitteeCode,
  956. PropertyPerson: req.PropertyPerson,
  957. PropertyPhone: req.PropertyPhone,
  958. //GardenName: req.GardenName,
  959. GardenAddr: req.GardenAddr,
  960. Cid: tokenInfo.Cid,
  961. Id:tokenInfo.GardenId,
  962. GardenPic:req.GardenPic,
  963. GardenDesc:req.GardenDesc,
  964. Lnt:req.Lnt,
  965. Lat:req.Lat,
  966. }
  967. _, err = pb.System.GardenUpdate(ctx, rpcReq)
  968. if err != nil {
  969. s, _ := json.MarshalToString(req)
  970. logger.Error("func",
  971. zap.String("call", "pb.Garden.GardenUpdate"),
  972. zap.String("params", s),
  973. zap.String("error", err.Error()))
  974. return errors.ErrorTransForm(err)
  975. }
  976. ctx.JSON(http.StatusOK, resp)
  977. return nil
  978. }
  979. // 执行任务
  980. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  981. }
  982. //
  983. // @Summary 申请修改小区关键信息
  984. // @Description 申请修改小区关键信息
  985. // @Tags 小区
  986. // @Accept json
  987. // @Produce json
  988. // @Param token header string true " "
  989. // @Param body body v1.GardenKeyInfoChangeBody true "小区信息"
  990. // @Success 200 {object} v1.GardenKeyInfoChangeResponse
  991. // @Failure 500 {object} base.HTTPError
  992. // @Router /api/v1/garden/key_info [put]
  993. func (c *Controller) GardenKeyInfoChange(ctx *gin.Context) {
  994. // 解析参数
  995. req := &param_v1.GardenKeyInfoChangeRequest{}
  996. parseParamTask := func() error {
  997. err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.GardenKeyInfoChangeBody)
  998. if err != nil {
  999. logger.Error("func",
  1000. zap.String("call", "util.ShouldBind"),
  1001. zap.String("error", err.Error()))
  1002. return errors.ParamsError
  1003. }
  1004. return nil
  1005. }
  1006. // 业务处理
  1007. handleServiceTask := func() error {
  1008. tokenInfo, err := utils.GetSubjectValue(ctx)
  1009. if err != nil {
  1010. return err
  1011. }
  1012. // 响应数据
  1013. resp := param_v1.GardenKeyInfoChangeResponse{}
  1014. rpcReq := &v1.GardenKeyInfoChangeRequest{
  1015. Province: req.Province,
  1016. ProvinceCode: req.ProvinceCode,
  1017. City: req.City,
  1018. CityCode: req.CityCode,
  1019. Area: req.Area,
  1020. AreaCode: req.AreaCode,
  1021. Street: req.Street,
  1022. StreetCode: req.StreetCode,
  1023. Committee: req.Committee,
  1024. CommitteeCode: req.CommitteeCode,
  1025. Cid: tokenInfo.Cid,
  1026. Id:tokenInfo.GardenId,
  1027. GardenName:req.GardenName,
  1028. }
  1029. _, err = pb.System.GardenKeyInfoChange(ctx, rpcReq)
  1030. if err != nil {
  1031. s, _ := json.MarshalToString(req)
  1032. logger.Error("func",
  1033. zap.String("call", "pb.Garden.GardenKeyInfoChange"),
  1034. zap.String("params", s),
  1035. zap.String("error", err.Error()))
  1036. return errors.ErrorTransForm(err)
  1037. }
  1038. ctx.JSON(http.StatusOK, resp)
  1039. return nil
  1040. }
  1041. // 执行任务
  1042. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  1043. }
  1044. //
  1045. // @Summary 小区关键信息申请列表
  1046. // @Description 小区关键信息申请列表
  1047. // @Tags 小区
  1048. // @Accept json
  1049. // @Produce json
  1050. // @Param token header string true " "
  1051. // @Param page query int false " "
  1052. // @Param page_size query int false " "
  1053. // @Param status query int false "0不过率 1 待审核 2 审核通过 3 未通过 "
  1054. // @Success 200 {object} v1.GardenKeyInfoChangeListResponse
  1055. // @Failure 500 {object} base.HTTPError
  1056. // @Router /api/v1/garden/key_info [get]
  1057. func (c *Controller) GardenKeyInfoChangeList(ctx *gin.Context) {
  1058. // 解析参数
  1059. req := &param_v1.GardenKeyInfoChangeListRequest{}
  1060. parseParamTask := func() error {
  1061. err := util.ShouldBind(ctx, &req.Header, nil, &req.GardenKeyInfoChangeListQuery, nil)
  1062. if err != nil {
  1063. logger.Error("func",
  1064. zap.String("call", "util.ShouldBind"),
  1065. zap.String("error", err.Error()))
  1066. return errors.ParamsError
  1067. }
  1068. return nil
  1069. }
  1070. // 业务处理
  1071. handleServiceTask := func() error {
  1072. tokenInfo, err := utils.GetSubjectValue(ctx)
  1073. if err != nil {
  1074. return err
  1075. }
  1076. // 响应数据
  1077. resp := param_v1.GardenKeyInfoChangeListResponse{}
  1078. rpcReq := &v1.GardenKeyInfoChangeListRequest{
  1079. Cid: tokenInfo.Cid,
  1080. GardenId:tokenInfo.GardenId,
  1081. Status:req.Status,
  1082. Page:req.Page,
  1083. PageSize:req.PageSize,
  1084. }
  1085. rpcRsp, err := pb.System.GardenKeyInfoChangeList(ctx, rpcReq)
  1086. if err != nil {
  1087. s, _ := json.MarshalToString(req)
  1088. logger.Error("func",
  1089. zap.String("call", "pb.Garden.GardenKeyInfoChangeList"),
  1090. zap.String("params", s),
  1091. zap.String("error", err.Error()))
  1092. return errors.ErrorTransForm(err)
  1093. }
  1094. if rpcRsp.List == nil {
  1095. rpcRsp.List = make([]*v1.GardenKeyInfoData, 0)
  1096. }
  1097. resp.Data = *rpcRsp
  1098. ctx.JSON(http.StatusOK, resp)
  1099. return nil
  1100. }
  1101. // 执行任务
  1102. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  1103. }