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. 116
      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 ROW_NUMBER() OVER (ORDER BY sumCount desc) AS rowNumber ,
mail_first_category category,count(1) sumCount ,
CONCAT(ROUND(count(1)*100/(select count(1) from mail where 1=1
<if test="id != null and id != ''">and second_dept_id=#{id}</if>
),0),'%') countRate
mail_first_category category,
count(1) sumCount ,
(select count(1) from mail where 1=1
<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
where 1=1
<if test="id != null and id != ''">

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

@ -1,59 +1,105 @@
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.update.LambdaUpdateWrapper;
import com.biutag.constants.AppConstants;
import com.biutag.entity.system.Dept;
import com.biutag.entity.vo.DeptTree;
import com.biutag.mapper.system.DeptMapper;
import com.biutag.lan.domain.CountyStreetDept;
import com.biutag.lan.domain.bo.DutyImport;
import com.biutag.lan.mapper.CountyStreetDeptMapper;
import org.junit.jupiter.api.Test;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.io.*;
import java.util.*;
import java.util.zip.ZipFile;
@SpringBootTest
public class SpringTestCase {
@Autowired
private DeptMapper deptMapper;
private CountyStreetDeptMapper countyStreetDeptMapper;
@Test
public void testMailCategory() {
LambdaQueryWrapper<Dept> queryWrapper = new LambdaQueryWrapper<Dept>().eq(Dept::getIsDelete, 0).orderByAsc(Dept::getSort);
List<Dept> depts = deptMapper.selectList(queryWrapper);
Map<String, DeptTree> childMap = new HashMap<>();
depts.forEach(dept -> {
DeptTree node = new DeptTree();
BeanUtils.copyProperties(dept, node);
childMap.put(dept.getId(), node);
});
List<DeptTree> tree = new ArrayList<>();
for (Dept dept : depts) {
// 根节点
if (AppConstants.ROOT_DEPT_ID.equals(dept.getId())) {
tree.add(childMap.get(dept.getId()));
public void map() {
List<File> files = FileUtil.loopFiles("D:\\Workspace\\创客\\地图数据\\湖南\\长沙");
for (File file : files) {
System.out.println(file.getName());
String name = file.getName().substring(0, file.getName().indexOf("边界"));
int firstIndex = file.getName().indexOf("_");
String deptId = file.getName().substring(firstIndex + 1, file.getName().indexOf("_", firstIndex + 1)) + "000000";
try {
ZipFile zipFile = new ZipFile(file);
zipFile.stream().forEach(entry -> {
try (InputStream is = zipFile.getInputStream(entry)) {
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
StringBuilder content = new StringBuilder();
String line;
// 逐行读取并拼接
while ((line = reader.readLine()) != null) {
content.append(line); // 保留换行符
}
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 {
DeptTree parent = childMap.get(dept.getPid());
if (parent != null) {
parent.getChildren().add(childMap.get(dept.getId())); // 添加到父节点的子列表
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) {
LambdaUpdateWrapper<Dept> updateWrapper = new LambdaUpdateWrapper<Dept>().eq(Dept::getId, deptTree.getId()).set(Dept::getLevel, level);
deptMapper.update(updateWrapper);
update(deptTree.getChildren(), level + 1);
@Test
public void saveCountyStreetDept() {
ExcelReader excelReader = EasyExcel.read(new File("D:\\Workspace\\创客\\地图数据\\湖南省乡镇区行政区划编码.xlsx"), new ReadListener<LinkedHashMap>() {
@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