|
@@ -2,14 +2,13 @@ package com.huimv.farm.damsubsidy.controller;
|
|
|
|
|
|
import com.huimv.farm.damsubsidy.common.utils.AreaUtil;
|
|
import com.huimv.farm.damsubsidy.common.utils.AreaUtil;
|
|
import com.huimv.farm.damsubsidy.common.utils.Result;
|
|
import com.huimv.farm.damsubsidy.common.utils.Result;
|
|
-import com.huimv.farm.damsubsidy.common.utils.ResultCode;
|
|
|
|
|
|
+import com.huimv.farm.damsubsidy.entity.AreaAll;
|
|
import com.huimv.farm.damsubsidy.service.IAreaByLevelService;
|
|
import com.huimv.farm.damsubsidy.service.IAreaByLevelService;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.web.bind.annotation.*;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
-import java.util.Arrays;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
-import java.util.Map;
|
|
|
|
|
|
|
|
|
|
|
|
// Author: Tinger-XXX
|
|
// Author: Tinger-XXX
|
|
@@ -18,40 +17,91 @@ import java.util.Map;
|
|
@RequestMapping("/area")
|
|
@RequestMapping("/area")
|
|
public class AreaByLevelController {
|
|
public class AreaByLevelController {
|
|
@Autowired
|
|
@Autowired
|
|
- private IAreaByLevelService areaByLevelService;
|
|
|
|
-
|
|
|
|
- private final List<Integer> idLengths = Arrays.asList(2, 4, 6, 9, 12);
|
|
|
|
|
|
+ private IAreaByLevelService service;
|
|
|
|
|
|
@GetMapping("/types")
|
|
@GetMapping("/types")
|
|
public Result listTypes() {
|
|
public Result listTypes() {
|
|
- return areaByLevelService.listTypes();
|
|
|
|
|
|
+ return service.listTypes();
|
|
}
|
|
}
|
|
|
|
|
|
@GetMapping("/levels")
|
|
@GetMapping("/levels")
|
|
public Result listLevels() {
|
|
public Result listLevels() {
|
|
- return areaByLevelService.listLevels();
|
|
|
|
|
|
+ return service.listLevels();
|
|
}
|
|
}
|
|
|
|
|
|
@GetMapping("/info")
|
|
@GetMapping("/info")
|
|
public Result getInfo() {
|
|
public Result getInfo() {
|
|
- return areaByLevelService.getInfo();
|
|
|
|
|
|
+ return service.getInfo();
|
|
}
|
|
}
|
|
|
|
|
|
@GetMapping("/provinces")
|
|
@GetMapping("/provinces")
|
|
public Result listProvinces() {
|
|
public Result listProvinces() {
|
|
- return areaByLevelService.listProvinces();
|
|
|
|
|
|
+ return service.listProvinces();
|
|
}
|
|
}
|
|
|
|
|
|
@PostMapping("/children_of")
|
|
@PostMapping("/children_of")
|
|
- public Result listChildrenOf(@RequestBody Map<String, String> map) {
|
|
|
|
- String curId = map.get("cur_id"), child = map.get("child");
|
|
|
|
|
|
+ public Result listChildrenOf(@RequestBody AreaAll cur) {
|
|
|
|
+ String curId = cur.getId(), child = cur.getChild();
|
|
if (curId == null || child == null)
|
|
if (curId == null || child == null)
|
|
return new Result(10002, "key param lost", false);
|
|
return new Result(10002, "key param lost", false);
|
|
- boolean include = AreaUtil.include(idLengths, curId.length());
|
|
|
|
- if (!include || child.length() != 2)
|
|
|
|
|
|
+ if (AreaUtil.isNotIn(curId.length(), AreaUtil.idLengths) || child.length() != 2)
|
|
return new Result(10002, "error params", false);
|
|
return new Result(10002, "error params", false);
|
|
|
|
|
|
if (curId.length() == 12) return new Result(10002, "no more children", false);
|
|
if (curId.length() == 12) return new Result(10002, "no more children", false);
|
|
- return areaByLevelService.listChildrenOf(curId, child);
|
|
|
|
|
|
+ return service.listChildrenOf(curId, child);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @PostMapping("/add")
|
|
|
|
+ public Result addArea(@RequestBody AreaAll record) {
|
|
|
|
+ if (AreaUtil.isError(record))
|
|
|
|
+ return new Result(10002, "参数错误,添加失败", false);
|
|
|
|
+ return service.insert(record);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @PostMapping("/add_batch")
|
|
|
|
+ public Result addAreaBatch(@RequestBody List<AreaAll> records) {
|
|
|
|
+ ArrayList<String> errId = new ArrayList<>();
|
|
|
|
+ for (AreaAll one: records) if (AreaUtil.isError(one)) errId.add(one.getId());
|
|
|
|
+
|
|
|
|
+ if (errId.size() > 0)
|
|
|
|
+ return new Result(10002, "操作未执行,以下id数据不规范:" + errId, false);
|
|
|
|
+
|
|
|
|
+ return service.insert(records);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @PostMapping("/remove")
|
|
|
|
+ public Result removeArea(@RequestBody AreaAll one) {
|
|
|
|
+ String id = one.getId();
|
|
|
|
+ if (AreaUtil.isNotIn(id.length(), AreaUtil.idLengths))
|
|
|
|
+ return new Result(10002, "参数错误,删除失败", false);
|
|
|
|
+ return service.delete(id);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @PostMapping("/remove_batch")
|
|
|
|
+ public Result removeAreaBatch(@RequestBody List<String> ids) {
|
|
|
|
+ ArrayList<String> errId = new ArrayList<>();
|
|
|
|
+ for (String id: ids) if (AreaUtil.isNotIn(id.length(), AreaUtil.idLengths)) errId.add(id);
|
|
|
|
+
|
|
|
|
+ if (errId.size() > 0)
|
|
|
|
+ return new Result(10002, "操作未执行,以下id不规范:" + errId, false);
|
|
|
|
+
|
|
|
|
+ return service.delete(ids);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @PostMapping("/update")
|
|
|
|
+ public Result updateArea(@RequestBody AreaAll one) {
|
|
|
|
+ if (AreaUtil.isError(one))
|
|
|
|
+ return new Result(10002, "参数错误,更新失败", false);
|
|
|
|
+ return service.update(one);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @PostMapping("/update_batch")
|
|
|
|
+ public Result updateArea(@RequestBody List<AreaAll> records) {
|
|
|
|
+ ArrayList<String> errId = new ArrayList<>();
|
|
|
|
+ for (AreaAll one: records) if (AreaUtil.isError(one)) errId.add(one.getId());
|
|
|
|
+
|
|
|
|
+ if (errId.size() > 0)
|
|
|
|
+ return new Result(10002, "操作未执行,以下id数据不规范:" + errId, false);
|
|
|
|
+ return service.update(records);
|
|
}
|
|
}
|
|
}
|
|
}
|