|
@@ -3,43 +3,42 @@ package com.github.zuihou.business.controller.place;
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.github.zuihou.authority.dao.common.DictionaryItemMapper;
|
|
|
+import com.github.zuihou.authority.dto.core.OrgSaveDTO;
|
|
|
import com.github.zuihou.authority.entity.auth.User;
|
|
|
import com.github.zuihou.authority.entity.common.DictionaryItem;
|
|
|
import com.github.zuihou.authority.entity.core.Org;
|
|
|
import com.github.zuihou.authority.service.auth.UserService;
|
|
|
import com.github.zuihou.authority.service.core.OrgService;
|
|
|
+import com.github.zuihou.base.R;
|
|
|
+import com.github.zuihou.base.controller.SuperController;
|
|
|
import com.github.zuihou.base.request.PageParams;
|
|
|
-import com.github.zuihou.business.company.entity.Company;
|
|
|
-import com.github.zuihou.business.order.dto.OrderPageDTO;
|
|
|
-import com.github.zuihou.business.order.entity.Order;
|
|
|
-import com.github.zuihou.business.place.entity.Place;
|
|
|
+import com.github.zuihou.business.place.dto.PlacePageDTO;
|
|
|
import com.github.zuihou.business.place.dto.PlaceSaveDTO;
|
|
|
import com.github.zuihou.business.place.dto.PlaceUpdateDTO;
|
|
|
-import com.github.zuihou.business.place.dto.PlacePageDTO;
|
|
|
+import com.github.zuihou.business.place.entity.Place;
|
|
|
import com.github.zuihou.business.place.service.PlaceService;
|
|
|
-
|
|
|
-import java.lang.reflect.Array;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.LinkedList;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
-import java.util.stream.Collectors;
|
|
|
-
|
|
|
-import com.github.zuihou.base.controller.SuperController;
|
|
|
-import com.github.zuihou.base.R;
|
|
|
-import com.github.zuihou.database.mybatis.conditions.Wraps;
|
|
|
+import com.github.zuihou.business.place_region.PlaceRegion;
|
|
|
+import com.github.zuihou.business.place_region.dao.PlaceRegionMapper;
|
|
|
import com.github.zuihou.database.mybatis.conditions.query.LbqWrapper;
|
|
|
import com.github.zuihou.database.mybatis.conditions.query.QueryWrap;
|
|
|
+import com.github.zuihou.security.annotation.PreAuth;
|
|
|
+import com.github.zuihou.utils.BeanPlusUtil;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.data.redis.connection.ReactiveGeoCommands;
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
-import org.springframework.web.bind.annotation.*;
|
|
|
-import com.github.zuihou.security.annotation.PreAuth;
|
|
|
+import org.springframework.web.bind.annotation.GetMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestParam;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
+import java.util.LinkedList;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* 场地控制器
|
|
@@ -58,7 +57,7 @@ public class PlaceController extends SuperController<PlaceService, Long, Place,
|
|
|
@Resource
|
|
|
private OrgService orgService;
|
|
|
@Resource
|
|
|
- private DictionaryItemMapper dictionaryItemMapper;
|
|
|
+ private PlaceRegionMapper placeRegionMapper;
|
|
|
|
|
|
/**
|
|
|
* 分页查询
|
|
@@ -81,7 +80,8 @@ public class PlaceController extends SuperController<PlaceService, Long, Place,
|
|
|
lbqWrapper.eq(Place::getPlcCid, model.getPlcCid());
|
|
|
baseService.page(page, wrapper);
|
|
|
|
|
|
- List<Long> regionIds = new LinkedList<>();
|
|
|
+ // 场地ID列表
|
|
|
+ List<Long> ids = new LinkedList<>();
|
|
|
List<Place> placeList = page.getRecords();
|
|
|
for (Place place : placeList)
|
|
|
{
|
|
@@ -89,20 +89,65 @@ public class PlaceController extends SuperController<PlaceService, Long, Place,
|
|
|
place.setPlcComDesc(getPlaceComDescById(place.getCreateUser()));
|
|
|
place.setSelectedOptions(arr);
|
|
|
|
|
|
- if (null != place.getRegionId())
|
|
|
+ ids.add(place.getId());
|
|
|
+ }
|
|
|
+
|
|
|
+ // 补充所属区域属性
|
|
|
+ if (ids.size() > 0)
|
|
|
+ {
|
|
|
+ Map<Long, Map<String, Object>> placeRegions = placeRegionMapper.findByPlaceIds(StringUtils.join(ids, ","));
|
|
|
+
|
|
|
+ Map<String, Object> rows;
|
|
|
+ for (Place place : placeList)
|
|
|
{
|
|
|
- regionIds.add(place.getRegionId());
|
|
|
+ rows = placeRegions.get(place.getId());
|
|
|
+ if (null != rows)
|
|
|
+ {
|
|
|
+ place.setRegionIds((String) rows.getOrDefault("RegionIds", ""));
|
|
|
+ place.setRegions((String) rows.getOrDefault("Regions", ""));
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- // 补充所属区域属性
|
|
|
- if (regionIds.size() > 0)
|
|
|
+ @Override
|
|
|
+ public R<Place> handlerSave(PlaceSaveDTO model)
|
|
|
+ {
|
|
|
+ // 1 保存场地
|
|
|
+ Place p = BeanPlusUtil.toBean(model, Place.class);
|
|
|
+ this.baseService.save(p);
|
|
|
+
|
|
|
+ // 2 保存所属区域
|
|
|
+ String[] regionIds = p.getRegionIds().split(",");
|
|
|
+ for (String rId : regionIds)
|
|
|
{
|
|
|
- Map<Long, String> names = dictionaryItemMapper.selectBatchIds(regionIds).stream()
|
|
|
- .collect(Collectors.toMap(DictionaryItem::getId, DictionaryItem::getName));
|
|
|
+ placeRegionMapper.insert(PlaceRegion.builder().placeId(p.getId()).regionId(Long.parseLong(rId)).build());
|
|
|
+ }
|
|
|
+
|
|
|
+ return success(p);
|
|
|
+ }
|
|
|
|
|
|
- placeList.forEach(p -> p.setRegion(names.getOrDefault(p.getRegionId(), "")));
|
|
|
+ @Override
|
|
|
+ public R<Place> handlerUpdate(PlaceUpdateDTO model)
|
|
|
+ {
|
|
|
+ // 1 保存场地
|
|
|
+ Place p = BeanPlusUtil.toBean(model, Place.class);
|
|
|
+ this.baseService.updateAllById(p);
|
|
|
+
|
|
|
+ // 2 保存所属区域
|
|
|
+ // 2.1 删除老数据
|
|
|
+ placeRegionMapper.deleteByPlaceId(p.getId());
|
|
|
+ // 2.2 插入新数据
|
|
|
+ String[] regionIds = p.getRegionIds().split(",");
|
|
|
+ for (String rId : regionIds)
|
|
|
+ {
|
|
|
+ placeRegionMapper.insert(PlaceRegion.builder()
|
|
|
+ .placeId(p.getId())
|
|
|
+ .regionId(Long.parseLong(rId))
|
|
|
+ .build());
|
|
|
}
|
|
|
+
|
|
|
+ return success(p);
|
|
|
}
|
|
|
|
|
|
/**
|