|
@@ -1,95 +1,129 @@
|
|
|
-//package cn.com.ty.lift.system.region.controller;
|
|
|
-//
|
|
|
-//import cn.com.ty.lift.common.constants.ApiConstants;
|
|
|
-//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()) {
|
|
|
+package cn.com.ty.lift.system.region.controller;
|
|
|
+
|
|
|
+import cn.com.ty.lift.common.constants.ApiConstants;
|
|
|
+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.dao.mapper.CommonMapper;
|
|
|
+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.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+/**
|
|
|
+ * <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;
|
|
|
+ private final CommonMapper mapper;
|
|
|
+
|
|
|
+
|
|
|
+ @PostMapping("/list")
|
|
|
+ public RestResponse list(@RequestBody RegionReq regionReq) {
|
|
|
+ long current = regionReq.getPageNum() * regionReq.getPageSize() - 1;
|
|
|
+ List<Map<String, Object>> list = mapper.list(
|
|
|
+ "r.id, r.area_code, r.province_code, a.name cityName, r.area_name, r.remark, u.name",
|
|
|
+ "region r left join user_info u on r.user_id = u.user_id left join area_code a on r.city_code = a.code left join area_code on r.province_code = a.name",
|
|
|
+ "where r.mt_company_id =" + regionReq.getMtCompanyId());
|
|
|
+ List<Map<String, Object>> projects = mapper.list("region_id,num", "project", "");
|
|
|
+ int count = 0;
|
|
|
+ Integer num = 0;
|
|
|
+ for (int i = 0; i < list.size(); i++) {
|
|
|
+ Object id = list.get(i).get("id");
|
|
|
+ for (int j = 0; j < projects.size(); j++) {
|
|
|
+// System.out.println("================"+projects.get(i).get("region_id"));
|
|
|
+// System.out.println("================"+list.get(j).get("id"));
|
|
|
+ if (projects.get(j).get("region_id").equals(id)) {
|
|
|
+ count += 1;
|
|
|
+ }
|
|
|
+// num += projects.get(j).get("num");
|
|
|
+ //
|
|
|
+ //
|
|
|
+ //
|
|
|
+ //
|
|
|
+ //
|
|
|
+ }
|
|
|
+ list.get(i).put("project_num", count);
|
|
|
+ count = 0;
|
|
|
+ num = 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ System.out.println(list);
|
|
|
+ // if (page.getRecords().isEmpty()) {
|
|
|
// return RestResponse.ok(null, ApiConstants.RESULT_NO_DATA, "无数据");
|
|
|
// }
|
|
|
// return RestResponse.ok(page, ApiConstants.RESULT_SUCCESS, "查询成功");
|
|
|
-// }
|
|
|
-//
|
|
|
-// @PostMapping("/add")
|
|
|
-// public RestResponse add(@RequestBody Region region) {
|
|
|
-// if (regionService.save(region)) {
|
|
|
-// return RestResponse.ok(null, ApiConstants.RESULT_SUCCESS, "新增成功");
|
|
|
-// }
|
|
|
-// return RestResponse.ok(null, ApiConstants.RESULT_ERROR, "新增失败");
|
|
|
-// }
|
|
|
-//
|
|
|
-// @PostMapping("/delete")
|
|
|
-// public RestResponse delete(@RequestBody Region region) {
|
|
|
-// if (regionService.removeById(region.getId())) {
|
|
|
-// return RestResponse.ok(null, ApiConstants.RESULT_SUCCESS, "删除成功");
|
|
|
-// }
|
|
|
-// return RestResponse.ok(null, ApiConstants.RESULT_ERROR, "删除失败");
|
|
|
-// }
|
|
|
-//
|
|
|
-// @PostMapping("/update")
|
|
|
-// public RestResponse update(@RequestBody Region region) {
|
|
|
-// if (regionService.updateById(region)) {
|
|
|
-// return RestResponse.ok(null, ApiConstants.RESULT_SUCCESS, "修改成功");
|
|
|
-// }
|
|
|
-// return RestResponse.ok(null, ApiConstants.RESULT_ERROR, "修改失败");
|
|
|
-// }
|
|
|
-//
|
|
|
-// @PostMapping
|
|
|
-// public RestResponse get(@RequestBody Region region) {
|
|
|
-// Region byId = regionService.getById(region.getId());
|
|
|
-// if (null == byId) {
|
|
|
-// return RestResponse.ok(null, ApiConstants.RESULT_NO_DATA, "未找到");
|
|
|
-// }
|
|
|
-// return RestResponse.ok(byId, ApiConstants.RESULT_SUCCESS, "查询成功");
|
|
|
-// }
|
|
|
-//
|
|
|
-// @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, ApiConstants.RESULT_NO_DATA, "无数据");
|
|
|
-// }
|
|
|
-// return RestResponse.ok(regions, ApiConstants.RESULT_SUCCESS, "查询成功");
|
|
|
-// }
|
|
|
-//
|
|
|
-// @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, ApiConstants.RESULT_NO_DATA, "无数据");
|
|
|
-// }
|
|
|
-// return RestResponse.ok(areaCodes, ApiConstants.RESULT_SUCCESS, "查询成功");
|
|
|
-// }
|
|
|
-//}
|
|
|
+ return RestResponse.ok(null, "", "");
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/add")
|
|
|
+ public RestResponse add(@RequestBody Region region) {
|
|
|
+ if (regionService.save(region)) {
|
|
|
+ return RestResponse.ok(null, ApiConstants.RESULT_SUCCESS, "新增成功");
|
|
|
+ }
|
|
|
+ return RestResponse.ok(null, ApiConstants.RESULT_ERROR, "新增失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/delete")
|
|
|
+ public RestResponse delete(@RequestBody Region region) {
|
|
|
+ if (regionService.removeById(region.getId())) {
|
|
|
+ return RestResponse.ok(null, ApiConstants.RESULT_SUCCESS, "删除成功");
|
|
|
+ }
|
|
|
+ return RestResponse.ok(null, ApiConstants.RESULT_ERROR, "删除失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/update")
|
|
|
+ public RestResponse update(@RequestBody Region region) {
|
|
|
+ if (regionService.updateById(region)) {
|
|
|
+ return RestResponse.ok(null, ApiConstants.RESULT_SUCCESS, "修改成功");
|
|
|
+ }
|
|
|
+ return RestResponse.ok(null, ApiConstants.RESULT_ERROR, "修改失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping
|
|
|
+ public RestResponse get(@RequestBody Region region) {
|
|
|
+ Region byId = regionService.getById(region.getId());
|
|
|
+ if (null == byId) {
|
|
|
+ return RestResponse.ok(null, ApiConstants.RESULT_NO_DATA, "未找到");
|
|
|
+ }
|
|
|
+ return RestResponse.ok(byId, ApiConstants.RESULT_SUCCESS, "查询成功");
|
|
|
+ }
|
|
|
+
|
|
|
+ @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, ApiConstants.RESULT_NO_DATA, "无数据");
|
|
|
+ }
|
|
|
+ return RestResponse.ok(regions, ApiConstants.RESULT_SUCCESS, "查询成功");
|
|
|
+ }
|
|
|
+
|
|
|
+ @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, ApiConstants.RESULT_NO_DATA, "无数据");
|
|
|
+ }
|
|
|
+ return RestResponse.ok(areaCodes, ApiConstants.RESULT_SUCCESS, "查询成功");
|
|
|
+ }
|
|
|
+}
|