garden.go 56 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139
  1. package v1
  2. import (
  3. "fmt"
  4. "git.getensh.com/common/gopkgs/logger"
  5. "git.getensh.com/common/gopkgs/tasker/httptasker"
  6. "git.getensh.com/common/gopkgs/util"
  7. "github.com/gin-gonic/gin"
  8. "github.com/tealeg/xlsx"
  9. "go.uber.org/zap"
  10. "google.golang.org/grpc/status"
  11. "net/http"
  12. "os"
  13. "path"
  14. "property-system-gateway/errors"
  15. param_v1 "property-system-gateway/param/v1"
  16. "property-system-gateway/parser"
  17. "property-system-gateway/pb"
  18. "property-system-gateway/pb/v1"
  19. "property-system-gateway/utils"
  20. "strconv"
  21. "strings"
  22. "time"
  23. )
  24. //
  25. // @Summary 添加楼栋管家
  26. // @Description 添加楼栋管家
  27. // @Tags 楼栋管理
  28. // @Accept json
  29. // @Produce json
  30. // @Param token header string true "token"
  31. // @Param body body v1.BuildingAddManagerBody true " "
  32. // @Success 200 {object} v1.BuildingAddManagerResponse
  33. // @Failure 500 {object} base.HTTPError
  34. // @Router /api/v1/buildings/manager [post]
  35. func (c *Controller) BuildingAddManager(ctx *gin.Context) {
  36. // 解析参数
  37. req := &param_v1.BuildingAddManagerRequest{}
  38. parseParamTask := func() error {
  39. err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.BuildingAddManagerBody)
  40. if err != nil {
  41. logger.Error("func",
  42. zap.String("call", "util.ShouldBind"),
  43. zap.String("error", err.Error()))
  44. return errors.ParamsError
  45. }
  46. return nil
  47. }
  48. // 业务处理
  49. handleServiceTask := func() error {
  50. tokenInfo, err := utils.GetSubjectValue(ctx)
  51. if err != nil {
  52. return err
  53. }
  54. // 响应数据
  55. resp := param_v1.BuildingAddManagerResponse{}
  56. rpcReq := &v1.BuildingAddManagerRequest{
  57. GardenId: tokenInfo.GardenId,
  58. BuildingId: req.BuildingId,
  59. ManagerUid: req.ManagerUid,
  60. }
  61. _, err = pb.Garden.BuildingAddManager(ctx, rpcReq)
  62. if err != nil {
  63. s, _ := json.MarshalToString(req)
  64. logger.Error("func",
  65. zap.String("call", "pb.Garden.BuildingAddManager"),
  66. zap.String("params", s),
  67. zap.String("error", err.Error()))
  68. return errors.ErrorTransForm(err)
  69. }
  70. ctx.JSON(http.StatusOK, resp)
  71. return nil
  72. }
  73. // 执行任务
  74. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  75. }
  76. //
  77. // @Summary 删除楼栋管家
  78. // @Description 删除楼栋管家
  79. // @Tags 楼栋管理
  80. // @Accept json
  81. // @Produce json
  82. // @Param token header string true "token"
  83. // @Param id query int true "经纪人与楼栋的关系id"
  84. // @Success 200 {object} v1.BuildingDelManagerResponse
  85. // @Failure 500 {object} base.HTTPError
  86. // @Router /api/v1/buildings/manager [delete]
  87. func (c *Controller) BuildingDelManager(ctx *gin.Context) {
  88. // 解析参数
  89. req := &param_v1.BuildingDelManagerRequest{}
  90. parseParamTask := func() error {
  91. err := util.ShouldBind(ctx, &req.Header, nil, &req.BuildingDelManagerQuery, nil)
  92. if err != nil {
  93. logger.Error("func",
  94. zap.String("call", "util.ShouldBind"),
  95. zap.String("error", err.Error()))
  96. return errors.ParamsError
  97. }
  98. return nil
  99. }
  100. // 业务处理
  101. handleServiceTask := func() error {
  102. tokenInfo, err := utils.GetSubjectValue(ctx)
  103. if err != nil {
  104. return err
  105. }
  106. // 响应数据
  107. resp := param_v1.BuildingDelManagerResponse{}
  108. rpcReq := &v1.BuildingDelManagerRequest{
  109. GardenId: tokenInfo.GardenId,
  110. Id: req.Id,
  111. }
  112. _, err = pb.Garden.BuildingDelManager(ctx, rpcReq)
  113. if err != nil {
  114. s, _ := json.MarshalToString(req)
  115. logger.Error("func",
  116. zap.String("call", "pb.Garden.BuildingDelManager"),
  117. zap.String("params", s),
  118. zap.String("error", err.Error()))
  119. return errors.ErrorTransForm(err)
  120. }
  121. ctx.JSON(http.StatusOK, resp)
  122. return nil
  123. }
  124. // 执行任务
  125. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  126. }
  127. //
  128. // @Summary 楼栋管家列表
  129. // @Description 楼栋管家列表
  130. // @Tags 楼栋管理
  131. // @Accept json
  132. // @Produce json
  133. // @Param token header string true "token"
  134. // @Param building_id query int true "楼栋id"
  135. // @Success 200 {object} v1.BuildingManagerListResponse
  136. // @Failure 500 {object} base.HTTPError
  137. // @Router /api/v1/buildings/manager [get]
  138. func (c *Controller) BuildingManagerList(ctx *gin.Context) {
  139. // 解析参数
  140. req := &param_v1.BuildingManagerListRequest{}
  141. parseParamTask := func() error {
  142. err := util.ShouldBind(ctx, &req.Header, nil, &req.BuildingManagerListQuery, nil)
  143. if err != nil {
  144. logger.Error("func",
  145. zap.String("call", "util.ShouldBind"),
  146. zap.String("error", err.Error()))
  147. return errors.ParamsError
  148. }
  149. return nil
  150. }
  151. // 业务处理
  152. handleServiceTask := func() error {
  153. tokenInfo, err := utils.GetSubjectValue(ctx)
  154. if err != nil {
  155. return err
  156. }
  157. // 响应数据
  158. resp := param_v1.BuildingManagerListResponse{}
  159. rpcReq := &v1.BuildingManagerListRequest{
  160. GardenId: tokenInfo.GardenId,
  161. BuildingId: req.BuildingId,
  162. }
  163. rpcRsp, err := pb.Garden.BuildingManagerList(ctx, rpcReq)
  164. if err != nil {
  165. s, _ := json.MarshalToString(req)
  166. logger.Error("func",
  167. zap.String("call", "pb.Garden.BuildingManagerList"),
  168. zap.String("params", s),
  169. zap.String("error", err.Error()))
  170. return errors.ErrorTransForm(err)
  171. }
  172. if rpcRsp.List == nil {
  173. rpcRsp.List = make([]*v1.BuildingManagerItem, 0)
  174. }
  175. resp.Data = *rpcRsp
  176. ctx.JSON(http.StatusOK, resp)
  177. return nil
  178. }
  179. // 执行任务
  180. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  181. }
  182. //
  183. // @Summary 添加楼栋
  184. // @Description 添加楼栋
  185. // @Tags 楼盘管理
  186. // @Accept json
  187. // @Produce json
  188. // @Param token header string true "token"
  189. // @Param body body v1.BuildingAddBody true "信息"
  190. // @Success 200 {object} v1.BuildingAddResponse
  191. // @Failure 500 {object} base.HTTPError
  192. // @Router /api/v1/buildings/building [post]
  193. func (c *Controller) BuildingAdd(ctx *gin.Context) {
  194. // 解析参数
  195. req := &param_v1.BuildingAddRequest{}
  196. parseParamTask := func() error {
  197. err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.BuildingAddBody)
  198. if err != nil {
  199. logger.Error("func",
  200. zap.String("call", "util.ShouldBind"),
  201. zap.String("error", err.Error()))
  202. return errors.ParamsError
  203. }
  204. return nil
  205. }
  206. // 业务处理
  207. handleServiceTask := func() error {
  208. tokenInfo, err := utils.GetSubjectValue(ctx)
  209. if err != nil {
  210. return err
  211. }
  212. // 响应数据
  213. resp := param_v1.BuildingAddResponse{}
  214. rpcReq := &v1.BuildingAddRequest{
  215. GardenId: tokenInfo.GardenId,
  216. BuildingNumber: req.BuildingNumber,
  217. BuildingName: req.BuildingName,
  218. BuildingArea: req.BuildingArea,
  219. BuildingUsedArea: req.BuildingUsedArea,
  220. Comment: req.Comment,
  221. }
  222. rpcRsp, err := pb.Garden.BuildingAdd(ctx, rpcReq)
  223. if err != nil {
  224. s, _ := json.MarshalToString(req)
  225. logger.Error("func",
  226. zap.String("call", "pb.Garden.BuildingAdd"),
  227. zap.String("params", s),
  228. zap.String("error", err.Error()))
  229. return errors.ErrorTransForm(err)
  230. }
  231. resp.Data = *rpcRsp
  232. ctx.JSON(http.StatusOK, resp)
  233. logReq := OperationLogRequest{
  234. Module: ModuleGarden,
  235. Action: ActionGardenAddBuilding,
  236. Origin: nil,
  237. Target: req.BuildingAddBody,
  238. UserName: tokenInfo.UserName,
  239. Uid: tokenInfo.Uid,
  240. Cid: tokenInfo.Cid,
  241. GardenId: tokenInfo.GardenId,
  242. }
  243. go OperationLogAdd(&logReq)
  244. return nil
  245. }
  246. // 执行任务
  247. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  248. }
  249. //
  250. // @Summary 更改楼栋
  251. // @Description 更改楼栋
  252. // @Tags 楼盘管理
  253. // @Accept json
  254. // @Produce json
  255. // @Param token header string true "token"
  256. // @Param body body v1.BuildingUpdateBody true "信息"
  257. // @Success 200 {object} v1.BuildingUpdateResponse
  258. // @Failure 500 {object} base.HTTPError
  259. // @Router /api/v1/buildings/building [put]
  260. func (c *Controller) BuildingUpdate(ctx *gin.Context) {
  261. // 解析参数
  262. req := &param_v1.BuildingUpdateRequest{}
  263. parseParamTask := func() error {
  264. err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.BuildingUpdateBody)
  265. if err != nil {
  266. logger.Error("func",
  267. zap.String("call", "util.ShouldBind"),
  268. zap.String("error", err.Error()))
  269. return errors.ParamsError
  270. }
  271. return nil
  272. }
  273. // 业务处理
  274. handleServiceTask := func() error {
  275. tokenInfo, err := utils.GetSubjectValue(ctx)
  276. if err != nil {
  277. return err
  278. }
  279. // 响应数据
  280. resp := param_v1.BuildingUpdateResponse{}
  281. rpcReq := &v1.BuildingUpdateRequest{
  282. GardenId: tokenInfo.GardenId,
  283. BuildingNumber: req.BuildingNumber,
  284. BuildingName: req.BuildingName,
  285. BuildingArea: req.BuildingArea,
  286. BuildingUsedArea: req.BuildingUsedArea,
  287. Comment: req.Comment,
  288. Id: req.Id,
  289. }
  290. rpcRsp, err := pb.Garden.BuildingUpdate(ctx, rpcReq)
  291. if err != nil {
  292. s, _ := json.MarshalToString(req)
  293. logger.Error("func",
  294. zap.String("call", "pb.Garden.BuildingUpdate"),
  295. zap.String("params", s),
  296. zap.String("error", err.Error()))
  297. return errors.ErrorTransForm(err)
  298. }
  299. ctx.JSON(http.StatusOK, resp)
  300. logReq := OperationLogRequest{
  301. Module: ModuleGarden,
  302. Action: ActionGardenUpdateBuilding,
  303. Origin: rpcRsp.Origin,
  304. Target: req.BuildingUpdateBody,
  305. UserName: tokenInfo.UserName,
  306. Uid: tokenInfo.Uid,
  307. Cid: tokenInfo.Cid,
  308. GardenId: tokenInfo.GardenId,
  309. }
  310. go OperationLogAdd(&logReq)
  311. return nil
  312. }
  313. // 执行任务
  314. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  315. }
  316. //
  317. // @Summary 删除楼栋
  318. // @Description 删除楼栋
  319. // @Tags 楼盘管理
  320. // @Accept json
  321. // @Produce json
  322. // @Param token header string true "token"
  323. // @Param id query int true "id"
  324. // @Success 200 {object} v1.BuildingDelResponse
  325. // @Failure 500 {object} base.HTTPError
  326. // @Router /api/v1/buildings/building [delete]
  327. func (c *Controller) BuildingDel(ctx *gin.Context) {
  328. // 解析参数
  329. req := &param_v1.BuildingDelRequest{}
  330. parseParamTask := func() error {
  331. err := util.ShouldBind(ctx, &req.Header, nil, &req.BuildingDelQuery, nil)
  332. if err != nil {
  333. logger.Error("func",
  334. zap.String("call", "util.ShouldBind"),
  335. zap.String("error", err.Error()))
  336. return errors.ParamsError
  337. }
  338. return nil
  339. }
  340. // 业务处理
  341. handleServiceTask := func() error {
  342. tokenInfo, err := utils.GetSubjectValue(ctx)
  343. if err != nil {
  344. return err
  345. }
  346. // 响应数据
  347. resp := param_v1.BuildingDelResponse{}
  348. rpcReq := &v1.BuildingDelRequest{
  349. GardenId: tokenInfo.GardenId,
  350. Id: req.Id,
  351. }
  352. rpcRsp, err := pb.Garden.BuildingDel(ctx, rpcReq)
  353. if err != nil {
  354. s, _ := json.MarshalToString(req)
  355. logger.Error("func",
  356. zap.String("call", "pb.Garden.BuildingDel"),
  357. zap.String("params", s),
  358. zap.String("error", err.Error()))
  359. return errors.ErrorTransForm(err)
  360. }
  361. ctx.JSON(http.StatusOK, resp)
  362. logReq := OperationLogRequest{
  363. Module: ModuleGarden,
  364. Action: ActionGardenDelBuilding,
  365. Origin: rpcRsp.Origin,
  366. Target: nil,
  367. UserName: tokenInfo.UserName,
  368. Uid: tokenInfo.Uid,
  369. Cid: tokenInfo.Cid,
  370. GardenId: tokenInfo.GardenId,
  371. }
  372. go OperationLogAdd(&logReq)
  373. return nil
  374. }
  375. // 执行任务
  376. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  377. }
  378. //
  379. // @Summary 楼栋列表
  380. // @Description 楼栋列表
  381. // @Tags 楼盘管理
  382. // @Accept json
  383. // @Produce json
  384. // @Param token header string true "token"
  385. // @Param page query int false " "
  386. // @Param page_size query int false " "
  387. // @Param building_number query string false "楼栋编号"
  388. // @Success 200 {object} v1.BuildingListResponse
  389. // @Failure 500 {object} base.HTTPError
  390. // @Router /api/v1/buildings/building [get]
  391. func (c *Controller) BuildingList(ctx *gin.Context) {
  392. // 解析参数
  393. req := &param_v1.BuildingListRequest{}
  394. parseParamTask := func() error {
  395. err := util.ShouldBind(ctx, &req.Header, nil, &req.BuildingListQuery, nil)
  396. if err != nil {
  397. logger.Error("func",
  398. zap.String("call", "util.ShouldBind"),
  399. zap.String("error", err.Error()))
  400. return errors.ParamsError
  401. }
  402. return nil
  403. }
  404. // 业务处理
  405. handleServiceTask := func() error {
  406. tokenInfo, err := utils.GetSubjectValue(ctx)
  407. if err != nil {
  408. return err
  409. }
  410. // 响应数据
  411. resp := param_v1.BuildingListResponse{}
  412. rpcReq := &v1.BuildingListRequest{
  413. GardenId: tokenInfo.GardenId,
  414. BuildingNumber: req.BuildingNumber,
  415. Page: req.Page,
  416. PageSize: req.PageSize,
  417. }
  418. rpcRsp, err := pb.Garden.BuildingList(ctx, rpcReq)
  419. if err != nil {
  420. s, _ := json.MarshalToString(req)
  421. logger.Error("func",
  422. zap.String("call", "pb.Garden.BuildingList"),
  423. zap.String("params", s),
  424. zap.String("error", err.Error()))
  425. return errors.ErrorTransForm(err)
  426. }
  427. if rpcRsp.List == nil {
  428. rpcRsp.List = make([]*v1.BuildingItem, 0)
  429. }
  430. resp.Data = *rpcRsp
  431. ctx.JSON(http.StatusOK, resp)
  432. return nil
  433. }
  434. // 执行任务
  435. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  436. }
  437. //
  438. // @Summary 添加单元
  439. // @Description 添加单元
  440. // @Tags 楼盘管理
  441. // @Accept json
  442. // @Produce json
  443. // @Param token header string true "token"
  444. // @Param body body v1.UnitAddBody true "信息"
  445. // @Success 200 {object} v1.UnitAddResponse
  446. // @Failure 500 {object} base.HTTPError
  447. // @Router /api/v1/buildings/unit [post]
  448. func (c *Controller) UnitAdd(ctx *gin.Context) {
  449. // 解析参数
  450. req := &param_v1.UnitAddRequest{}
  451. parseParamTask := func() error {
  452. err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.UnitAddBody)
  453. if err != nil {
  454. logger.Error("func",
  455. zap.String("call", "util.ShouldBind"),
  456. zap.String("error", err.Error()))
  457. return errors.ParamsError
  458. }
  459. return nil
  460. }
  461. // 业务处理
  462. handleServiceTask := func() error {
  463. tokenInfo, err := utils.GetSubjectValue(ctx)
  464. if err != nil {
  465. return err
  466. }
  467. // 响应数据
  468. resp := param_v1.UnitAddResponse{}
  469. rpcReq := &v1.UnitAddRequest{
  470. GardenId: tokenInfo.GardenId,
  471. UnitNumber: req.UnitNumber,
  472. UnitName: req.UnitName,
  473. UnitLayers: req.UnitLayers,
  474. BuildingId: req.BuildingId,
  475. HasLift: req.HasLift,
  476. }
  477. rpcRsp, err := pb.Garden.UnitAdd(ctx, rpcReq)
  478. if err != nil {
  479. s, _ := json.MarshalToString(req)
  480. logger.Error("func",
  481. zap.String("call", "pb.Garden.UnitAdd"),
  482. zap.String("params", s),
  483. zap.String("error", err.Error()))
  484. return errors.ErrorTransForm(err)
  485. }
  486. resp.Data = *rpcRsp
  487. ctx.JSON(http.StatusOK, resp)
  488. logReq := OperationLogRequest{
  489. Module: ModuleGarden,
  490. Action: ActionGardenAddUnit,
  491. Origin: nil,
  492. Target: req.UnitAddBody,
  493. UserName: tokenInfo.UserName,
  494. Uid: tokenInfo.Uid,
  495. Cid: tokenInfo.Cid,
  496. GardenId: tokenInfo.GardenId,
  497. }
  498. go OperationLogAdd(&logReq)
  499. return nil
  500. }
  501. // 执行任务
  502. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  503. }
  504. //
  505. // @Summary 更改单元
  506. // @Description 更改单元
  507. // @Tags 楼盘管理
  508. // @Accept json
  509. // @Produce json
  510. // @Param token header string true "token"
  511. // @Param body body v1.UnitUpdateBody true "信息"
  512. // @Success 200 {object} v1.UnitUpdateResponse
  513. // @Failure 500 {object} base.HTTPError
  514. // @Router /api/v1/buildings/unit [put]
  515. func (c *Controller) UnitUpdate(ctx *gin.Context) {
  516. // 解析参数
  517. req := &param_v1.UnitUpdateRequest{}
  518. parseParamTask := func() error {
  519. err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.UnitUpdateBody)
  520. if err != nil {
  521. logger.Error("func",
  522. zap.String("call", "util.ShouldBind"),
  523. zap.String("error", err.Error()))
  524. return errors.ParamsError
  525. }
  526. return nil
  527. }
  528. // 业务处理
  529. handleServiceTask := func() error {
  530. tokenInfo, err := utils.GetSubjectValue(ctx)
  531. if err != nil {
  532. return err
  533. }
  534. // 响应数据
  535. resp := param_v1.UnitUpdateResponse{}
  536. rpcReq := &v1.UnitUpdateRequest{
  537. GardenId: tokenInfo.GardenId,
  538. UnitNumber: req.UnitNumber,
  539. UnitName: req.UnitName,
  540. UnitLayers: req.UnitLayers,
  541. BuildingId: req.BuildingId,
  542. HasLift: req.HasLift,
  543. Id: req.Id,
  544. }
  545. rpcRsp, err := pb.Garden.UnitUpdate(ctx, rpcReq)
  546. if err != nil {
  547. s, _ := json.MarshalToString(req)
  548. logger.Error("func",
  549. zap.String("call", "pb.Garden.UnitUpdate"),
  550. zap.String("params", s),
  551. zap.String("error", err.Error()))
  552. return errors.ErrorTransForm(err)
  553. }
  554. ctx.JSON(http.StatusOK, resp)
  555. logReq := OperationLogRequest{
  556. Module: ModuleGarden,
  557. Action: ActionGardenUpdateUnit,
  558. Origin: rpcRsp.Origin,
  559. Target: req.UnitUpdateBody,
  560. UserName: tokenInfo.UserName,
  561. Uid: tokenInfo.Uid,
  562. Cid: tokenInfo.Cid,
  563. GardenId: tokenInfo.GardenId,
  564. }
  565. go OperationLogAdd(&logReq)
  566. return nil
  567. }
  568. // 执行任务
  569. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  570. }
  571. //
  572. // @Summary 删除单元
  573. // @Description 删除单元
  574. // @Tags 楼盘管理
  575. // @Accept json
  576. // @Produce json
  577. // @Param token header string true "token"
  578. // @Param id query int true "id"
  579. // @Success 200 {object} v1.UnitDelResponse
  580. // @Failure 500 {object} base.HTTPError
  581. // @Router /api/v1/buildings/unit [delete]
  582. func (c *Controller) UnitDel(ctx *gin.Context) {
  583. // 解析参数
  584. req := &param_v1.UnitDelRequest{}
  585. parseParamTask := func() error {
  586. err := util.ShouldBind(ctx, &req.Header, nil, &req.UnitDelQuery, nil)
  587. if err != nil {
  588. logger.Error("func",
  589. zap.String("call", "util.ShouldBind"),
  590. zap.String("error", err.Error()))
  591. return errors.ParamsError
  592. }
  593. return nil
  594. }
  595. // 业务处理
  596. handleServiceTask := func() error {
  597. tokenInfo, err := utils.GetSubjectValue(ctx)
  598. if err != nil {
  599. return err
  600. }
  601. // 响应数据
  602. resp := param_v1.UnitDelResponse{}
  603. rpcReq := &v1.UnitDelRequest{
  604. GardenId: tokenInfo.GardenId,
  605. Id: req.Id,
  606. }
  607. rpcRsp, err := pb.Garden.UnitDel(ctx, rpcReq)
  608. if err != nil {
  609. s, _ := json.MarshalToString(req)
  610. logger.Error("func",
  611. zap.String("call", "pb.Garden.UnitDel"),
  612. zap.String("params", s),
  613. zap.String("error", err.Error()))
  614. return errors.ErrorTransForm(err)
  615. }
  616. ctx.JSON(http.StatusOK, resp)
  617. logReq := OperationLogRequest{
  618. Module: ModuleGarden,
  619. Action: ActionGardenDelUnit,
  620. Origin: rpcRsp.Origin,
  621. Target: nil,
  622. UserName: tokenInfo.UserName,
  623. Uid: tokenInfo.Uid,
  624. Cid: tokenInfo.Cid,
  625. GardenId: tokenInfo.GardenId,
  626. }
  627. go OperationLogAdd(&logReq)
  628. return nil
  629. }
  630. // 执行任务
  631. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  632. }
  633. //
  634. // @Summary 单元列表
  635. // @Description 单元列表
  636. // @Tags 楼盘管理
  637. // @Accept json
  638. // @Produce json
  639. // @Param token header string true "token"
  640. // @Param page query int false " "
  641. // @Param page_size query int false " "
  642. // @Param unit_number query int false "单元编号"
  643. // @Param building_id query int false "楼栋id"
  644. // @Success 200 {object} v1.UnitListResponse
  645. // @Failure 500 {object} base.HTTPError
  646. // @Router /api/v1/buildings/unit [get]
  647. func (c *Controller) UnitList(ctx *gin.Context) {
  648. // 解析参数
  649. req := &param_v1.UnitListRequest{}
  650. parseParamTask := func() error {
  651. err := util.ShouldBind(ctx, &req.Header, nil, &req.UnitListQuery, nil)
  652. if err != nil {
  653. logger.Error("func",
  654. zap.String("call", "util.ShouldBind"),
  655. zap.String("error", err.Error()))
  656. return errors.ParamsError
  657. }
  658. return nil
  659. }
  660. // 业务处理
  661. handleServiceTask := func() error {
  662. tokenInfo, err := utils.GetSubjectValue(ctx)
  663. if err != nil {
  664. return err
  665. }
  666. // 响应数据
  667. resp := param_v1.UnitListResponse{}
  668. rpcReq := &v1.UnitListRequest{
  669. GardenId: tokenInfo.GardenId,
  670. UnitNumber: req.UnitNumber,
  671. BuildingId: req.BuildingId,
  672. Page: req.Page,
  673. PageSize: req.PageSize,
  674. }
  675. rpcRsp, err := pb.Garden.UnitList(ctx, rpcReq)
  676. if err != nil {
  677. s, _ := json.MarshalToString(req)
  678. logger.Error("func",
  679. zap.String("call", "pb.Garden.UnitList"),
  680. zap.String("params", s),
  681. zap.String("error", err.Error()))
  682. return errors.ErrorTransForm(err)
  683. }
  684. if rpcRsp.List == nil {
  685. rpcRsp.List = make([]*v1.UnitItem, 0)
  686. }
  687. resp.Data = *rpcRsp
  688. ctx.JSON(http.StatusOK, resp)
  689. return nil
  690. }
  691. // 执行任务
  692. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  693. }
  694. //
  695. // @Summary 添加房屋
  696. // @Description 添加房屋
  697. // @Tags 楼盘管理
  698. // @Accept json
  699. // @Produce json
  700. // @Param token header string true "token"
  701. // @Param body body v1.HouseAddBody true "信息"
  702. // @Success 200 {object} v1.HouseAddResponse
  703. // @Failure 500 {object} base.HTTPError
  704. // @Router /api/v1/buildings/house [post]
  705. func (c *Controller) HouseAdd(ctx *gin.Context) {
  706. // 解析参数
  707. req := &param_v1.HouseAddRequest{}
  708. parseParamTask := func() error {
  709. err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.HouseAddBody)
  710. if err != nil {
  711. logger.Error("func",
  712. zap.String("call", "util.ShouldBind"),
  713. zap.String("error", err.Error()))
  714. return errors.ParamsError
  715. }
  716. return nil
  717. }
  718. // 业务处理
  719. handleServiceTask := func() error {
  720. tokenInfo, err := utils.GetSubjectValue(ctx)
  721. if err != nil {
  722. return err
  723. }
  724. // 响应数据
  725. resp := param_v1.HouseAddResponse{}
  726. rpcReq := &v1.HouseAddRequest{
  727. GardenId: tokenInfo.GardenId,
  728. UnitId: req.UnitId,
  729. HouseNumber: req.HouseNumber,
  730. HouseType: req.HouseType,
  731. HouseUsedArea: req.HouseUsedArea,
  732. HouseArea: req.HouseArea,
  733. Layer: req.Layer,
  734. RoomCount: req.RoomCount,
  735. HallCount: req.HallCount,
  736. BuildingId: req.BuildingId,
  737. }
  738. rpcRsp, err := pb.Garden.HouseAdd(ctx, rpcReq)
  739. if err != nil {
  740. s, _ := json.MarshalToString(req)
  741. logger.Error("func",
  742. zap.String("call", "pb.Garden.HouseAdd"),
  743. zap.String("params", s),
  744. zap.String("error", err.Error()))
  745. return errors.ErrorTransForm(err)
  746. }
  747. resp.Data = *rpcRsp
  748. ctx.JSON(http.StatusOK, resp)
  749. logReq := OperationLogRequest{
  750. Module: ModuleGarden,
  751. Action: ActionGardenAddHouse,
  752. Origin: nil,
  753. Target: req.HouseAddBody,
  754. UserName: tokenInfo.UserName,
  755. Uid: tokenInfo.Uid,
  756. Cid: tokenInfo.Cid,
  757. GardenId: tokenInfo.GardenId,
  758. }
  759. go OperationLogAdd(&logReq)
  760. return nil
  761. }
  762. // 执行任务
  763. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  764. }
  765. //
  766. // @Summary 更改房屋
  767. // @Description 更改房屋
  768. // @Tags 楼盘管理
  769. // @Accept json
  770. // @Produce json
  771. // @Param token header string true "token"
  772. // @Param body body v1.HouseUpdateBody true "信息"
  773. // @Success 200 {object} v1.HouseUpdateResponse
  774. // @Failure 500 {object} base.HTTPError
  775. // @Router /api/v1/buildings/house [put]
  776. func (c *Controller) HouseUpdate(ctx *gin.Context) {
  777. // 解析参数
  778. req := &param_v1.HouseUpdateRequest{}
  779. parseParamTask := func() error {
  780. err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.HouseUpdateBody)
  781. if err != nil {
  782. logger.Error("func",
  783. zap.String("call", "util.ShouldBind"),
  784. zap.String("error", err.Error()))
  785. return errors.ParamsError
  786. }
  787. return nil
  788. }
  789. // 业务处理
  790. handleServiceTask := func() error {
  791. tokenInfo, err := utils.GetSubjectValue(ctx)
  792. if err != nil {
  793. return err
  794. }
  795. // 响应数据
  796. resp := param_v1.HouseUpdateResponse{}
  797. rpcReq := &v1.HouseUpdateRequest{
  798. GardenId: tokenInfo.GardenId,
  799. UnitId: req.UnitId,
  800. HouseNumber: req.HouseNumber,
  801. HouseType: req.HouseType,
  802. HouseUsedArea: req.HouseUsedArea,
  803. HouseArea: req.HouseArea,
  804. Layer: req.Layer,
  805. RoomCount: req.RoomCount,
  806. HallCount: req.HallCount,
  807. Id: req.Id,
  808. }
  809. rpcRsp, err := pb.Garden.HouseUpdate(ctx, rpcReq)
  810. if err != nil {
  811. s, _ := json.MarshalToString(req)
  812. logger.Error("func",
  813. zap.String("call", "pb.Garden.HouseUpdate"),
  814. zap.String("params", s),
  815. zap.String("error", err.Error()))
  816. return errors.ErrorTransForm(err)
  817. }
  818. ctx.JSON(http.StatusOK, resp)
  819. logReq := OperationLogRequest{
  820. Module: ModuleGarden,
  821. Action: ActionGardenUpdateHouse,
  822. Origin: rpcRsp.Origin,
  823. Target: req.HouseUpdateBody,
  824. UserName: tokenInfo.UserName,
  825. Uid: tokenInfo.Uid,
  826. Cid: tokenInfo.Cid,
  827. GardenId: tokenInfo.GardenId,
  828. }
  829. go OperationLogAdd(&logReq)
  830. return nil
  831. }
  832. // 执行任务
  833. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  834. }
  835. //
  836. // @Summary 删除房屋
  837. // @Description 删除房屋
  838. // @Tags 楼盘管理
  839. // @Accept json
  840. // @Produce json
  841. // @Param token header string true "token"
  842. // @Param id query int true "id"
  843. // @Success 200 {object} v1.HouseDelResponse
  844. // @Failure 500 {object} base.HTTPError
  845. // @Router /api/v1/buildings/house [delete]
  846. func (c *Controller) HouseDel(ctx *gin.Context) {
  847. // 解析参数
  848. req := &param_v1.HouseDelRequest{}
  849. parseParamTask := func() error {
  850. err := util.ShouldBind(ctx, &req.Header, nil, &req.HouseDelQuery, nil)
  851. if err != nil {
  852. logger.Error("func",
  853. zap.String("call", "util.ShouldBind"),
  854. zap.String("error", err.Error()))
  855. return errors.ParamsError
  856. }
  857. return nil
  858. }
  859. // 业务处理
  860. handleServiceTask := func() error {
  861. tokenInfo, err := utils.GetSubjectValue(ctx)
  862. if err != nil {
  863. return err
  864. }
  865. // 响应数据
  866. resp := param_v1.HouseDelResponse{}
  867. rpcReq := &v1.HouseDelRequest{
  868. GardenId: tokenInfo.GardenId,
  869. Id: req.Id,
  870. }
  871. rpcRsp, err := pb.Garden.HouseDel(ctx, rpcReq)
  872. if err != nil {
  873. s, _ := json.MarshalToString(req)
  874. logger.Error("func",
  875. zap.String("call", "pb.Garden.HouseDel"),
  876. zap.String("params", s),
  877. zap.String("error", err.Error()))
  878. return errors.ErrorTransForm(err)
  879. }
  880. ctx.JSON(http.StatusOK, resp)
  881. logReq := OperationLogRequest{
  882. Module: ModuleGarden,
  883. Action: ActionGardenDelHouse,
  884. Origin: rpcRsp.Origin,
  885. Target: nil,
  886. UserName: tokenInfo.UserName,
  887. Uid: tokenInfo.Uid,
  888. Cid: tokenInfo.Cid,
  889. GardenId: tokenInfo.GardenId,
  890. }
  891. go OperationLogAdd(&logReq)
  892. return nil
  893. }
  894. // 执行任务
  895. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  896. }
  897. func handleHouseName(ctx *gin.Context, houseName string, tokenInfo utils.TokenInfo) (int64, int64, string, bool, error) {
  898. array := strings.Split(houseName, "-")
  899. if len(array) != 3 && len(array) != 1 {
  900. return 0, 0, "", false, status.Error(10003, "总房号格式错误")
  901. }
  902. // 纯房号
  903. if len(array) == 1 {
  904. return 0, 0, array[0], false, nil
  905. }
  906. // 先找楼栋
  907. rpcReq := &v1.BuildingListRequest{
  908. GardenId: tokenInfo.GardenId,
  909. BuildingNumber: array[0],
  910. Page: -1,
  911. PageSize: -1,
  912. }
  913. rpcRsp, err := pb.Garden.BuildingList(ctx, rpcReq)
  914. if err != nil {
  915. s, _ := json.MarshalToString(rpcReq)
  916. logger.Error("func",
  917. zap.String("call", "pb.Garden.BuildingList"),
  918. zap.String("params", s),
  919. zap.String("error", err.Error()))
  920. return 0, 0, "", false, errors.ErrorTransForm(err)
  921. }
  922. if len(rpcRsp.List) == 0 {
  923. return 0, 0, "", true, nil
  924. }
  925. // 再找单元
  926. buildingId := rpcRsp.List[0].Id
  927. unitNumber, _ := strconv.Atoi(array[1])
  928. mReq := &v1.UnitListRequest{
  929. GardenId: tokenInfo.GardenId,
  930. BuildingId: buildingId,
  931. UnitNumber: int64(unitNumber),
  932. Page: -1,
  933. PageSize: -1,
  934. }
  935. mRsp, err := pb.Garden.UnitList(ctx, mReq)
  936. if err != nil {
  937. s, _ := json.MarshalToString(mReq)
  938. logger.Error("func",
  939. zap.String("call", "pb.Garden.UnitList"),
  940. zap.String("params", s),
  941. zap.String("error", err.Error()))
  942. return 0, 0, "", false, errors.ErrorTransForm(err)
  943. }
  944. if len(mRsp.List) == 0 {
  945. return 0, 0, "", true, nil
  946. }
  947. return buildingId, mRsp.List[0].Id, array[2], false, nil
  948. }
  949. //
  950. // @Summary 房屋列表
  951. // @Description 房屋列表
  952. // @Tags 楼盘管理
  953. // @Accept json
  954. // @Produce json
  955. // @Param token header string true "token"
  956. // @Param page query int false " "
  957. // @Param page_size query int false " "
  958. // @Param house_number query int false "门牌号906"
  959. // @Param house_name query int false "总房号 1-2-906"
  960. // @Param building_id query int false "楼栋id"
  961. // @Param unit_id query int false "单元id"
  962. // @Param household_uid query int false "住户uid"
  963. // @Param house_type query int false "房屋类型 1 住宅 2 商铺 3 办公"
  964. // @Param house_rent query bool false "是否用于房屋租赁 true 是 false 否"
  965. // @Success 200 {object} v1.HouseListResponse
  966. // @Failure 500 {object} base.HTTPError
  967. // @Router /api/v1/buildings/house [get]
  968. func (c *Controller) HouseList(ctx *gin.Context) {
  969. // 解析参数
  970. req := &param_v1.HouseListRequest{}
  971. parseParamTask := func() error {
  972. err := util.ShouldBind(ctx, &req.Header, nil, &req.HouseListQuery, nil)
  973. if err != nil {
  974. logger.Error("func",
  975. zap.String("call", "util.ShouldBind"),
  976. zap.String("error", err.Error()))
  977. return errors.ParamsError
  978. }
  979. return nil
  980. }
  981. // 业务处理
  982. handleServiceTask := func() error {
  983. tokenInfo, err := utils.GetSubjectValue(ctx)
  984. if err != nil {
  985. return err
  986. }
  987. resp := param_v1.HouseListResponse{}
  988. resp.Data = v1.HouseListReply{
  989. Page: 1,
  990. Total: 0,
  991. List: make([]*v1.HouseItem, 0),
  992. }
  993. if req.HouseName != "" {
  994. shouldReturn := false
  995. var err error
  996. req.BuildingId, req.UnitId, req.HouseNumber, shouldReturn, err = handleHouseName(ctx, req.HouseName, tokenInfo)
  997. if err != nil {
  998. return err
  999. }
  1000. if shouldReturn {
  1001. ctx.JSON(http.StatusOK, resp)
  1002. return nil
  1003. }
  1004. }
  1005. // 响应数据
  1006. rpcReq := &v1.HouseListRequest{
  1007. GardenId: tokenInfo.GardenId,
  1008. HouseNumber: req.HouseNumber,
  1009. HouseType: req.HouseType,
  1010. BuildingId: req.BuildingId,
  1011. UnitId: req.UnitId,
  1012. Page: req.Page,
  1013. PageSize: req.PageSize,
  1014. Uid: req.HouseholdUid,
  1015. HouseRent: req.HouseRent,
  1016. }
  1017. rpcRsp, err := pb.Garden.HouseList(ctx, rpcReq)
  1018. if err != nil {
  1019. s, _ := json.MarshalToString(req)
  1020. logger.Error("func",
  1021. zap.String("call", "pb.Garden.HouseList"),
  1022. zap.String("params", s),
  1023. zap.String("error", err.Error()))
  1024. return errors.ErrorTransForm(err)
  1025. }
  1026. if rpcRsp.List == nil {
  1027. rpcRsp.List = make([]*v1.HouseItem, 0)
  1028. }
  1029. resp.Data = *rpcRsp
  1030. ctx.JSON(http.StatusOK, resp)
  1031. return nil
  1032. }
  1033. // 执行任务
  1034. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  1035. }
  1036. /*
  1037. //
  1038. // @Summary 批量添加
  1039. // @Description 批量添加
  1040. // @Tags 楼盘管理
  1041. // @Accept json
  1042. // @Produce json
  1043. // @Param token header string true "token"
  1044. // @Param body body v1.BatchHouseAddBody true "信息"
  1045. // @Success 200 {object} v1.HouseAddResponse
  1046. // @Failure 500 {object} base.HTTPError
  1047. // @Router /api/v1/buildings/batch [post]
  1048. func (c *Controller) BatchHouseAdd(ctx *gin.Context) {
  1049. // 解析参数
  1050. req := &param_v1.BatchHouseAddRequest{}
  1051. parseParamTask := func() error {
  1052. err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.BatchHouseAddBody)
  1053. if err != nil {
  1054. logger.Error("func",
  1055. zap.String("call", "util.ShouldBind"),
  1056. zap.String("error", err.Error()))
  1057. return errors.ParamsError
  1058. }
  1059. return nil
  1060. }
  1061. // 业务处理
  1062. handleServiceTask := func() error {
  1063. tokenInfo, err := utils.GetSubjectValue(ctx)
  1064. if err != nil {
  1065. return err
  1066. }
  1067. // 响应数据
  1068. resp := param_v1.BatchHouseAddResponse{}
  1069. rpcReq := &v1.BatchHouseAddRequest{
  1070. GardenId:tokenInfo.GardenId,
  1071. }
  1072. rpcReq.Buildings = make([]*v1.BatchBuildingItem, len(req.Buildings))
  1073. for i, _ := range req.Buildings {
  1074. rpcReq.Buildings[i] = &req.Buildings[i]
  1075. }
  1076. rpcReq.Units = make([]*v1.BatchUnitItem, len(req.Units))
  1077. for i, _ := range req.Units {
  1078. rpcReq.Units[i] = &req.Units[i]
  1079. }
  1080. rpcReq.Houses = make([]*v1.BatchHouseItem, len(req.Houses))
  1081. for i, _ := range req.Houses {
  1082. rpcReq.Houses[i] = &req.Houses[i]
  1083. }
  1084. _, err = pb.Garden.BatchHouseAdd(ctx, rpcReq)
  1085. if err != nil {
  1086. s, _ := json.MarshalToString(req)
  1087. logger.Error("func",
  1088. zap.String("call", "pb.Garden.BatchHouseAdd"),
  1089. zap.String("params", s),
  1090. zap.String("error", err.Error()))
  1091. return errors.ErrorTransForm(err)
  1092. }
  1093. ctx.JSON(http.StatusOK, resp)
  1094. return nil
  1095. }
  1096. // 执行任务
  1097. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  1098. }
  1099. */
  1100. var HouseTypeM = map[string]int{
  1101. "住宅": 1,
  1102. "商铺": 2,
  1103. "办公": 3,
  1104. }
  1105. func parseHouseImportContent(fileName string) ([]*v1.BatchHouseItem, error) {
  1106. f, err := xlsx.OpenFile(fileName)
  1107. if err != nil {
  1108. return nil, status.Error(10003, "xlsx 打开失败")
  1109. }
  1110. if len(f.Sheets) == 0 {
  1111. return nil, status.Error(10003, "参数文件没有sheet")
  1112. }
  1113. sheet := f.Sheets[0]
  1114. if len(sheet.Rows) == 0 {
  1115. return nil, status.Error(10003, "文件为空")
  1116. }
  1117. if len(sheet.Rows) > 1005 {
  1118. return nil, status.Error(10003, "单次导入不能超过一千条记录, 请分批导入")
  1119. }
  1120. list := []*v1.BatchHouseItem{}
  1121. for i, row := range sheet.Rows {
  1122. if len(row.Cells) < 9 {
  1123. return nil, status.Error(10003, fmt.Sprintf("第%d行", i)+"列数错误,请使用模板")
  1124. }
  1125. if i == 0 {
  1126. if row.Cells[0].Value != "楼栋编号" ||
  1127. row.Cells[1].Value != "单元编号" ||
  1128. row.Cells[2].Value != "房屋号" ||
  1129. row.Cells[3].Value != "房屋建筑面积" ||
  1130. row.Cells[4].Value != "房屋使用面积" ||
  1131. row.Cells[5].Value != "楼层" ||
  1132. //row.Cells[6].Value != "房屋类型" ||
  1133. !strings.Contains(row.Cells[6].Value, "房屋类型") ||
  1134. row.Cells[7].Value != "几室" ||
  1135. row.Cells[8].Value != "几厅" {
  1136. return nil, status.Error(10003, fmt.Sprintf("第%d行", i+1)+"标题错误,请使用模板")
  1137. }
  1138. continue
  1139. }
  1140. buidingNumber := strings.TrimSpace(row.Cells[0].Value)
  1141. unitNumberStr := strings.TrimSpace(row.Cells[1].Value)
  1142. houseNumber := strings.TrimSpace(row.Cells[2].Value)
  1143. houseAreaStr := strings.TrimSpace(row.Cells[3].Value)
  1144. houseUsedAreaStr := strings.TrimSpace(row.Cells[4].Value)
  1145. houseLevelStr := strings.TrimSpace(row.Cells[5].Value)
  1146. houseTypeStr := strings.TrimSpace(row.Cells[6].Value)
  1147. roomStr := strings.TrimSpace(row.Cells[7].Value)
  1148. hallStr := strings.TrimSpace(row.Cells[8].Value)
  1149. if buidingNumber == "" && unitNumberStr == "" &&
  1150. houseNumber == "" && houseAreaStr == "" &&
  1151. houseUsedAreaStr == "" && houseLevelStr == "" &&
  1152. houseTypeStr == "" && roomStr == "" && hallStr == "" {
  1153. continue
  1154. }
  1155. if buidingNumber == "" || unitNumberStr == "" ||
  1156. houseNumber == "" || houseAreaStr == "" ||
  1157. houseUsedAreaStr == "" || houseLevelStr == "" ||
  1158. houseTypeStr == "" && roomStr == "" && hallStr == "" {
  1159. return nil, status.Error(10003, fmt.Sprintf("第%d行", i+1)+"参数不能为空")
  1160. }
  1161. unitNumber, err := strconv.Atoi(unitNumberStr)
  1162. if err != nil {
  1163. return nil, status.Error(10003, fmt.Sprintf("第%d行", i+1)+"单元格式错误")
  1164. }
  1165. houseArea, err := strconv.ParseFloat(houseAreaStr, 64)
  1166. if err != nil {
  1167. return nil, status.Error(10003, fmt.Sprintf("第%d行", i+1)+"房屋建筑面积格式错误")
  1168. }
  1169. houseUsedArea, err := strconv.ParseFloat(houseUsedAreaStr, 64)
  1170. if err != nil {
  1171. return nil, status.Error(10003, fmt.Sprintf("第%d行", i+1)+"房屋使用面积面积格式错误")
  1172. }
  1173. houseLevel, err := strconv.Atoi(houseLevelStr)
  1174. if err != nil {
  1175. return nil, status.Error(10003, fmt.Sprintf("第%d行", i+1)+"楼层格式错误")
  1176. }
  1177. roomCount, err := strconv.Atoi(roomStr)
  1178. if err != nil {
  1179. return nil, status.Error(10003, fmt.Sprintf("第%d行", i+1)+"几室格式错误")
  1180. }
  1181. hallCount, err := strconv.Atoi(hallStr)
  1182. if err != nil {
  1183. return nil, status.Error(10003, fmt.Sprintf("第%d行", i+1)+"几厅格式错误")
  1184. }
  1185. houseType := HouseTypeM[houseTypeStr]
  1186. if houseType == 0 {
  1187. return nil, status.Error(10003, fmt.Sprintf("第%d行", i+1)+"不支持的房屋类型,房屋类型只支持住宅、公寓、商铺")
  1188. }
  1189. item := &v1.BatchHouseItem{
  1190. BuildingNumber: buidingNumber,
  1191. UnitNumber: int64(unitNumber),
  1192. HouseNumber: houseNumber,
  1193. HouseArea: houseArea,
  1194. HouseUsedArea: houseUsedArea,
  1195. HouseType: int64(houseType),
  1196. Layer: int64(houseLevel),
  1197. RoomCount: int64(roomCount),
  1198. HallCount: int64(hallCount),
  1199. }
  1200. list = append(list, item)
  1201. }
  1202. return list, nil
  1203. }
  1204. func parseUnitImportContent(fileName string) ([]*v1.BatchUnitItem, error) {
  1205. f, err := xlsx.OpenFile(fileName)
  1206. if err != nil {
  1207. return nil, status.Error(10003, "xlsx 打开失败")
  1208. }
  1209. if len(f.Sheets) == 0 {
  1210. return nil, status.Error(10003, "参数文件没有sheet")
  1211. }
  1212. sheet := f.Sheets[0]
  1213. if len(sheet.Rows) == 0 {
  1214. return nil, status.Error(10003, "文件为空")
  1215. }
  1216. if len(sheet.Rows) > 1005 {
  1217. return nil, status.Error(10003, "单次导入不能超过一千条记录, 请分批导入")
  1218. }
  1219. list := []*v1.BatchUnitItem{}
  1220. for i, row := range sheet.Rows {
  1221. if len(row.Cells) < 5 {
  1222. return nil, status.Error(10003, fmt.Sprintf("第%d行", i)+"列数错误,请使用模板")
  1223. }
  1224. if i == 0 {
  1225. if row.Cells[0].Value != "楼栋编号" ||
  1226. row.Cells[1].Value != "单元编号" ||
  1227. row.Cells[2].Value != "单元名称" ||
  1228. row.Cells[3].Value != "层数" ||
  1229. row.Cells[4].Value != "是否有电梯" {
  1230. return nil, status.Error(10003, fmt.Sprintf("第%d行", i+1)+"标题错误,请使用模板")
  1231. }
  1232. continue
  1233. }
  1234. buidingNumber := strings.TrimSpace(row.Cells[0].Value)
  1235. unitNumberStr := strings.TrimSpace(row.Cells[1].Value)
  1236. unitName := strings.TrimSpace(row.Cells[2].Value)
  1237. layersStr := strings.TrimSpace(row.Cells[3].Value)
  1238. hasLiftStr := strings.TrimSpace(row.Cells[4].Value)
  1239. if buidingNumber == "" && unitNumberStr == "" &&
  1240. unitName == "" && layersStr == "" &&
  1241. hasLiftStr == "" {
  1242. continue
  1243. }
  1244. if buidingNumber == "" || unitNumberStr == "" ||
  1245. unitName == "" || layersStr == "" ||
  1246. hasLiftStr == "" {
  1247. return nil, status.Error(10003, fmt.Sprintf("第%d行", i+1)+"参数不能为空")
  1248. }
  1249. unitNumber, err := strconv.Atoi(unitNumberStr)
  1250. if err != nil {
  1251. return nil, status.Error(10003, fmt.Sprintf("第%d行", i+1)+"单元格式错误")
  1252. }
  1253. layers, err := strconv.Atoi(layersStr)
  1254. if err != nil {
  1255. return nil, status.Error(10003, fmt.Sprintf("第%d行", i+1)+"层数格式错误")
  1256. }
  1257. hasLift := true
  1258. if hasLiftStr == "否" {
  1259. hasLift = false
  1260. } else if hasLiftStr != "是" {
  1261. return nil, status.Error(10003, fmt.Sprintf("第%d行", i+1)+"是否有电梯格式错误")
  1262. }
  1263. item := &v1.BatchUnitItem{
  1264. BuildingNumber: buidingNumber,
  1265. UnitNumber: int64(unitNumber),
  1266. UnitLayers: int64(layers),
  1267. UnitName: unitName,
  1268. HasLift: hasLift,
  1269. }
  1270. list = append(list, item)
  1271. }
  1272. return list, nil
  1273. }
  1274. func parseBuildingImportContent(fileName string) ([]*v1.BatchBuildingItem, error) {
  1275. f, err := xlsx.OpenFile(fileName)
  1276. if err != nil {
  1277. return nil, status.Error(10003, "xlsx 打开失败")
  1278. }
  1279. if len(f.Sheets) == 0 {
  1280. return nil, status.Error(10003, "参数文件没有sheet")
  1281. }
  1282. sheet := f.Sheets[0]
  1283. if len(sheet.Rows) == 0 {
  1284. return nil, status.Error(10003, "文件为空")
  1285. }
  1286. if len(sheet.Rows) > 1005 {
  1287. return nil, status.Error(10003, "单次导入不能超过一千条记录, 请分批导入")
  1288. }
  1289. list := []*v1.BatchBuildingItem{}
  1290. for i, row := range sheet.Rows {
  1291. if len(row.Cells) < 4 {
  1292. return nil, status.Error(10003, fmt.Sprintf("第%d行", i)+"列数错误,请使用模板")
  1293. }
  1294. if i == 0 {
  1295. if row.Cells[0].Value != "楼栋编号" ||
  1296. row.Cells[1].Value != "楼栋名称" ||
  1297. row.Cells[2].Value != "楼栋建筑面积" ||
  1298. row.Cells[3].Value != "楼栋使用面积" {
  1299. return nil, status.Error(10003, fmt.Sprintf("第%d行", i+1)+"标题错误,请使用模板")
  1300. }
  1301. continue
  1302. }
  1303. buidingNumber := strings.TrimSpace(row.Cells[0].Value)
  1304. buildingName := strings.TrimSpace(row.Cells[1].Value)
  1305. buildingAreaStr := strings.TrimSpace(row.Cells[2].Value)
  1306. buildingUsedAreaStr := strings.TrimSpace(row.Cells[3].Value)
  1307. if buidingNumber == "" && buildingName == "" {
  1308. continue
  1309. }
  1310. if buidingNumber == "" || buildingName == "" {
  1311. return nil, status.Error(10003, fmt.Sprintf("第%d行", i+1)+"参数不能为空")
  1312. }
  1313. buildingArea, err := strconv.ParseFloat(buildingAreaStr, 64)
  1314. if err != nil && buildingAreaStr != "" {
  1315. return nil, status.Error(10003, fmt.Sprintf("第%d行", i+1)+"楼栋面积格式错误")
  1316. }
  1317. buildingUsedArea, err := strconv.ParseFloat(buildingUsedAreaStr, 64)
  1318. if err != nil && buildingUsedAreaStr != "" {
  1319. return nil, status.Error(10003, fmt.Sprintf("第%d行", i+1)+"楼栋使用面积格式错误")
  1320. }
  1321. item := &v1.BatchBuildingItem{
  1322. BuildingNumber: buidingNumber,
  1323. BuildingName: buildingName,
  1324. BuildingArea: buildingArea,
  1325. BuildingUsedArea: buildingUsedArea,
  1326. }
  1327. list = append(list, item)
  1328. }
  1329. return list, nil
  1330. }
  1331. //
  1332. // @Summary 房屋导入
  1333. // @Description 房屋导入
  1334. // @Tags 楼盘管理
  1335. // @Accept json
  1336. // @Produce json
  1337. // @Param token header string true "token"
  1338. // @Param file formData file true "file"
  1339. // @Success 200 {object} v1.BatchHouseAddResponse
  1340. // @Failure 500 {object} base.HTTPError
  1341. // @Router /api/v1/buildings/house/import [post]
  1342. func (c Controller) HouseImport(ctx *gin.Context) {
  1343. // 解析参数
  1344. req := &param_v1.BatchHouseAddRequest{}
  1345. newFile := ""
  1346. var tokenInfo utils.TokenInfo
  1347. parseParamTask := func() error {
  1348. var err error
  1349. tokenInfo, err = utils.GetSubjectValue(ctx)
  1350. if err != nil {
  1351. return err
  1352. }
  1353. file, err := ctx.FormFile("file")
  1354. if err != nil {
  1355. return errors.SystemError
  1356. }
  1357. if file.Size > 10*1024*1024 {
  1358. return status.Error(10003, "文件过大")
  1359. }
  1360. ext := path.Ext(file.Filename)
  1361. if ext != ".xlsx" {
  1362. return status.Error(10003, "仅支持xlsx文件格式")
  1363. }
  1364. newFile = fmt.Sprintf("power-%s-%d-%d.xlsx", file.Filename, tokenInfo.Uid, time.Now().UnixNano())
  1365. err = ctx.SaveUploadedFile(file, newFile)
  1366. if err != nil {
  1367. logger.Error("func",
  1368. zap.String("call", "ctx.SaveUploadedFile"),
  1369. zap.String("error", err.Error()))
  1370. return status.Error(10003, "保存文件失败")
  1371. }
  1372. return nil
  1373. }
  1374. // 业务处理
  1375. handleServiceTask := func() error {
  1376. list, err := parseHouseImportContent(newFile)
  1377. if err != nil {
  1378. os.Remove(newFile)
  1379. return err
  1380. }
  1381. os.Remove(newFile)
  1382. if len(list) == 0 {
  1383. return nil
  1384. }
  1385. // 响应数据
  1386. resp := param_v1.BatchHouseAddResponse{}
  1387. rpcReq := &v1.BatchHouseAddRequest{
  1388. GardenId: tokenInfo.GardenId,
  1389. Houses: list,
  1390. }
  1391. _, err = pb.Garden.BatchHouseAdd(ctx, rpcReq)
  1392. if err != nil {
  1393. s, _ := json.MarshalToString(req)
  1394. logger.Error("func",
  1395. zap.String("call", "Garden.BatchHouseAdd"),
  1396. zap.String("params", s),
  1397. zap.String("error", err.Error()))
  1398. return errors.ErrorTransForm(err)
  1399. }
  1400. ctx.JSON(http.StatusOK, resp)
  1401. return nil
  1402. }
  1403. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  1404. }
  1405. //
  1406. // @Summary 单元导入
  1407. // @Description 单元导入
  1408. // @Tags 楼盘管理
  1409. // @Accept json
  1410. // @Produce json
  1411. // @Param token header string true "token"
  1412. // @Param file formData file true "file"
  1413. // @Success 200 {object} v1.BatchHouseAddResponse
  1414. // @Failure 500 {object} base.HTTPError
  1415. // @Router /api/v1/buildings/unit/import [post]
  1416. func (c Controller) UnitImport(ctx *gin.Context) {
  1417. // 解析参数
  1418. req := &param_v1.BatchHouseAddRequest{}
  1419. newFile := ""
  1420. var tokenInfo utils.TokenInfo
  1421. parseParamTask := func() error {
  1422. var err error
  1423. tokenInfo, err = utils.GetSubjectValue(ctx)
  1424. if err != nil {
  1425. return err
  1426. }
  1427. file, err := ctx.FormFile("file")
  1428. if err != nil {
  1429. return errors.SystemError
  1430. }
  1431. if file.Size > 10*1024*1024 {
  1432. return status.Error(10003, "文件过大")
  1433. }
  1434. ext := path.Ext(file.Filename)
  1435. if ext != ".xlsx" {
  1436. return status.Error(10003, "仅支持xlsx文件格式")
  1437. }
  1438. newFile = fmt.Sprintf("power-%s-%d-%d.xlsx", file.Filename, tokenInfo.Uid, time.Now().UnixNano())
  1439. err = ctx.SaveUploadedFile(file, newFile)
  1440. if err != nil {
  1441. logger.Error("func",
  1442. zap.String("call", "ctx.SaveUploadedFile"),
  1443. zap.String("error", err.Error()))
  1444. return status.Error(10003, "保存文件失败")
  1445. }
  1446. return nil
  1447. }
  1448. // 业务处理
  1449. handleServiceTask := func() error {
  1450. list, err := parseUnitImportContent(newFile)
  1451. if err != nil {
  1452. os.Remove(newFile)
  1453. return err
  1454. }
  1455. os.Remove(newFile)
  1456. if len(list) == 0 {
  1457. return nil
  1458. }
  1459. // 响应数据
  1460. resp := param_v1.BatchHouseAddResponse{}
  1461. rpcReq := &v1.BatchHouseAddRequest{
  1462. GardenId: tokenInfo.GardenId,
  1463. Units: list,
  1464. }
  1465. _, err = pb.Garden.BatchHouseAdd(ctx, rpcReq)
  1466. if err != nil {
  1467. s, _ := json.MarshalToString(req)
  1468. logger.Error("func",
  1469. zap.String("call", "Garden.BatchHouseAdd"),
  1470. zap.String("params", s),
  1471. zap.String("error", err.Error()))
  1472. return errors.ErrorTransForm(err)
  1473. }
  1474. ctx.JSON(http.StatusOK, resp)
  1475. return nil
  1476. }
  1477. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  1478. }
  1479. //
  1480. // @Summary 楼栋导入
  1481. // @Description 楼栋导入
  1482. // @Tags 楼盘管理
  1483. // @Accept json
  1484. // @Produce json
  1485. // @Param token header string true "token"
  1486. // @Param file formData file true "file"
  1487. // @Success 200 {object} v1.BatchHouseAddResponse
  1488. // @Failure 500 {object} base.HTTPError
  1489. // @Router /api/v1/buildings/building/import [post]
  1490. func (c Controller) BuildingImport(ctx *gin.Context) {
  1491. // 解析参数
  1492. req := &param_v1.BatchHouseAddRequest{}
  1493. newFile := ""
  1494. var tokenInfo utils.TokenInfo
  1495. parseParamTask := func() error {
  1496. var err error
  1497. tokenInfo, err = utils.GetSubjectValue(ctx)
  1498. if err != nil {
  1499. return err
  1500. }
  1501. file, err := ctx.FormFile("file")
  1502. if err != nil {
  1503. return errors.SystemError
  1504. }
  1505. if file.Size > 10*1024*1024 {
  1506. return status.Error(10003, "文件过大")
  1507. }
  1508. ext := path.Ext(file.Filename)
  1509. if ext != ".xlsx" {
  1510. return status.Error(10003, "仅支持xlsx文件格式")
  1511. }
  1512. newFile = fmt.Sprintf("power-%s-%d-%d.xlsx", file.Filename, tokenInfo.Uid, time.Now().UnixNano())
  1513. err = ctx.SaveUploadedFile(file, newFile)
  1514. if err != nil {
  1515. logger.Error("func",
  1516. zap.String("call", "ctx.SaveUploadedFile"),
  1517. zap.String("error", err.Error()))
  1518. return status.Error(10003, "保存文件失败")
  1519. }
  1520. return nil
  1521. }
  1522. // 业务处理
  1523. handleServiceTask := func() error {
  1524. list, err := parseBuildingImportContent(newFile)
  1525. if err != nil {
  1526. os.Remove(newFile)
  1527. return err
  1528. }
  1529. os.Remove(newFile)
  1530. if len(list) == 0 {
  1531. return nil
  1532. }
  1533. // 响应数据
  1534. resp := param_v1.BatchHouseAddResponse{}
  1535. rpcReq := &v1.BatchHouseAddRequest{
  1536. GardenId: tokenInfo.GardenId,
  1537. Buildings: list,
  1538. }
  1539. _, err = pb.Garden.BatchHouseAdd(ctx, rpcReq)
  1540. if err != nil {
  1541. s, _ := json.MarshalToString(req)
  1542. logger.Error("func",
  1543. zap.String("call", "Garden.BatchHouseAdd"),
  1544. zap.String("params", s),
  1545. zap.String("error", err.Error()))
  1546. return errors.ErrorTransForm(err)
  1547. }
  1548. ctx.JSON(http.StatusOK, resp)
  1549. return nil
  1550. }
  1551. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  1552. }
  1553. //
  1554. // @Summary 小区信息
  1555. // @Description 小区信息
  1556. // @Tags 小区
  1557. // @Accept json
  1558. // @Produce json
  1559. // @Param token header string true " "
  1560. // @Success 200 {object} v1.GardenInfoResponse
  1561. // @Failure 500 {object} base.HTTPError
  1562. // @Router /api/v1/garden [get]
  1563. func (c *Controller) GardenInfo(ctx *gin.Context) {
  1564. // 解析参数
  1565. req := &param_v1.GardenInfoRequest{}
  1566. parseParamTask := func() error {
  1567. err := util.ShouldBind(ctx, &req.Header, nil, nil, nil)
  1568. if err != nil {
  1569. logger.Error("func",
  1570. zap.String("call", "util.ShouldBind"),
  1571. zap.String("error", err.Error()))
  1572. return errors.ParamsError
  1573. }
  1574. return nil
  1575. }
  1576. // 业务处理
  1577. handleServiceTask := func() error {
  1578. tokenInfo, err := utils.GetSubjectValue(ctx)
  1579. if err != nil {
  1580. return err
  1581. }
  1582. // 响应数据
  1583. resp := param_v1.GardenInfoResponse{}
  1584. rpcReq := &v1.GardenInfosRequest{
  1585. Ids: []int64{tokenInfo.GardenId},
  1586. }
  1587. rpcRsp, err := pb.System.GardenInfos(ctx, rpcReq)
  1588. if err != nil {
  1589. s, _ := json.MarshalToString(req)
  1590. logger.Error("func",
  1591. zap.String("call", "Garden.GardenInfos"),
  1592. zap.String("params", s),
  1593. zap.String("error", err.Error()))
  1594. return errors.ErrorTransForm(err)
  1595. }
  1596. if rpcRsp.List == nil {
  1597. return errors.ErrRecordNotFound
  1598. }
  1599. for i, v := range rpcRsp.List {
  1600. if len(v.WaterType) == 0 {
  1601. rpcRsp.List[i].WaterType = []int32{}
  1602. }
  1603. if len(v.ElectricType) == 0 {
  1604. rpcRsp.List[i].ElectricType = []int32{}
  1605. }
  1606. if len(v.GardenPics) == 0 {
  1607. rpcRsp.List[i].GardenPics = []string{}
  1608. }
  1609. }
  1610. resp.Data = *rpcRsp.List[0]
  1611. ctx.JSON(http.StatusOK, resp)
  1612. return nil
  1613. }
  1614. // 执行任务
  1615. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  1616. }
  1617. //
  1618. // @Summary 修改小区普通信息
  1619. // @Description 修改小区普通信息
  1620. // @Tags 小区
  1621. // @Accept json
  1622. // @Produce json
  1623. // @Param token header string true " "
  1624. // @Param body body v1.GardenUpdateBody true "小区信息"
  1625. // @Success 200 {object} v1.GardenUpdateResponse
  1626. // @Failure 500 {object} base.HTTPError
  1627. // @Router /api/v1/garden [put]
  1628. func (c *Controller) GardenUpdate(ctx *gin.Context) {
  1629. // 解析参数
  1630. req := &param_v1.GardenUpdateRequest{}
  1631. parseParamTask := func() error {
  1632. err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.GardenUpdateBody)
  1633. if err != nil {
  1634. logger.Error("func",
  1635. zap.String("call", "util.ShouldBind"),
  1636. zap.String("error", err.Error()))
  1637. return errors.ParamsError
  1638. }
  1639. return nil
  1640. }
  1641. // 业务处理
  1642. handleServiceTask := func() error {
  1643. tokenInfo, err := utils.GetSubjectValue(ctx)
  1644. if err != nil {
  1645. return err
  1646. }
  1647. // 响应数据
  1648. resp := param_v1.GardenUpdateResponse{}
  1649. rpcReq := &v1.GardenUpdateRequest{
  1650. //Province: req.Province,
  1651. //ProvinceCode: req.ProvinceCode,
  1652. //City: req.City,
  1653. //CityCode: req.CityCode,
  1654. //Area: req.Area,
  1655. //AreaCode: req.AreaCode,
  1656. //Street: req.Street,
  1657. //StreetCode: req.StreetCode,
  1658. //Committee: req.Committee,
  1659. //CommitteeCode: req.CommitteeCode,
  1660. PropertyPerson: req.PropertyPerson,
  1661. PropertyPhone: req.PropertyPhone,
  1662. //GardenName: req.GardenName,
  1663. GardenAddr: req.GardenAddr,
  1664. Cid: tokenInfo.Cid,
  1665. Id: tokenInfo.GardenId,
  1666. GardenPic: req.GardenPic,
  1667. GardenDesc: req.GardenDesc,
  1668. Lnt: req.Lnt,
  1669. Lat: req.Lat,
  1670. GardenPics: req.GardenPics,
  1671. BuildingStart: req.BuildingStart,
  1672. BuildingEnd: req.BuildingEnd,
  1673. PropertyFeeStart: req.PropertyFeeStart,
  1674. PropertyFeeEnd: req.PropertyFeeEnd,
  1675. GasFeeStart: req.GasFeeStart,
  1676. GasFeeEnd: req.GasFeeEnd,
  1677. BuildingArea: req.BuildingArea,
  1678. BuildingCompany: req.BuildingCompany,
  1679. CoveredArea: req.CoveredArea,
  1680. GreenPercent: req.GreenPercent,
  1681. AreaPercent: req.AreaPercent,
  1682. SpaceInfo: req.SpaceInfo,
  1683. SpaceTotal: req.SpaceTotal,
  1684. HouseTotal: req.HouseTotal,
  1685. BuildingType: req.BuildingType,
  1686. WaterType: req.WaterType,
  1687. ElectricType: req.ElectricType,
  1688. AvgPrice: req.AvgPrice,
  1689. }
  1690. _, err = pb.System.GardenUpdate(ctx, rpcReq)
  1691. if err != nil {
  1692. s, _ := json.MarshalToString(req)
  1693. logger.Error("func",
  1694. zap.String("call", "pb.Garden.GardenUpdate"),
  1695. zap.String("params", s),
  1696. zap.String("error", err.Error()))
  1697. return errors.ErrorTransForm(err)
  1698. }
  1699. ctx.JSON(http.StatusOK, resp)
  1700. return nil
  1701. }
  1702. // 执行任务
  1703. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  1704. }
  1705. //
  1706. // @Summary 申请修改小区关键信息
  1707. // @Description 申请修改小区关键信息
  1708. // @Tags 小区
  1709. // @Accept json
  1710. // @Produce json
  1711. // @Param token header string true " "
  1712. // @Param body body v1.GardenKeyInfoChangeBody true "小区信息"
  1713. // @Success 200 {object} v1.GardenKeyInfoChangeResponse
  1714. // @Failure 500 {object} base.HTTPError
  1715. // @Router /api/v1/garden/key_info [put]
  1716. func (c *Controller) GardenKeyInfoChange(ctx *gin.Context) {
  1717. // 解析参数
  1718. req := &param_v1.GardenKeyInfoChangeRequest{}
  1719. parseParamTask := func() error {
  1720. err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.GardenKeyInfoChangeBody)
  1721. if err != nil {
  1722. logger.Error("func",
  1723. zap.String("call", "util.ShouldBind"),
  1724. zap.String("error", err.Error()))
  1725. return errors.ParamsError
  1726. }
  1727. return nil
  1728. }
  1729. // 业务处理
  1730. handleServiceTask := func() error {
  1731. tokenInfo, err := utils.GetSubjectValue(ctx)
  1732. if err != nil {
  1733. return err
  1734. }
  1735. // 响应数据
  1736. resp := param_v1.GardenKeyInfoChangeResponse{}
  1737. rpcReq := &v1.GardenKeyInfoChangeRequest{
  1738. Province: req.Province,
  1739. ProvinceCode: req.ProvinceCode,
  1740. City: req.City,
  1741. CityCode: req.CityCode,
  1742. Area: req.Area,
  1743. AreaCode: req.AreaCode,
  1744. Street: req.Street,
  1745. StreetCode: req.StreetCode,
  1746. Committee: req.Committee,
  1747. CommitteeCode: req.CommitteeCode,
  1748. Cid: tokenInfo.Cid,
  1749. Id: tokenInfo.GardenId,
  1750. GardenName: req.GardenName,
  1751. }
  1752. _, err = pb.System.GardenKeyInfoChange(ctx, rpcReq)
  1753. if err != nil {
  1754. s, _ := json.MarshalToString(req)
  1755. logger.Error("func",
  1756. zap.String("call", "pb.Garden.GardenKeyInfoChange"),
  1757. zap.String("params", s),
  1758. zap.String("error", err.Error()))
  1759. return errors.ErrorTransForm(err)
  1760. }
  1761. ctx.JSON(http.StatusOK, resp)
  1762. return nil
  1763. }
  1764. // 执行任务
  1765. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  1766. }
  1767. //
  1768. // @Summary 小区关键信息申请列表
  1769. // @Description 小区关键信息申请列表
  1770. // @Tags 小区
  1771. // @Accept json
  1772. // @Produce json
  1773. // @Param token header string true " "
  1774. // @Param page query int false " "
  1775. // @Param page_size query int false " "
  1776. // @Param status query int false "0不过率 1 待审核 2 审核通过 3 未通过 "
  1777. // @Success 200 {object} v1.GardenKeyInfoChangeListResponse
  1778. // @Failure 500 {object} base.HTTPError
  1779. // @Router /api/v1/garden/key_info [get]
  1780. func (c *Controller) GardenKeyInfoChangeList(ctx *gin.Context) {
  1781. // 解析参数
  1782. req := &param_v1.GardenKeyInfoChangeListRequest{}
  1783. parseParamTask := func() error {
  1784. err := util.ShouldBind(ctx, &req.Header, nil, &req.GardenKeyInfoChangeListQuery, nil)
  1785. if err != nil {
  1786. logger.Error("func",
  1787. zap.String("call", "util.ShouldBind"),
  1788. zap.String("error", err.Error()))
  1789. return errors.ParamsError
  1790. }
  1791. return nil
  1792. }
  1793. // 业务处理
  1794. handleServiceTask := func() error {
  1795. tokenInfo, err := utils.GetSubjectValue(ctx)
  1796. if err != nil {
  1797. return err
  1798. }
  1799. // 响应数据
  1800. resp := param_v1.GardenKeyInfoChangeListResponse{}
  1801. rpcReq := &v1.GardenKeyInfoChangeListRequest{
  1802. Cid: tokenInfo.Cid,
  1803. GardenId: tokenInfo.GardenId,
  1804. Status: req.Status,
  1805. Page: req.Page,
  1806. PageSize: req.PageSize,
  1807. }
  1808. rpcRsp, err := pb.System.GardenKeyInfoChangeList(ctx, rpcReq)
  1809. if err != nil {
  1810. s, _ := json.MarshalToString(req)
  1811. logger.Error("func",
  1812. zap.String("call", "pb.Garden.GardenKeyInfoChangeList"),
  1813. zap.String("params", s),
  1814. zap.String("error", err.Error()))
  1815. return errors.ErrorTransForm(err)
  1816. }
  1817. if rpcRsp.List == nil {
  1818. rpcRsp.List = make([]*v1.GardenKeyInfoData, 0)
  1819. }
  1820. resp.Data = *rpcRsp
  1821. ctx.JSON(http.StatusOK, resp)
  1822. return nil
  1823. }
  1824. // 执行任务
  1825. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  1826. }
  1827. //
  1828. // @Summary 获取单元模板
  1829. // @Description 获取单元模板
  1830. // @Tags 楼盘管理
  1831. // @Accept json
  1832. // @Produce json
  1833. // @Param token header string true "token"
  1834. // @Success 200 {object} v1.TemplateResponse
  1835. // @Failure 500 {object} base.HTTPError
  1836. // @Router /api/v1/buildings/unit/template [get]
  1837. func (c *Controller) UnitTemplate(ctx *gin.Context) {
  1838. // 解析参数
  1839. req := &param_v1.TemplateRequest{}
  1840. parseParamTask := func() error {
  1841. err := util.ShouldBind(ctx, &req.Header, nil, nil, nil)
  1842. if err != nil {
  1843. logger.Error("func",
  1844. zap.String("call", "util.ShouldBind"),
  1845. zap.String("error", err.Error()))
  1846. return errors.ParamsError
  1847. }
  1848. return nil
  1849. }
  1850. // 业务处理
  1851. handleServiceTask := func() error {
  1852. // 响应数据
  1853. resp := param_v1.TemplateResponse{}
  1854. resp.Data.Url = parser.Conf.Oss.UnitTempUrl
  1855. ctx.JSON(http.StatusOK, resp)
  1856. return nil
  1857. }
  1858. // 执行任务
  1859. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  1860. }
  1861. //
  1862. // @Summary 获取楼盘模板
  1863. // @Description 获取楼盘模板
  1864. // @Tags 楼盘管理
  1865. // @Accept json
  1866. // @Produce json
  1867. // @Param token header string true "token"
  1868. // @Success 200 {object} v1.TemplateResponse
  1869. // @Failure 500 {object} base.HTTPError
  1870. // @Router /api/v1/buildings/building/template [get]
  1871. func (c *Controller) BuildingTemplate(ctx *gin.Context) {
  1872. // 解析参数
  1873. req := &param_v1.TemplateRequest{}
  1874. parseParamTask := func() error {
  1875. err := util.ShouldBind(ctx, &req.Header, nil, nil, nil)
  1876. if err != nil {
  1877. logger.Error("func",
  1878. zap.String("call", "util.ShouldBind"),
  1879. zap.String("error", err.Error()))
  1880. return errors.ParamsError
  1881. }
  1882. return nil
  1883. }
  1884. // 业务处理
  1885. handleServiceTask := func() error {
  1886. // 响应数据
  1887. resp := param_v1.TemplateResponse{}
  1888. resp.Data.Url = parser.Conf.Oss.BuildingTempUrl
  1889. ctx.JSON(http.StatusOK, resp)
  1890. return nil
  1891. }
  1892. // 执行任务
  1893. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  1894. }
  1895. //
  1896. // @Summary 获取房屋模板
  1897. // @Description 获取房屋模板
  1898. // @Tags 楼盘管理
  1899. // @Accept json
  1900. // @Produce json
  1901. // @Param token header string true "token"
  1902. // @Success 200 {object} v1.TemplateResponse
  1903. // @Failure 500 {object} base.HTTPError
  1904. // @Router /api/v1/buildings/house/template [get]
  1905. func (c *Controller) HouseTemplate(ctx *gin.Context) {
  1906. // 解析参数
  1907. req := &param_v1.TemplateRequest{}
  1908. parseParamTask := func() error {
  1909. err := util.ShouldBind(ctx, &req.Header, nil, nil, nil)
  1910. if err != nil {
  1911. logger.Error("func",
  1912. zap.String("call", "util.ShouldBind"),
  1913. zap.String("error", err.Error()))
  1914. return errors.ParamsError
  1915. }
  1916. return nil
  1917. }
  1918. // 业务处理
  1919. handleServiceTask := func() error {
  1920. // 响应数据
  1921. resp := param_v1.TemplateResponse{}
  1922. resp.Data.Url = parser.Conf.Oss.HouseTempUrl
  1923. ctx.JSON(http.StatusOK, resp)
  1924. return nil
  1925. }
  1926. // 执行任务
  1927. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  1928. }