Commit 3438b077 authored by 赵啸非's avatar 赵啸非

添加更新基础区域

parent 6b9f2ddc
package com.mortals.xhx.module.base.model.vo;
import lombok.Data;
import java.util.List;
@Data
public class GroupAreaInfo {
/**
* 一体化的父id
*/
private String iid;
/**
* 一体化的父id
*/
private String pid;
/**
* 是否有下级区域(True.是,False.否)
*/
private String haveSonArea;
/**
* 是否有下级部门(True.是,False.否)
*/
private String haveSonDept;
/**
* 是否获取部门(true.是,false.否)
*/
private String haveGetDept;
/**
* 是否获取事项列表(true.是,false.否)
*/
private String haveGetMatterList;
/**
* 区域编码
*/
private String areaCode;
/**
* 区域等级(1.省,2.地市州,3.区县,4.街道,5.社区)
*/
private Integer areaLevel;
/**
* 名称简称
*/
private String shortName;
/**
* 访问地址
*/
private String domain;
/**
* 区域状态 (0.停用,1.正常)
*/
private String status;
private List<GroupAreaInfo> sonAreas;
}
package com.mortals.xhx.module.base.model.vo;
import lombok.Data;
@Data
public class RootAreaInfo {
private GroupAreaInfo group;
}
......@@ -28,4 +28,7 @@ public interface BaseAreaService extends ICRUDService<BaseAreaEntity, Long> {
Rest<List<String>> getSubAreaByRootName(BaseAreaEntity baseAreaEntity, Context context);
Rest<Void> updateArea(BaseAreaEntity baseAreaEntity, Context context);
}
\ No newline at end of file
package com.mortals.xhx.module.base.service.impl;
import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.mortals.framework.common.Rest;
import com.mortals.framework.model.Context;
import com.mortals.framework.service.impl.AbstractCRUDServiceImpl;
import com.mortals.xhx.busiz.rsp.ApiResp;
import com.mortals.xhx.common.utils.AreaMatchCodeUtil;
import com.mortals.xhx.common.utils.BeanUtil;
import com.mortals.xhx.module.area.model.AreaEntity;
......@@ -11,10 +16,13 @@ import com.mortals.xhx.module.area.service.AreaService;
import com.mortals.xhx.module.base.dao.BaseAreaDao;
import com.mortals.xhx.module.base.model.BaseAreaEntity;
import com.mortals.xhx.module.base.model.BaseAreaQuery;
import com.mortals.xhx.module.base.model.vo.GroupAreaInfo;
import com.mortals.xhx.module.base.model.vo.RootAreaInfo;
import com.mortals.xhx.module.base.service.BaseAreaService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import java.util.List;
import java.util.stream.Collectors;
......@@ -31,6 +39,7 @@ public class BaseAreaServiceImpl extends AbstractCRUDServiceImpl<BaseAreaDao, Ba
@Autowired
private AreaService areaService;
@Override
public Rest<String> genSubAreaByRootName(BaseAreaEntity baseAreaEntity, Context context) {
......@@ -39,20 +48,20 @@ public class BaseAreaServiceImpl extends AbstractCRUDServiceImpl<BaseAreaDao, Ba
matchCode = AreaMatchCodeUtil.getMatchCode(matchCode, baseAreaEntity.getAreaLevel());
BaseAreaQuery baseAreaQuery = new BaseAreaQuery();
baseAreaQuery.setAreaCode(matchCode + "%");
List<BaseAreaEntity> baseAreaEntityList =this.find(baseAreaQuery);
List<BaseAreaEntity> baseAreaEntityList = this.find(baseAreaQuery);
//清除子区域数据
Rest<String> rest = areaService.removeAll();
List<AreaEntity> collect = baseAreaEntityList.stream().map(item -> {
AreaEntity areaEntity = new AreaEntity();
areaEntity.initAttrValue();
BeanUtils.copyProperties(item, areaEntity,BeanUtil.getNullPropertyNames(item));
if(item.getAreaCode().equalsIgnoreCase(areaCode)){
BeanUtils.copyProperties(item, areaEntity, BeanUtil.getNullPropertyNames(item));
if (item.getAreaCode().equalsIgnoreCase(areaCode)) {
areaEntity.setPid("0");
}
return areaEntity;
}).collect(Collectors.toList());
log.info("更新数据条数:"+collect.size());
log.info("更新数据条数:" + collect.size());
List<List<AreaEntity>> partition = ListUtil.partition(collect, 100);
for (List<AreaEntity> areaEntities : partition) {
areaService.save(areaEntities, context);
......@@ -74,11 +83,77 @@ public class BaseAreaServiceImpl extends AbstractCRUDServiceImpl<BaseAreaDao, Ba
matchCode = AreaMatchCodeUtil.getMatchCode(matchCode, baseAreaEntity.getAreaLevel());
BaseAreaQuery baseAreaQuery = new BaseAreaQuery();
baseAreaQuery.setAreaCode(matchCode + "%");
List<BaseAreaEntity> baseAreaEntityList =this.find(baseAreaQuery);
List<BaseAreaEntity> baseAreaEntityList = this.find(baseAreaQuery);
List<String> areaCodeList = baseAreaEntityList.stream().map(i -> i.getAreaCode()).collect(Collectors.toList());
return Rest.ok(areaCodeList);
}
@Override
public Rest<Void> updateArea(BaseAreaEntity baseAreaEntity, Context context) {
//https://www.sczwfw.gov.cn/jiq/interface/jitem/find-by-code?code=510000000000&deptType=1&jsonpCallback=jsonpcallback&_=1747020251031
//todo 更新四川区域数据
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);
rest = StrUtil.subBetween(rest, "jsonpcallback(", ")");
Rest<RootAreaInfo> ret = JSON.parseObject(rest, new TypeReference<Rest<RootAreaInfo>>() {
});
if (200 == ret.getCode()) {
GroupAreaInfo group = ret.getData().getGroup();
//查询当前group是否存在 存在 更新数据
BaseAreaQuery baseAreaQuery = new BaseAreaQuery();
baseAreaQuery.setAreaCode(group.getAreaCode());
updateAndSaveEntity(baseAreaQuery, group);
List<GroupAreaInfo> sonAreas = group.getSonAreas();
for (GroupAreaInfo sonArea : sonAreas) {
//
baseAreaQuery = new BaseAreaQuery();
baseAreaQuery.setAreaCode(sonArea.getAreaCode());
updateAndSaveEntity(baseAreaQuery, sonArea);
updateArea(new BaseAreaQuery().areaCode(sonArea.getAreaCode()), context);
}
}
return Rest.ok();
}
private void updateAndSaveEntity(BaseAreaQuery baseAreaQuery, GroupAreaInfo group) {
BaseAreaEntity entity = this.selectOne(baseAreaQuery);
if (!ObjectUtils.isEmpty(entity)) {
//新增
entity = new BaseAreaEntity();
entity.initAttrValue();
BeanUtils.copyProperties(group, entity, BeanUtil.getNullPropertyNames(group));
this.save(entity);
} else {
//更新
BeanUtils.copyProperties(group, entity, BeanUtil.getNullPropertyNames(group));
this.update(entity);
}
}
public static void main(String[] args) {
String url = "https://www.sczwfw.gov.cn/jiq/interface/jitem/find-by-code?code=510100000000&deptType=1&jsonpCallback=jsonpcallback&_=1747020251031";
String rest = HttpUtil.get(url);
rest = StrUtil.subBetween(rest, "jsonpcallback(", ")");
System.out.println(rest);
Rest<RootAreaInfo> ret = JSON.parseObject(rest, new TypeReference<Rest<RootAreaInfo>>() {
});
System.out.println(JSON.toJSONString(ret));
}
}
\ No newline at end of file
......@@ -6,6 +6,7 @@ import com.mortals.framework.common.Rest;
import com.mortals.framework.exception.AppException;
import com.mortals.framework.model.Context;
import com.mortals.framework.service.ICacheService;
import com.mortals.framework.util.ThreadPool;
import com.mortals.framework.web.BaseCRUDJsonBodyMappingController;
import com.mortals.xhx.base.system.param.service.ParamService;
import com.mortals.xhx.common.code.YesNoEnum;
......@@ -73,7 +74,7 @@ public class BaseAreaController extends BaseCRUDJsonBodyMappingController<BaseAr
}
if (ObjectUtils.isEmpty(baseAreaEntity)) {
throw new AppException(String.format("区域数据未找到,区域名称:%s,区域编码:%s", areaQuery.getName(),areaQuery.getAreaCode()));
throw new AppException(String.format("区域数据未找到,区域名称:%s,区域编码:%s", areaQuery.getName(), areaQuery.getAreaCode()));
}
boolean bool = cacheService.setnx(RedisCacheKeys.getSyncAreaLockKey() + areaQuery.getName(), areaQuery.getName(), 60L);
if (!bool) {
......@@ -81,11 +82,11 @@ public class BaseAreaController extends BaseCRUDJsonBodyMappingController<BaseAr
}
Rest<String> rest = this.service.genSubAreaByRootName(baseAreaEntity, getContext());
if(YesNoEnum.NO.getValue()==rest.getCode()){
throw new AppException("更新子区域失败,"+rest.getMsg());
if (YesNoEnum.NO.getValue() == rest.getCode()) {
throw new AppException("更新子区域失败," + rest.getMsg());
}
// ThreadPool.getInstance().execute(new SyncSubAreaThread(this.service, baseAreaEntity, getContext()));
// ThreadPool.getInstance().execute(new SyncSubAreaThread(this.service, baseAreaEntity, getContext()));
recordSysLog(request, busiDesc + " 【成功】");
jsonObject.put(KEY_RESULT_CODE, VALUE_RESULT_SUCCESS);
jsonObject.put(KEY_RESULT_MSG, "初始同步区域数据命令下发成功!");
......@@ -98,4 +99,37 @@ public class BaseAreaController extends BaseCRUDJsonBodyMappingController<BaseAr
}
/**
* 更新基础区域数据
*/
@PostMapping(value = "updateBaseArea")
@UnAuth
public String updateBaseArea(@RequestBody BaseAreaQuery areaQuery) {
JSONObject jsonObject = new JSONObject();
String busiDesc = "更新基础区域数据" + this.getModuleDesc();
try {
if (ObjectUtils.isEmpty(areaQuery.getName()) && ObjectUtils.isEmpty(areaQuery.getAreaCode())) {
throw new AppException("当前初始区域编码或名称为空!");
}
new Thread(() -> {
this.service.updateArea(areaQuery, getContext());
}).start();
//编码优先
//this.service.updateArea(areaQuery, getContext());
// ThreadPool.getInstance().execute(thread);
recordSysLog(request, busiDesc + " 【成功】");
jsonObject.put(KEY_RESULT_CODE, VALUE_RESULT_SUCCESS);
jsonObject.put(KEY_RESULT_MSG, "更新基础区域数据命令下发成功!");
} catch (Exception e) {
log.error("获取异常", e);
jsonObject.put(KEY_RESULT_CODE, VALUE_RESULT_FAILURE);
jsonObject.put(KEY_RESULT_MSG, super.convertException(e));
}
return jsonObject.toJSONString();
}
}
\ No newline at end of file
......@@ -63,6 +63,11 @@ Content-Type: application/json
{}
###更新区域
POST {{baseUrl}}/base/area/updateBaseArea
Content-Type: application/json
{"areaCode": "510000000000"}
###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