Browse Source

20250821

厅长信箱
wxc 3 months ago
parent
commit
f891adadca
  1. 32
      mailbox-lan/src/main/java/com/biutag/lan/domain/CountyStreetDept.java
  2. 11
      mailbox-lan/src/main/java/com/biutag/lan/mapper/CountyStreetDeptMapper.java
  3. 0
      mailbox-lan/src/main/resources/mapper/CountyStreetDeptMapper.xml
  4. 18
      mailbox-lan/src/main/resources/mapper/DataScreenMapper.xml
  5. 122
      mailbox-lan/src/test/java/com/biutag/lan/SpringTestCase.java

32
mailbox-lan/src/main/java/com/biutag/lan/domain/CountyStreetDept.java

@ -0,0 +1,32 @@
package com.biutag.lan.domain;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import lombok.Getter;
import lombok.Setter;
/**
* @author wxc
* @date 2025/8/18
*/
@Setter
@Getter
public class CountyStreetDept {
@TableId(type = IdType.AUTO)
private Integer id;
private String deptId;
private String pid;
@TableField("\"level\"")
private Integer level;
private String name;
// 地图数据
private String geometry;
}

11
mailbox-lan/src/main/java/com/biutag/lan/mapper/CountyStreetDeptMapper.java

@ -0,0 +1,11 @@
package com.biutag.lan.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.biutag.lan.domain.CountyStreetDept;
/**
* @author wxc
* @date 2025/8/18
*/
public interface CountyStreetDeptMapper extends BaseMapper<CountyStreetDept> {
}

0
mailbox-lan/src/main/resources/mapper/PoliceUserMapper.xml → mailbox-lan/src/main/resources/mapper/CountyStreetDeptMapper.xml

18
mailbox-lan/src/main/resources/mapper/DataScreenMapper.xml

@ -203,10 +203,20 @@
<select id="mailTypeRank" resultType="java.util.Map"> <select id="mailTypeRank" resultType="java.util.Map">
select ROW_NUMBER() OVER (ORDER BY sumCount desc) AS rowNumber , select ROW_NUMBER() OVER (ORDER BY sumCount desc) AS rowNumber ,
mail_first_category category,count(1) sumCount , mail_first_category category,
CONCAT(ROUND(count(1)*100/(select count(1) from mail where 1=1 count(1) sumCount ,
<if test="id != null and id != ''">and second_dept_id=#{id}</if> (select count(1) from mail where 1=1
),0),'%') countRate <if test="id != null and id != ''">
<choose>
<when test="level == 1">
and first_dept_id=#{id}
</when>
<otherwise>
and second_dept_id=#{id}
</otherwise>
</choose>
</if>) AS denominator,
CONCAT(ROUND(CASE WHEN denominator = 0 THEN 0 ELSE sumCount * 100 / denominator END,0),'%') countRate
FROM mail FROM mail
where 1=1 where 1=1
<if test="id != null and id != ''"> <if test="id != null and id != ''">

122
mailbox-lan/src/test/java/com/biutag/lan/SpringTestCase.java

@ -1,59 +1,105 @@
package com.biutag.lan; package com.biutag.lan;
import cn.hutool.core.io.FileUtil;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelReader;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.read.listener.ReadListener;
import com.alibaba.excel.read.metadata.ReadSheet;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.biutag.lan.domain.CountyStreetDept;
import com.biutag.constants.AppConstants; import com.biutag.lan.domain.bo.DutyImport;
import com.biutag.entity.system.Dept; import com.biutag.lan.mapper.CountyStreetDeptMapper;
import com.biutag.entity.vo.DeptTree;
import com.biutag.mapper.system.DeptMapper;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import java.util.ArrayList; import java.io.*;
import java.util.HashMap; import java.util.*;
import java.util.List; import java.util.zip.ZipFile;
import java.util.Map;
@SpringBootTest @SpringBootTest
public class SpringTestCase { public class SpringTestCase {
@Autowired @Autowired
private DeptMapper deptMapper; private CountyStreetDeptMapper countyStreetDeptMapper;
@Test @Test
public void testMailCategory() { public void map() {
LambdaQueryWrapper<Dept> queryWrapper = new LambdaQueryWrapper<Dept>().eq(Dept::getIsDelete, 0).orderByAsc(Dept::getSort); List<File> files = FileUtil.loopFiles("D:\\Workspace\\创客\\地图数据\\湖南\\长沙");
List<Dept> depts = deptMapper.selectList(queryWrapper); for (File file : files) {
System.out.println(file.getName());
Map<String, DeptTree> childMap = new HashMap<>(); String name = file.getName().substring(0, file.getName().indexOf("边界"));
depts.forEach(dept -> { int firstIndex = file.getName().indexOf("_");
DeptTree node = new DeptTree(); String deptId = file.getName().substring(firstIndex + 1, file.getName().indexOf("_", firstIndex + 1)) + "000000";
BeanUtils.copyProperties(dept, node); try {
childMap.put(dept.getId(), node); ZipFile zipFile = new ZipFile(file);
}); zipFile.stream().forEach(entry -> {
List<DeptTree> tree = new ArrayList<>(); try (InputStream is = zipFile.getInputStream(entry)) {
for (Dept dept : depts) { BufferedReader reader = new BufferedReader(new InputStreamReader(is));
// 根节点 StringBuilder content = new StringBuilder();
if (AppConstants.ROOT_DEPT_ID.equals(dept.getId())) { String line;
tree.add(childMap.get(dept.getId()));
} else { // 逐行读取并拼接
DeptTree parent = childMap.get(dept.getPid()); while ((line = reader.readLine()) != null) {
if (parent != null) { content.append(line); // 保留换行符
parent.getChildren().add(childMap.get(dept.getId())); // 添加到父节点的子列表 }
} String geo = content.toString();
CountyStreetDept countryStreetDept = countyStreetDeptMapper.selectOne(new LambdaQueryWrapper<CountyStreetDept>().eq(CountyStreetDept::getName, name));
if (Objects.isNull(countryStreetDept)) {
countryStreetDept = new CountyStreetDept();
countryStreetDept.setDeptId(deptId);
countryStreetDept.setName(name);
countryStreetDept.setLevel(2);
countryStreetDept.setGeometry(geo);
countyStreetDeptMapper.insert(countryStreetDept);
} else {
countryStreetDept.setDeptId(deptId);
countryStreetDept.setGeometry(geo);
countyStreetDeptMapper.updateById(countryStreetDept);
}
} catch (IOException e) {
e.printStackTrace();
}
});
} catch (IOException e) {
throw new RuntimeException(e);
} }
// String geo = FileUtil.readString(unzip, "UTF-8");
//
// System.out.println(geo);
} }
update(tree, 0);
} }
public void update(List<DeptTree> tree, int level) {
for (DeptTree deptTree : tree) { @Test
LambdaUpdateWrapper<Dept> updateWrapper = new LambdaUpdateWrapper<Dept>().eq(Dept::getId, deptTree.getId()).set(Dept::getLevel, level); public void saveCountyStreetDept() {
deptMapper.update(updateWrapper); ExcelReader excelReader = EasyExcel.read(new File("D:\\Workspace\\创客\\地图数据\\湖南省乡镇区行政区划编码.xlsx"), new ReadListener<LinkedHashMap>() {
update(deptTree.getChildren(), level + 1);
} @Override
public void invoke(LinkedHashMap data, AnalysisContext analysisContext) {
System.out.println(data);
String pid = data.get(5).toString();
String name = data.get(6).toString();
String deptId = data.get(7).toString();
CountyStreetDept countyStreetDept = new CountyStreetDept();
countyStreetDept.setPid(pid);
countyStreetDept.setName(name);
countyStreetDept.setDeptId(deptId);
countyStreetDept.setLevel(3);
countyStreetDeptMapper.insert(countyStreetDept);
}
@Override
public void doAfterAllAnalysed(AnalysisContext analysisContext) {
}
}).build();
ReadSheet sheet = EasyExcel.readSheet(0).build();
excelReader.read(sheet);
excelReader.close();
} }
} }

Loading…
Cancel
Save