|
@@ -0,0 +1,94 @@
|
|
|
+package cn.com.ty.lift.system.region.controller;
|
|
|
+
|
|
|
+import cn.com.ty.lift.common.model.AreaCode;
|
|
|
+import cn.com.ty.lift.system.region.dao.entity.Region;
|
|
|
+import cn.com.ty.lift.system.region.dao.entity.model.RegionReq;
|
|
|
+import cn.com.ty.lift.system.region.service.impl.RegionServiceImpl;
|
|
|
+import cn.com.ty.lift.system.user.service.impl.AreaCodeService;
|
|
|
+import cn.com.xwy.boot.web.dto.RestResponse;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import lombok.AllArgsConstructor;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+/**
|
|
|
+ * <p>
|
|
|
+ * 区域表 前端控制器
|
|
|
+ * </p>
|
|
|
+ *
|
|
|
+ * @author wang-hai-cheng
|
|
|
+ * @since 2019-12-09
|
|
|
+ */
|
|
|
+@AllArgsConstructor
|
|
|
+@RestController
|
|
|
+@RequestMapping("/region")
|
|
|
+public class RegionController {
|
|
|
+ private final RegionServiceImpl regionService;
|
|
|
+ private final AreaCodeService areaCodeService;
|
|
|
+
|
|
|
+ @PostMapping("/list")
|
|
|
+ public RestResponse list(@RequestBody RegionReq regionReq) {
|
|
|
+ IPage<Region> page = regionService.page(new Page<>(regionReq.getPageNum(), regionReq.getPageSize()));
|
|
|
+ if (page.getRecords().isEmpty()) {
|
|
|
+ return RestResponse.ok(null, "9", "无数据");
|
|
|
+ }
|
|
|
+ return RestResponse.ok(page, "1", "查询成功");
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/add")
|
|
|
+ public RestResponse add(@RequestBody Region region) {
|
|
|
+ if (regionService.save(region)) {
|
|
|
+ return RestResponse.ok(null, "1", "新增成功");
|
|
|
+ }
|
|
|
+ return RestResponse.ok(null, "0", "新增失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/delete")
|
|
|
+ public RestResponse delete(@RequestBody Region region) {
|
|
|
+ if (regionService.removeById(region.getId())) {
|
|
|
+ return RestResponse.ok(null, "1", "删除成功");
|
|
|
+ }
|
|
|
+ return RestResponse.ok(null, "0", "删除失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/update")
|
|
|
+ public RestResponse update(@RequestBody Region region) {
|
|
|
+ if (regionService.updateById(region)) {
|
|
|
+ return RestResponse.ok(null, "1", "修改成功");
|
|
|
+ }
|
|
|
+ return RestResponse.ok(null, "0", "修改失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping
|
|
|
+ public RestResponse get(@RequestBody Region region) {
|
|
|
+ Region byId = regionService.getById(region.getId());
|
|
|
+ if (null == byId) {
|
|
|
+ return RestResponse.ok(null, "9", "未找到");
|
|
|
+ }
|
|
|
+ return RestResponse.ok(byId, "1", "查询成功");
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/project/regions")
|
|
|
+ public RestResponse regions(@RequestBody Region region) {
|
|
|
+ List<Region> regions = regionService.list(new QueryWrapper<Region>()
|
|
|
+ .eq("mt_company_id", region.getMtCompanyId()));
|
|
|
+ if (regions.isEmpty()) {
|
|
|
+ return RestResponse.ok(null, "9", "无数据");
|
|
|
+ }
|
|
|
+ return RestResponse.ok(regions, "1", "查询成功");
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/project/areas")
|
|
|
+ public RestResponse areas(@RequestBody AreaCode areaCode) {
|
|
|
+ List<AreaCode> areaCodes = areaCodeService.list(new QueryWrapper<AreaCode>()
|
|
|
+ .eq("parent", areaCode.getParent())
|
|
|
+ .eq("level", 3));
|
|
|
+ if (areaCodes.isEmpty()) {
|
|
|
+ return RestResponse.ok(null, "9", "无数据");
|
|
|
+ }
|
|
|
+ return RestResponse.ok(areaCodes, "1", "查询成功");
|
|
|
+ }
|
|
|
+}
|