|
@@ -7,10 +7,13 @@ import cn.com.ty.lift.enterprise.common.mapper.CommonMapper;
|
|
|
import cn.com.ty.lift.enterprise.region.dao.mapper.RegionMapper;
|
|
|
import cn.com.ty.lift.enterprise.region.service.RegionService;
|
|
|
import cn.com.xwy.boot.web.dto.RestResponse;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
@@ -27,29 +30,37 @@ import java.util.Map;
|
|
|
public class RegionServiceImpl extends ServiceImpl<RegionMapper, Region> implements RegionService {
|
|
|
private final CommonMapper mapper;
|
|
|
|
|
|
- public RestResponse regions(RegionReq regionReq) {
|
|
|
- long pageNum = regionReq.getPageNum() * regionReq.getPageSize() - 2;
|
|
|
- long pageSize = regionReq.getPageSize();
|
|
|
+ //分页区域列表
|
|
|
+ public RestResponse regions(RegionReq req) {
|
|
|
+ long pageNum = (req.getPageNum() - 1) * req.getPageSize();
|
|
|
+ long pageSize = req.getPageSize();
|
|
|
+ Page<Map<String, Object>> page = new Page<>(req.getPageNum(), req.getPageSize());
|
|
|
//获取维保团队的区域列表
|
|
|
List<Map<String, Object>> regions = mapper.list(
|
|
|
- "r.id, r.area_code, r.province_code, r.city_code, 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() + " limit " + pageNum + "," + pageSize);
|
|
|
- List<Map<String, Object>> projects = mapper.list("region_id,num", "project", "");
|
|
|
- List<Map<String, Object>> area_code = mapper.list("code,name", "area_code", "");
|
|
|
- int count = 0;
|
|
|
+ "r.id, r.area_code areaCode, r.province_code provinceCode, r.city_code cityCode, r.area_name areaName, r.remark, u.name",
|
|
|
+ "region r left join user_info u on r.user_id = u.user_id",
|
|
|
+ "where r.mt_company_id =" + req.getMtCompanyId() + " limit " + pageNum + "," + pageSize);
|
|
|
+ //如果没有区域
|
|
|
+ if (regions.isEmpty()) {
|
|
|
+ return RestResponse.ok(null, ApiConstants.RESULT_NO_DATA, "无数据");
|
|
|
+ }
|
|
|
+ List<Map<String, Object>> projects = mapper
|
|
|
+ .list("region_id,num", "project", "");
|
|
|
+ List<Map<String, Object>> area_code = mapper
|
|
|
+ .list("code,name", "area_code", "");
|
|
|
+ int projectNum = 0;
|
|
|
Integer num = 0;
|
|
|
//遍历区域列表
|
|
|
if (regions.isEmpty()) {
|
|
|
- return RestResponse.ok(null,ApiConstants.RESULT_NO_DATA,"无数据");
|
|
|
+ return RestResponse.ok(null, ApiConstants.RESULT_NO_DATA, "无数据");
|
|
|
}
|
|
|
for (Map<String, Object> region : regions) {
|
|
|
//遍历省市列表,将省市的id转化为name
|
|
|
for (Map<String, Object> area : area_code) {
|
|
|
- if (region.get("province_code").equals(area.get("code"))) {
|
|
|
+ if (region.get("provinceCode").equals(area.get("code"))) {
|
|
|
region.put("provinceName", area.get("name"));
|
|
|
}
|
|
|
- if (region.get("city_code").equals(area.get("code"))) {
|
|
|
+ if (region.get("cityCode").equals(area.get("code"))) {
|
|
|
region.put("cityName", area.get("name"));
|
|
|
}
|
|
|
}
|
|
@@ -58,29 +69,29 @@ public class RegionServiceImpl extends ServiceImpl<RegionMapper, Region> impleme
|
|
|
Object id = region.get("id");
|
|
|
for (Map<String, Object> project : projects) {
|
|
|
if (project.get("region_id").equals(id)) {
|
|
|
- count += 1;
|
|
|
+ projectNum += 1;
|
|
|
num += (Integer) project.get("num");
|
|
|
}
|
|
|
}
|
|
|
- region.put("project_num", count);
|
|
|
+ region.put("project_num", projectNum);
|
|
|
region.put("num", num);
|
|
|
- count = 0;
|
|
|
+ projectNum = 0;
|
|
|
num = 0;
|
|
|
}
|
|
|
-
|
|
|
+ //设置分页对象的属性
|
|
|
+ int count = this.getBaseMapper().selectCount(new QueryWrapper<Region>()
|
|
|
+ .eq("mt_company_id", req.getMtCompanyId()));
|
|
|
+ page.setRecords(regions);
|
|
|
+ page.setTotal(count);
|
|
|
+ page.setPages(count / pageSize);
|
|
|
//封装分页
|
|
|
//待完成
|
|
|
-
|
|
|
- System.out.println(regions);
|
|
|
- if (regions.isEmpty()) {
|
|
|
- return RestResponse.ok(null, ApiConstants.RESULT_NO_DATA, "无数据");
|
|
|
- }
|
|
|
- return RestResponse.ok(regions, ApiConstants.RESULT_SUCCESS, "查询成功");
|
|
|
+ return RestResponse.ok(page, ApiConstants.RESULT_SUCCESS, "查询成功");
|
|
|
}
|
|
|
|
|
|
public RestResponse delete(Region region) {
|
|
|
Map<String, Object> regionId = mapper.one("count(id) count", "project", "where region_id=" + region.getId());
|
|
|
- if ( regionId.get("count").equals(0L)) {
|
|
|
+ if (regionId.get("count").equals(0L)) {
|
|
|
if (this.removeById(region.getId())) {
|
|
|
return RestResponse.ok(null, ApiConstants.RESULT_SUCCESS, "删除成功");
|
|
|
}
|