PlaceBaseInfoController.java 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. package com.zhiqiyun.open.mvc.controller;
  2. import com.alibaba.fastjson.JSON;
  3. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  4. import com.baomidou.mybatisplus.core.metadata.OrderItem;
  5. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  6. import com.zhiqiyun.open.annotation.Permission;
  7. import com.zhiqiyun.open.core.models.place.PlaceBaseInfo;
  8. import com.zhiqiyun.open.core.models.place.PlaceBaseInfoExtend;
  9. import com.zhiqiyun.open.core.models.place.PlaceCategory;
  10. import com.zhiqiyun.open.core.models.place.PlaceCategoryExtendColumn;
  11. import com.zhiqiyun.open.core.models.user.OauthInfo;
  12. import com.zhiqiyun.open.core.service.*;
  13. import com.zhiqiyun.open.mvc.Result;
  14. import com.zhiqiyun.open.mvc.params.place.QueryPlaceBaseInfoParam;
  15. import com.zhiqiyun.open.mvc.params.place.SavePlaceBaseInfoExtendParam;
  16. import com.zhiqiyun.open.mvc.params.place.SavePlaceBaseInfoParam;
  17. import com.zhiqiyun.open.utils.DateUtil;
  18. import com.zhiqiyun.open.utils.ServletContext;
  19. import lombok.extern.slf4j.Slf4j;
  20. import org.apache.commons.codec.digest.DigestUtils;
  21. import org.apache.commons.lang3.StringUtils;
  22. import org.springframework.beans.BeanUtils;
  23. import org.springframework.beans.factory.annotation.Autowired;
  24. import org.springframework.web.bind.annotation.*;
  25. import javax.validation.Valid;
  26. import java.math.BigDecimal;
  27. import java.util.ArrayList;
  28. import java.util.HashMap;
  29. import java.util.List;
  30. import java.util.Map;
  31. @Slf4j
  32. @RestController
  33. @RequestMapping("/place/info")
  34. public class PlaceBaseInfoController {
  35. @Autowired
  36. private PlaceCategoryService placeCategoryService;
  37. @Autowired
  38. private PlaceCategoryExtendColumnService placeCategoryExtendColumnService;
  39. @Autowired
  40. private PlaceBaseInfoService placeBaseInfoService;
  41. @Autowired
  42. private PlaceBaseInfoExtendService placeBaseInfoExtendService;
  43. @Autowired
  44. private SequenceService sequenceService;
  45. @Autowired
  46. private OauthService oauthService;
  47. @Permission(value = "place.base.info.find", tags = "查询文旅场所")
  48. @PostMapping("/findPage")
  49. public Result findPage(@RequestBody QueryPlaceBaseInfoParam param) {
  50. QueryWrapper<PlaceBaseInfo> wrapper = new QueryWrapper<>();
  51. if (StringUtils.isNotBlank(param.getName())) {
  52. wrapper.like("name", param.getName());
  53. }
  54. Page<PlaceBaseInfo> page = param.getPage();
  55. page.addOrder(OrderItem.desc("id"));
  56. Page<PlaceBaseInfo> resultData = this.placeBaseInfoService.page(page, wrapper);
  57. for (PlaceBaseInfo baseInfo : resultData.getRecords()) {
  58. PlaceCategory category = this.placeCategoryService.getById(baseInfo.getCategoryId());
  59. baseInfo.setCategory(category);
  60. }
  61. return Result.instance(Result.Code.SUCCESS).setData(resultData);
  62. }
  63. @Permission(value = "place.base.info.add", tags = "新建文旅场所")
  64. @PostMapping("/save")
  65. public Result save(@Valid @RequestBody SavePlaceBaseInfoParam param) throws Exception {
  66. PlaceBaseInfo entity = new PlaceBaseInfo();
  67. BeanUtils.copyProperties(param, entity);
  68. OauthInfo oauthInfo = this.oauthService.getAuth(ServletContext.getAccessToken());
  69. entity.setCreatedTime(DateUtil.current());
  70. entity.setCreatedBy(oauthInfo.getId());
  71. entity.setUpdatedTime(DateUtil.current());
  72. entity.setUpdatedBy(oauthInfo.getId());
  73. entity.setId(this.sequenceService.nextId());
  74. List<PlaceBaseInfoExtend> listExtends = new ArrayList<>();
  75. if (param.getListExtends() != null) {
  76. for (SavePlaceBaseInfoExtendParam extendParam : param.getListExtends()) {
  77. PlaceBaseInfoExtend extend = new PlaceBaseInfoExtend();
  78. BeanUtils.copyProperties(extendParam, extend);
  79. listExtends.add(extend);
  80. }
  81. }
  82. this.placeBaseInfoService.save(entity, listExtends);
  83. return Result.instance(Result.Code.MESSAGE_SUCCESS);
  84. }
  85. @Permission(value = "place.base.info.edit", tags = "更新文旅场所")
  86. @PostMapping("/updateById")
  87. public Result updateById(Long id, @Valid @RequestBody SavePlaceBaseInfoParam param) {
  88. PlaceBaseInfo entity = new PlaceBaseInfo();
  89. BeanUtils.copyProperties(param, entity);
  90. OauthInfo oauthInfo = this.oauthService.getAuth(ServletContext.getAccessToken());
  91. entity.setUpdatedBy(oauthInfo.getId());
  92. entity.setUpdatedTime(DateUtil.current());
  93. entity.setId(id);
  94. List<PlaceBaseInfoExtend> listExtends = new ArrayList<>();
  95. if (param.getListExtends() != null) {
  96. for (SavePlaceBaseInfoExtendParam extendParam : param.getListExtends()) {
  97. PlaceBaseInfoExtend extend = new PlaceBaseInfoExtend();
  98. BeanUtils.copyProperties(extendParam, extend);
  99. listExtends.add(extend);
  100. }
  101. }
  102. log.info(JSON.toJSONString(listExtends));
  103. this.placeBaseInfoService.updateById(entity, listExtends);
  104. return Result.instance(Result.Code.MESSAGE_SUCCESS);
  105. }
  106. @Permission(value = "place.base.info.delete", tags = "删除文旅场所")
  107. @PostMapping("/deleteByIds")
  108. public Result deleteByIds(@RequestBody List<Long> ids) {
  109. this.placeBaseInfoService.removeByIds(ids);
  110. return Result.instance(Result.Code.MESSAGE_SUCCESS);
  111. }
  112. @Permission(value = "place.base.info.gis.map", tags = "分类组查询数量", writeLog = false)
  113. @PostMapping("/findByGroupByDataType")
  114. public Result findByGroupByDataType() {
  115. List<PlaceCategory> list = this.placeCategoryService.list();
  116. List<Map<String, Object>> listData = new ArrayList<>();
  117. Map<String, Object> mapList = this.placeBaseInfoService.findByGroupByDataType();
  118. for (PlaceCategory category : list) {
  119. Map<String, Object> dataMap = new HashMap<>();
  120. dataMap.put("category", category);
  121. Object l = mapList.get("resource_" + category.getId());
  122. dataMap.put("num", l != null ? l : 0);
  123. listData.add(dataMap);
  124. }
  125. return Result.instance(Result.Code.SUCCESS).setData(listData);
  126. }
  127. @ResponseBody
  128. @PostMapping("/findByMapBounds")
  129. public Result findByMapBounds(BigDecimal maxlng, BigDecimal maxlat, BigDecimal minlng, BigDecimal minlat, Long categoryId) {
  130. QueryWrapper<PlaceBaseInfo> queryWrapper = new QueryWrapper<>();
  131. if (maxlng != null) {
  132. queryWrapper.le("f.lng", maxlng);
  133. }
  134. if (maxlat != null) {
  135. queryWrapper.le("f.lat", maxlat);
  136. }
  137. if (minlng != null) {
  138. queryWrapper.ge("f.lng", minlng);
  139. }
  140. if (minlat != null) {
  141. queryWrapper.ge("f.lat", minlat);
  142. }
  143. if (categoryId != null) {
  144. queryWrapper.eq("f.categoryId", categoryId);
  145. }
  146. List<PlaceBaseInfo> listData = this.placeBaseInfoService.findByMapBounds(queryWrapper);
  147. for (PlaceBaseInfo baseInfo : listData) {
  148. PlaceCategory category = this.placeCategoryService.getById(baseInfo.getCategoryId());
  149. baseInfo.setCategory(category);
  150. }
  151. return Result.instance(Result.Code.SUCCESS).setData(listData);
  152. }
  153. @PostMapping("/findAllDataType")
  154. @Permission(value = {"place.base.info.edit", "place.base.info.add"}, tags = "获取文旅场所", writeLog = false)
  155. public Result findAllDataType() {
  156. List<PlaceCategory> listData = this.placeCategoryService.list();
  157. return Result.instance(Result.Code.SUCCESS).setData(listData);
  158. }
  159. @PostMapping("/findDataBaseInfoExtends")
  160. @Permission(value = {"place.base.info.edit", "place.base.info.add"}, tags = "获取文旅场所扩展字段", writeLog = false)
  161. public Result findDataBaseInfoExtends(Long baseInfoId, Long categoryId) {
  162. QueryWrapper<PlaceCategoryExtendColumn> queryWrapper = new QueryWrapper<>();
  163. queryWrapper.eq("category_id", categoryId);
  164. List<PlaceCategoryExtendColumn> listData = this.placeCategoryExtendColumnService.list(queryWrapper);
  165. if (baseInfoId != null) {
  166. for (PlaceCategoryExtendColumn extendColumn : listData) {
  167. String id = DigestUtils.md5Hex(String.format("%s@%s", baseInfoId, extendColumn.getId()));
  168. PlaceBaseInfoExtend extend = this.placeBaseInfoExtendService.getById(id);
  169. if (extend != null) {
  170. extendColumn.setFieldValue(extend.getFieldValue());
  171. }
  172. }
  173. }
  174. return Result.instance(Result.Code.SUCCESS).setData(listData);
  175. }
  176. @ResponseBody
  177. @PostMapping("/findSelectByKeyword")
  178. public Result findSelectBaseInfoByKeyword(String keyword) throws Exception {
  179. QueryWrapper<PlaceBaseInfo> queryWrapper = new QueryWrapper<>();
  180. if (StringUtils.isNotBlank(keyword)) {
  181. queryWrapper.like("id", keyword);
  182. queryWrapper.or();
  183. queryWrapper.like("name", keyword);
  184. queryWrapper.or();
  185. queryWrapper.like("brief", keyword);
  186. queryWrapper.or();
  187. queryWrapper.like("address", keyword);
  188. queryWrapper.or();
  189. queryWrapper.like("contacts", keyword);
  190. queryWrapper.or();
  191. queryWrapper.like("contact_number", keyword);
  192. queryWrapper.or();
  193. queryWrapper.inSql("category_id", "select id from place_category where name like '%" + keyword + "%'");
  194. }
  195. queryWrapper.last("limit 10");
  196. queryWrapper.orderByDesc("id");
  197. List<PlaceBaseInfo> listData = this.placeBaseInfoService.list(queryWrapper);
  198. for (PlaceBaseInfo baseInfo : listData) {
  199. PlaceCategory category = this.placeCategoryService.getById(baseInfo.getCategoryId());
  200. baseInfo.setCategory(category);
  201. }
  202. return Result.instance(Result.Code.SUCCESS).setData(listData);
  203. }
  204. }