Commit dac3a5dc authored by 赵啸非's avatar 赵啸非

修改区域批量更新

parent 00f6d931
...@@ -29,6 +29,6 @@ public interface BaseAreaService extends ICRUDService<BaseAreaEntity, Long> { ...@@ -29,6 +29,6 @@ public interface BaseAreaService extends ICRUDService<BaseAreaEntity, Long> {
Rest<List<String>> getSubAreaByRootName(BaseAreaEntity baseAreaEntity, Context context); Rest<List<String>> getSubAreaByRootName(BaseAreaEntity baseAreaEntity, Context context);
Rest<Void> updateArea(BaseAreaEntity baseAreaEntity, Context context); Rest<Void> updateArea(BaseAreaEntity baseAreaEntity,List<BaseAreaEntity> list, Context context);
} }
\ No newline at end of file
...@@ -25,6 +25,7 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -25,6 +25,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils; import org.springframework.util.ObjectUtils;
import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
...@@ -95,32 +96,33 @@ public class BaseAreaServiceImpl extends AbstractCRUDServiceImpl<BaseAreaDao, Ba ...@@ -95,32 +96,33 @@ public class BaseAreaServiceImpl extends AbstractCRUDServiceImpl<BaseAreaDao, Ba
@Override @Override
public Rest<Void> updateArea(BaseAreaEntity baseAreaEntity, Context context) { public Rest<Void> updateArea(BaseAreaEntity baseAreaEntity,List<BaseAreaEntity> list, Context context) {
//https://www.sczwfw.gov.cn/jiq/interface/jitem/find-by-code?code=510000000000&deptType=1&jsonpCallback=jsonpcallback&_=1747020251031 //https://www.sczwfw.gov.cn/jiq/interface/jitem/find-by-code?code=510000000000&deptType=1&jsonpCallback=jsonpcallback&_=1747020251031
//todo 更新四川区域数据 //todo 更新四川区域数据
String url = "https://www.sczwfw.gov.cn/jiq/interface/jitem/find-by-code?code=" + baseAreaEntity.getAreaCode() + "&deptType=1&jsonpCallback=jsonpcallback&_=1747020251031"; String url = "https://www.sczwfw.gov.cn/jiq/interface/jitem/find-by-code?code=" + baseAreaEntity.getAreaCode() + "&deptType=1&jsonpCallback=jsonpcallback&_=1747020251031";
String rest = HttpUtil.get(url); String rest = HttpUtil.get(url);
rest = StrUtil.subBetween(rest, "jsonpcallback(", ")"); rest = StrUtil.subBetween(rest, "jsonpcallback(", ")");
Rest<RootAreaInfo> ret = JSON.parseObject(rest, new TypeReference<Rest<RootAreaInfo>>() { Rest<RootAreaInfo> ret = JSON.parseObject(rest, new TypeReference<Rest<RootAreaInfo>>() {
}); });
if (200 == ret.getCode()) { if (200 == ret.getCode()) {
GroupAreaInfo group = ret.getData().getGroup(); GroupAreaInfo group = ret.getData().getGroup();
//查询当前group是否存在 存在 更新数据 //查询当前group是否存在 存在 更新数据
BaseAreaQuery baseAreaQuery = new BaseAreaQuery(); BaseAreaQuery baseAreaQuery = new BaseAreaQuery();
baseAreaQuery.setAreaCode(group.getAreaCode()); baseAreaQuery.setAreaCode(group.getAreaCode());
updateAndSaveEntity(baseAreaQuery, group); BaseAreaEntity entity = updateAndSaveEntity(baseAreaQuery, group);
list.add(entity);
List<GroupAreaInfo> sonAreas = group.getSonAreas(); List<GroupAreaInfo> sonAreas = group.getSonAreas();
for (GroupAreaInfo sonArea : sonAreas) { for (GroupAreaInfo sonArea : sonAreas) {
// //
baseAreaQuery = new BaseAreaQuery(); baseAreaQuery = new BaseAreaQuery();
baseAreaQuery.setAreaCode(sonArea.getAreaCode()); baseAreaQuery.setAreaCode(sonArea.getAreaCode());
updateAndSaveEntity(baseAreaQuery, sonArea); entity = updateAndSaveEntity(baseAreaQuery, sonArea);
list.add(entity);
updateArea(new BaseAreaQuery().areaCode(sonArea.getAreaCode()), context); updateArea(new BaseAreaQuery().areaCode(sonArea.getAreaCode()),list, context);
} }
} }
...@@ -128,15 +130,13 @@ public class BaseAreaServiceImpl extends AbstractCRUDServiceImpl<BaseAreaDao, Ba ...@@ -128,15 +130,13 @@ public class BaseAreaServiceImpl extends AbstractCRUDServiceImpl<BaseAreaDao, Ba
return Rest.ok(); return Rest.ok();
} }
private void updateAndSaveEntity(BaseAreaQuery baseAreaQuery, GroupAreaInfo group) { private BaseAreaEntity updateAndSaveEntity(BaseAreaQuery baseAreaQuery, GroupAreaInfo group) {
BaseAreaEntity entity = this.selectOne(baseAreaQuery); BaseAreaEntity entity = this.selectOne(baseAreaQuery);
if (ObjectUtils.isEmpty(entity)) { if (ObjectUtils.isEmpty(entity)) {
//新增 //新增
entity = new BaseAreaEntity(); entity = new BaseAreaEntity();
entity.initAttrValue(); entity.initAttrValue();
BeanUtils.copyProperties(group, entity, BeanUtil.getNullPropertyNames(group)); BeanUtils.copyProperties(group, entity, BeanUtil.getNullPropertyNames(group));
entity.setName(group.getShortName()); entity.setName(group.getShortName());
entity.setCreateTime(new Date()); entity.setCreateTime(new Date());
...@@ -144,13 +144,15 @@ public class BaseAreaServiceImpl extends AbstractCRUDServiceImpl<BaseAreaDao, Ba ...@@ -144,13 +144,15 @@ public class BaseAreaServiceImpl extends AbstractCRUDServiceImpl<BaseAreaDao, Ba
entity.setUpdateTime(new Date()); entity.setUpdateTime(new Date());
entity.setStatus(1); entity.setStatus(1);
//log.info("新增数据:{}", JSON.toJSONString(group)); //log.info("新增数据:{}", JSON.toJSONString(group));
this.save(entity); //this.save(entity);
} else { } else {
//更新 //更新
BeanUtils.copyProperties(group, entity, BeanUtil.getNullPropertyNames(group)); BeanUtils.copyProperties(group, entity, BeanUtil.getNullPropertyNames(group));
entity.setUpdateTime(new Date()); entity.setUpdateTime(new Date());
this.update(entity); // this.update(entity);
} }
return entity;
} }
......
package com.mortals.xhx.module.base.web; package com.mortals.xhx.module.base.web;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Lists;
import com.mortals.framework.annotation.UnAuth; import com.mortals.framework.annotation.UnAuth;
import com.mortals.framework.common.Rest; import com.mortals.framework.common.Rest;
import com.mortals.framework.exception.AppException; import com.mortals.framework.exception.AppException;
...@@ -21,7 +22,10 @@ import org.springframework.web.bind.annotation.RequestBody; ...@@ -21,7 +22,10 @@ import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import java.util.ArrayList;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors;
/** /**
* 区域 * 区域
...@@ -113,7 +117,18 @@ public class BaseAreaController extends BaseCRUDJsonBodyMappingController<BaseAr ...@@ -113,7 +117,18 @@ public class BaseAreaController extends BaseCRUDJsonBodyMappingController<BaseAr
} }
new Thread(() -> { new Thread(() -> {
this.service.updateArea(areaQuery, getContext()); List<BaseAreaEntity> list = new ArrayList<>();
this.service.updateArea(areaQuery, list, getContext());
Map<Boolean, List<BaseAreaEntity>> collect = list.stream().collect(Collectors.partitioningBy(x -> x.getId() == null));
List<BaseAreaEntity> saveList = collect.get(true);
if (!ObjectUtils.isEmpty(saveList)) {
Lists.partition(saveList, 100).forEach(item -> this.service.save(item));
}
List<BaseAreaEntity> updateList = collect.get(false);
if (!ObjectUtils.isEmpty(updateList)) {
Lists.partition(updateList, 100).forEach(item -> this.service.update(item));
}
}).start(); }).start();
//编码优先 //编码优先
......
...@@ -67,7 +67,7 @@ ...@@ -67,7 +67,7 @@
a.domain, a.domain,
</if> </if>
<if test="(data == null) or (data != null and ( colPickMode == 0 and !data.containsKey('status') or colPickMode == 1 and data.containsKey('status')))"> <if test="(data == null) or (data != null and ( colPickMode == 0 and !data.containsKey('status') or colPickMode == 1 and data.containsKey('status')))">
a.status, a.`status`,
</if> </if>
<if test="(data == null) or (data != null and ( colPickMode == 0 and !data.containsKey('createTime') or colPickMode == 1 and data.containsKey('createTime')))"> <if test="(data == null) or (data != null and ( colPickMode == 0 and !data.containsKey('createTime') or colPickMode == 1 and data.containsKey('createTime')))">
a.createTime, a.createTime,
......
...@@ -67,7 +67,7 @@ Content-Type: application/json ...@@ -67,7 +67,7 @@ Content-Type: application/json
POST {{baseUrl}}/base/area/updateBaseArea POST {{baseUrl}}/base/area/updateBaseArea
Content-Type: application/json Content-Type: application/json
{"areaCode": "510000000000"} {"areaCode": "511700000000"}
###controoler 测试 ###controoler 测试
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment