增加地区修复功能
This commit is contained in:
parent
45556c6419
commit
0ae52c409e
@ -148,5 +148,12 @@ public class AreaController extends DefaultBaseController {
|
|||||||
return areaService.listByCode(areaCode);
|
return areaService.listByCode(areaCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ApiOperation(value = "更新短标题和合并名称", notes = "更新短标题和合并名称接口")
|
||||||
|
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
|
||||||
|
@GetMapping("update-sort-and-merger-name")
|
||||||
|
public SuccessResult updateShortAndMergerName() {
|
||||||
|
areaService.updateShortAndMergerName();
|
||||||
|
return new SuccessResult();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,6 @@ import ink.wgink.module.dictionary.pojo.dtos.AreaDTO;
|
|||||||
import ink.wgink.pojo.dtos.ZTreeDTO;
|
import ink.wgink.pojo.dtos.ZTreeDTO;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
import java.rmi.RemoteException;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@ -55,6 +54,15 @@ public interface IAreaDao extends IInitBaseTable {
|
|||||||
*/
|
*/
|
||||||
void update(Map<String, Object> params) throws UpdateException;
|
void update(Map<String, Object> params) throws UpdateException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改合并名称和短名称
|
||||||
|
*
|
||||||
|
* @param params
|
||||||
|
* @throws UpdateException
|
||||||
|
*/
|
||||||
|
void updateShortAndMergerName(Map<String, Object> params) throws UpdateException;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 地区字典列表
|
* 地区字典列表
|
||||||
*
|
*
|
||||||
@ -64,6 +72,15 @@ public interface IAreaDao extends IInitBaseTable {
|
|||||||
*/
|
*/
|
||||||
List<AreaDTO> list(Map<String, Object> params) throws SearchException;
|
List<AreaDTO> list(Map<String, Object> params) throws SearchException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分页
|
||||||
|
*
|
||||||
|
* @param params
|
||||||
|
* @return
|
||||||
|
* @throws SearchException
|
||||||
|
*/
|
||||||
|
List<AreaDTO> listPage(Map<String, Object> params) throws SearchException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 地区字典详情
|
* 地区字典详情
|
||||||
*
|
*
|
||||||
@ -100,4 +117,13 @@ public interface IAreaDao extends IInitBaseTable {
|
|||||||
*/
|
*/
|
||||||
Integer countByParentId(String id) throws SearchException;
|
Integer countByParentId(String id) throws SearchException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 统计总数
|
||||||
|
*
|
||||||
|
* @param params
|
||||||
|
* @return
|
||||||
|
* @throws SearchException
|
||||||
|
*/
|
||||||
|
Integer count(Map<String, Object> params) throws SearchException;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -72,6 +72,14 @@ public interface IAreaService {
|
|||||||
*/
|
*/
|
||||||
AreaDTO getByCode(String areaCode);
|
AreaDTO getByCode(String areaCode);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 全等级
|
||||||
|
*
|
||||||
|
* @param areaId
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
List<AreaDTO> listFullLevel(String areaId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 地区列表
|
* 地区列表
|
||||||
*
|
*
|
||||||
@ -135,4 +143,9 @@ public interface IAreaService {
|
|||||||
*/
|
*/
|
||||||
List<AreaDTO> listSubByCode(String areaCode);
|
List<AreaDTO> listSubByCode(String areaCode);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新短标题和合并名称
|
||||||
|
*/
|
||||||
|
void updateShortAndMergerName();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ package ink.wgink.module.dictionary.service.impl;
|
|||||||
import com.github.pagehelper.PageHelper;
|
import com.github.pagehelper.PageHelper;
|
||||||
import com.github.pagehelper.PageInfo;
|
import com.github.pagehelper.PageInfo;
|
||||||
import ink.wgink.common.base.DefaultBaseService;
|
import ink.wgink.common.base.DefaultBaseService;
|
||||||
|
import ink.wgink.interfaces.consts.ISystemConstant;
|
||||||
import ink.wgink.module.dictionary.dao.IAreaDao;
|
import ink.wgink.module.dictionary.dao.IAreaDao;
|
||||||
import ink.wgink.module.dictionary.pojo.dtos.AreaDTO;
|
import ink.wgink.module.dictionary.pojo.dtos.AreaDTO;
|
||||||
import ink.wgink.module.dictionary.pojo.vos.AreaVO;
|
import ink.wgink.module.dictionary.pojo.vos.AreaVO;
|
||||||
@ -12,12 +13,16 @@ import ink.wgink.pojo.dtos.ZTreeDTO;
|
|||||||
import ink.wgink.pojo.result.SuccessResultList;
|
import ink.wgink.pojo.result.SuccessResultList;
|
||||||
import ink.wgink.util.map.HashMapUtil;
|
import ink.wgink.util.map.HashMapUtil;
|
||||||
import ink.wgink.util.string.WStringUtil;
|
import ink.wgink.util.string.WStringUtil;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.ExecutorService;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
|
import java.util.concurrent.ThreadPoolExecutor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* When you feel like quitting. Think about why you started
|
* When you feel like quitting. Think about why you started
|
||||||
@ -34,6 +39,10 @@ public class AreaServiceImpl extends DefaultBaseService implements IAreaService
|
|||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private IAreaDao areaDao;
|
private IAreaDao areaDao;
|
||||||
|
/**
|
||||||
|
* 更新合并和短标题线程池
|
||||||
|
*/
|
||||||
|
private static ExecutorService UPDATE_MERGER_SHORT_NAME_EXECUTOR_SERVICE = Executors.newFixedThreadPool(66);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void save(AreaVO areaVO) {
|
public void save(AreaVO areaVO) {
|
||||||
@ -78,6 +87,15 @@ public class AreaServiceImpl extends DefaultBaseService implements IAreaService
|
|||||||
return areaDao.get(params);
|
return areaDao.get(params);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<AreaDTO> listFullLevel(String areaId) {
|
||||||
|
AreaDTO areaDTO = get(areaId);
|
||||||
|
List<AreaDTO> fullLevelAreaDTOS = new ArrayList<>();
|
||||||
|
fullLevelAreaDTOS.add(0, areaDTO);
|
||||||
|
setFullLevel(fullLevelAreaDTOS, areaDTO.getAreaParentId());
|
||||||
|
return fullLevelAreaDTOS;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<AreaDTO> list() {
|
public List<AreaDTO> list() {
|
||||||
Map<String, Object> params = getHashMap(0);
|
Map<String, Object> params = getHashMap(0);
|
||||||
@ -143,6 +161,117 @@ public class AreaServiceImpl extends DefaultBaseService implements IAreaService
|
|||||||
return areaDao.list(params);
|
return areaDao.list(params);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateShortAndMergerName() {
|
||||||
|
if (isUpdateShortAndMergerName()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Map<String, Object> params = getHashMap(2);
|
||||||
|
Integer count = areaDao.count(params);
|
||||||
|
int row = 1000;
|
||||||
|
int totalPage = row % 1000 == 0 ? count / row : (count / row + 1);
|
||||||
|
// int totalPage = 1;
|
||||||
|
for (int currentPage = 1; currentPage <= totalPage; currentPage++) {
|
||||||
|
updateShortAndMergerName(currentPage, totalPage, row);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否正在更新
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private boolean isUpdateShortAndMergerName() {
|
||||||
|
ThreadPoolExecutor threadPoolExecutor = (ThreadPoolExecutor) UPDATE_MERGER_SHORT_NAME_EXECUTOR_SERVICE;
|
||||||
|
return threadPoolExecutor.getQueue().size() != 0 || threadPoolExecutor.getActiveCount() != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void updateShortAndMergerName(int currentPage, int totalPage, int row) {
|
||||||
|
if (currentPage > totalPage) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
UPDATE_MERGER_SHORT_NAME_EXECUTOR_SERVICE.execute(() -> {
|
||||||
|
int limitStart = (currentPage - 1) * row;
|
||||||
|
Map<String, Object> params = getHashMap(2);
|
||||||
|
params.put("limitStart", limitStart);
|
||||||
|
params.put("limitRow", row);
|
||||||
|
List<AreaDTO> areaDTOS = areaDao.listPage(params);
|
||||||
|
if (areaDTOS.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
areaDTOS.forEach(areaDTO -> {
|
||||||
|
List<AreaDTO> fullLevelAreaDTOS = new ArrayList<>();
|
||||||
|
fullLevelAreaDTOS.add(0, areaDTO);
|
||||||
|
setFullLevel(fullLevelAreaDTOS, areaDTO.getAreaParentId());
|
||||||
|
// 完整的地区名称
|
||||||
|
String areaMergerName = "";
|
||||||
|
for (AreaDTO fullLevelAreaDTO : fullLevelAreaDTOS) {
|
||||||
|
areaMergerName += fullLevelAreaDTO.getAreaName();
|
||||||
|
}
|
||||||
|
String areaShortName = getAreaShortName(areaDTO.getAreaName());
|
||||||
|
params.clear();
|
||||||
|
params.put("areaId", areaDTO.getAreaId());
|
||||||
|
params.put("areaMergerName", areaMergerName);
|
||||||
|
params.put("areaShortName", areaShortName);
|
||||||
|
areaDao.updateShortAndMergerName(params);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取短名称
|
||||||
|
*
|
||||||
|
* @param areaName
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private String getAreaShortName(String areaName) {
|
||||||
|
String areaShortName = areaName;
|
||||||
|
if (areaName.endsWith("市")) {
|
||||||
|
areaShortName = areaShortName.substring(0, areaShortName.length() - 1);
|
||||||
|
} else if (areaName.endsWith("省")) {
|
||||||
|
areaShortName = areaShortName.substring(0, areaShortName.length() - 1);
|
||||||
|
} else if (areaName.endsWith("自治区")) {
|
||||||
|
areaShortName = areaShortName.substring(0, areaShortName.length() - 3);
|
||||||
|
} else if (areaName.endsWith("旗")) {
|
||||||
|
areaShortName = areaShortName.substring(0, areaShortName.length() - 1);
|
||||||
|
} else if (areaName.endsWith("县")) {
|
||||||
|
areaShortName = areaShortName.substring(0, areaShortName.length() - 1);
|
||||||
|
} else if (areaName.endsWith("社区")) {
|
||||||
|
areaShortName = areaShortName.substring(0, areaShortName.length() - 2);
|
||||||
|
} else if (areaName.endsWith("区")) {
|
||||||
|
areaShortName = areaShortName.substring(0, areaShortName.length() - 1);
|
||||||
|
} else if (areaName.endsWith("乡")) {
|
||||||
|
areaShortName = areaShortName.substring(0, areaShortName.length() - 1);
|
||||||
|
} else if (areaName.endsWith("镇")) {
|
||||||
|
areaShortName = areaShortName.substring(0, areaShortName.length() - 1);
|
||||||
|
} else if (areaName.endsWith("街道")) {
|
||||||
|
areaShortName = areaShortName.substring(0, areaShortName.length() - 2);
|
||||||
|
} else if (areaName.endsWith("居委会")) {
|
||||||
|
areaShortName = areaShortName.substring(0, areaShortName.length() - 2);
|
||||||
|
} else if (areaName.endsWith("嘎查村")) {
|
||||||
|
areaShortName = areaShortName.substring(0, areaShortName.length() - 3);
|
||||||
|
} else if (areaName.endsWith("村")) {
|
||||||
|
areaShortName = areaShortName.substring(0, areaShortName.length() - 1);
|
||||||
|
}
|
||||||
|
return areaShortName;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置完整级别
|
||||||
|
*
|
||||||
|
* @param fullLevelAreaDTOS
|
||||||
|
* @param areaParentId
|
||||||
|
*/
|
||||||
|
private void setFullLevel(List<AreaDTO> fullLevelAreaDTOS, String areaParentId) {
|
||||||
|
if (StringUtils.equals(ISystemConstant.TREE_ROOT_ID, areaParentId)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
AreaDTO areaDTO = get(areaParentId);
|
||||||
|
fullLevelAreaDTOS.add(0, areaDTO);
|
||||||
|
setFullLevel(fullLevelAreaDTOS, areaDTO.getAreaParentId());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 递归查询子组
|
* 递归查询子组
|
||||||
*
|
*
|
||||||
|
@ -154,6 +154,17 @@
|
|||||||
area_id = #{areaId}
|
area_id = #{areaId}
|
||||||
</update>
|
</update>
|
||||||
|
|
||||||
|
<!-- 修改合并名称和短名称 -->
|
||||||
|
<update id="updateShortAndMergerName" parameterType="map" flushCache="true">
|
||||||
|
UPDATE
|
||||||
|
data_area
|
||||||
|
SET
|
||||||
|
area_merger_name = #{areaMergerName},
|
||||||
|
area_short_name = #{areaShortName}
|
||||||
|
WHERE
|
||||||
|
area_id = #{areaId}
|
||||||
|
</update>
|
||||||
|
|
||||||
<!-- ztree列表 -->
|
<!-- ztree列表 -->
|
||||||
<select id="listZTree" parameterType="map" resultMap="areaZTreeDTO" useCache="true">
|
<select id="listZTree" parameterType="map" resultMap="areaZTreeDTO" useCache="true">
|
||||||
SELECT
|
SELECT
|
||||||
@ -228,6 +239,36 @@
|
|||||||
</if>
|
</if>
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
<!-- 字典列表 -->
|
||||||
|
<select id="listPage" parameterType="map" resultMap="areaDTO" useCache="true">
|
||||||
|
SELECT
|
||||||
|
area_id,
|
||||||
|
area_parent_id,
|
||||||
|
area_name,
|
||||||
|
area_code,
|
||||||
|
area_city_code,
|
||||||
|
area_merger_name,
|
||||||
|
area_short_name,
|
||||||
|
area_zip_code,
|
||||||
|
area_level,
|
||||||
|
area_lng,
|
||||||
|
area_lat,
|
||||||
|
area_pinyin,
|
||||||
|
area_first
|
||||||
|
FROM
|
||||||
|
data_area
|
||||||
|
WHERE
|
||||||
|
area_id >= (
|
||||||
|
SELECT
|
||||||
|
area_id
|
||||||
|
FROM
|
||||||
|
data_area
|
||||||
|
LIMIT
|
||||||
|
#{limitStart}, 1
|
||||||
|
)
|
||||||
|
LIMIT #{limitRow}
|
||||||
|
</select>
|
||||||
|
|
||||||
<!-- 字典详情 -->
|
<!-- 字典详情 -->
|
||||||
<select id="get" parameterType="map" resultMap="areaDTO">
|
<select id="get" parameterType="map" resultMap="areaDTO">
|
||||||
SELECT
|
SELECT
|
||||||
@ -277,6 +318,20 @@
|
|||||||
area_parent_id = #{_parameter}
|
area_parent_id = #{_parameter}
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
<!-- 统计总数 -->
|
||||||
|
<select id="count" parameterType="map" resultType="Integer" useCache="true">
|
||||||
|
SELECT
|
||||||
|
COUNT(*)
|
||||||
|
FROM
|
||||||
|
data_area
|
||||||
|
WHERE
|
||||||
|
is_delete = 0
|
||||||
|
<if test="areaParentId != null and areaParentId != ''">
|
||||||
|
AND
|
||||||
|
area_parent_id = #{areaParentId}
|
||||||
|
</if>
|
||||||
|
</select>
|
||||||
|
|
||||||
<!-- 获取最后一个子字典,实际数据,包含已删除,方式编码重复 -->
|
<!-- 获取最后一个子字典,实际数据,包含已删除,方式编码重复 -->
|
||||||
<select id="getLastByParentId" parameterType="String" resultMap="areaDTO">
|
<select id="getLastByParentId" parameterType="String" resultMap="areaDTO">
|
||||||
SELECT
|
SELECT
|
||||||
|
Loading…
Reference in New Issue
Block a user