|
@@ -2,7 +2,9 @@ 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.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;
|
|
@@ -18,12 +20,14 @@ 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.database.mybatis.conditions.query.LbqWrapper;
|
|
|
import com.github.zuihou.database.mybatis.conditions.query.QueryWrap;
|
|
|
import io.swagger.annotations.Api;
|
|
@@ -35,34 +39,40 @@ import org.springframework.validation.annotation.Validated;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
import com.github.zuihou.security.annotation.PreAuth;
|
|
|
|
|
|
+import javax.annotation.Resource;
|
|
|
|
|
|
/**
|
|
|
- * <p>
|
|
|
- * 前端控制器
|
|
|
- * 场地管理
|
|
|
- * </p>
|
|
|
+ * 场地管理前端控制器
|
|
|
*
|
|
|
* @author zuihou
|
|
|
* @date 2022-01-08
|
|
|
*/
|
|
|
-@Slf4j
|
|
|
-@Validated
|
|
|
-@RestController
|
|
|
-@RequestMapping("/place")
|
|
|
-@Api(value = "Place", tags = "场地管理")
|
|
|
+@Validated @Slf4j
|
|
|
@PreAuth(replace = "place:")
|
|
|
-public class PlaceController extends SuperController<PlaceService, Long, Place, PlacePageDTO, PlaceSaveDTO,
|
|
|
- PlaceUpdateDTO> {
|
|
|
- @Autowired
|
|
|
+@Api(value = "Place", tags = "场地管理")
|
|
|
+@RestController @RequestMapping("/place")
|
|
|
+public class PlaceController extends SuperController<PlaceService, Long, Place, PlacePageDTO, PlaceSaveDTO, PlaceUpdateDTO>
|
|
|
+{
|
|
|
+ @Resource
|
|
|
private UserService userService;
|
|
|
-
|
|
|
- @Autowired
|
|
|
+ @Resource
|
|
|
private OrgService orgService;
|
|
|
+ @Resource
|
|
|
+ private DictionaryItemMapper dictionaryItemMapper;
|
|
|
|
|
|
+ /**
|
|
|
+ * 分页查询
|
|
|
+ *
|
|
|
+ * @param params 查询参数
|
|
|
+ * @param page 分页信息
|
|
|
+ * @param defSize def大小
|
|
|
+ */
|
|
|
@Override
|
|
|
- public void query(PageParams<PlacePageDTO> params, IPage<Place> page, Long defSize) {
|
|
|
+ public void query(PageParams<PlacePageDTO> params, IPage<Place> page, Long defSize)
|
|
|
+ {
|
|
|
PlacePageDTO data = params.getModel();
|
|
|
Place model = BeanUtil.toBean(data, Place.class);
|
|
|
+
|
|
|
QueryWrap<Place> wrapper = this.handlerWrapper(null, params);
|
|
|
LbqWrapper<Place> lbqWrapper = wrapper.lambda();
|
|
|
lbqWrapper.like(Place::getPlcName, model.getPlcName());
|
|
@@ -70,68 +80,104 @@ public class PlaceController extends SuperController<PlaceService, Long, Place,
|
|
|
lbqWrapper.eq(Place::getPlcAid, model.getPlcAid());
|
|
|
lbqWrapper.eq(Place::getPlcCid, model.getPlcCid());
|
|
|
baseService.page(page, wrapper);
|
|
|
+
|
|
|
+ List<Long> regionIds = new LinkedList<>();
|
|
|
List<Place> placeList = page.getRecords();
|
|
|
- for (Place place : placeList) {
|
|
|
+ for (Place place : placeList)
|
|
|
+ {
|
|
|
String[] arr = {place.getPlcPid(), place.getPlcCid(), place.getPlcAid()};
|
|
|
place.setPlcComDesc(getPlaceComDescById(place.getCreateUser()));
|
|
|
place.setSelectedOptions(arr);
|
|
|
+
|
|
|
+ if (null != place.getRegionId())
|
|
|
+ {
|
|
|
+ regionIds.add(place.getRegionId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 补充所属区域属性
|
|
|
+ if (regionIds.size() > 0)
|
|
|
+ {
|
|
|
+ Map<Long, String> names = dictionaryItemMapper.selectBatchIds(regionIds).stream()
|
|
|
+ .collect(Collectors.toMap(DictionaryItem::getId, DictionaryItem::getName));
|
|
|
+
|
|
|
+ placeList.forEach(p -> p.setRegion(names.getOrDefault(p.getRegionId(), "")));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* Excel导入后的操作
|
|
|
*
|
|
|
- * @param list
|
|
|
+ * @param list 导入数据
|
|
|
*/
|
|
|
@Override
|
|
|
- public R<Boolean> handlerImport(List<Map<String, String>> list) {
|
|
|
- List<Place> placeList = list.stream().map((map) -> {
|
|
|
+ public R<Boolean> handlerImport(List<Map<String, String>> list)
|
|
|
+ {
|
|
|
+ List<Place> placeList = list.stream()
|
|
|
+ .map((map) ->
|
|
|
+ {
|
|
|
Place place = Place.builder().build();
|
|
|
//TODO 请在这里完成转换
|
|
|
return place;
|
|
|
- }).collect(Collectors.toList());
|
|
|
+ })
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
|
|
return R.success(baseService.saveBatch(placeList));
|
|
|
}
|
|
|
|
|
|
- @ApiOperation(value = "查询所有场地", notes = "查询所有场地")
|
|
|
@GetMapping("/getAll")
|
|
|
- public R<List<Place>> getAll(@RequestParam(value = "id", required = false) Long id) {
|
|
|
+ @ApiOperation(value = "查询所有场地", notes = "查询所有场地")
|
|
|
+ public R<List<Place>> getAll(@RequestParam(value = "id", required = false) Long id)
|
|
|
+ {
|
|
|
return R.success(baseService.getAll(id));
|
|
|
}
|
|
|
|
|
|
- private String getPlaceComDescById(long userId) {
|
|
|
+ private String getPlaceComDescById(long userId)
|
|
|
+ {
|
|
|
String comDesc = "";
|
|
|
User user = userService.getById(userId);
|
|
|
- if(user == null){
|
|
|
+ if (user == null)
|
|
|
+ {
|
|
|
return comDesc;
|
|
|
}
|
|
|
+
|
|
|
Org org = orgService.getById(user.getOrg().getKey());
|
|
|
- if(org == null){
|
|
|
+ if (org == null)
|
|
|
+ {
|
|
|
return comDesc;
|
|
|
}
|
|
|
+
|
|
|
String treePath = org.getTreePath();
|
|
|
String[] treeArray = treePath.split(",");
|
|
|
- if (treeArray != null) {
|
|
|
- if (treeArray.length == 0) {
|
|
|
+ if (treeArray != null)
|
|
|
+ {
|
|
|
+ if (treeArray.length == 0)
|
|
|
+ {
|
|
|
comDesc = org.getLabel();
|
|
|
- } else if (treeArray.length == 2) {
|
|
|
- if (org.getLabel().contains("分管")) {
|
|
|
+ }
|
|
|
+ else if (treeArray.length == 2)
|
|
|
+ {
|
|
|
+ if (org.getLabel().contains("分管"))
|
|
|
+ {
|
|
|
Org parentOrg = orgService.getById(org.getParentId());
|
|
|
comDesc = parentOrg.getLabel();
|
|
|
- } else {
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
comDesc = org.getLabel();
|
|
|
}
|
|
|
-
|
|
|
- } else if (treeArray.length > 2) {
|
|
|
+ }
|
|
|
+ else if (treeArray.length > 2)
|
|
|
+ {
|
|
|
String pOrgId = treeArray[2];
|
|
|
- if (StringUtils.isNotEmpty(pOrgId)) {
|
|
|
+ if (StringUtils.isNotEmpty(pOrgId))
|
|
|
+ {
|
|
|
Org parentOrg = orgService.getById(Long.parseLong(pOrgId));
|
|
|
comDesc = parentOrg.getLabel();
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
return comDesc;
|
|
|
}
|
|
|
-}
|
|
|
+}
|