24282 2 år sedan
förälder
incheckning
cf691483a8

+ 28 - 0
hx-area/pom.xml

@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <groupId>com.ruoyi</groupId>
+        <artifactId>ruoyi</artifactId>
+        <version>3.8.5</version>
+    </parent>
+
+    <artifactId>hx-area</artifactId>
+
+    <properties>
+        <maven.compiler.source>8</maven.compiler.source>
+        <maven.compiler.target>8</maven.compiler.target>
+        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+    </properties>
+
+    <dependencies>
+        <!-- 核心模块-->
+        <dependency>
+            <groupId>com.ruoyi</groupId>
+            <artifactId>ruoyi-framework</artifactId>
+        </dependency>
+    </dependencies>
+
+</project>

+ 37 - 0
hx-area/src/main/java/com/fjhx/area/controller/AreaInfoController.java

@@ -0,0 +1,37 @@
+package com.fjhx.area.controller;
+
+import com.baomidou.dynamic.datasource.annotation.DS;
+import com.fjhx.area.entity.po.AreaInfo;
+import com.fjhx.area.service.AreaInfoService;
+import com.ruoyi.common.constant.DatasourceConstant;
+import org.springframework.web.bind.annotation.*;
+import com.fjhx.area.entity.dto.AreaInfoSelectDto;
+import org.springframework.beans.factory.annotation.Autowired;
+
+import java.util.List;
+
+/**
+ * <p>
+ * 国家城市表 前端控制器
+ * </p>
+ *
+ * @author 
+ * @since 2023-03-17
+ */
+@DS(DatasourceConstant.SLAVE_NAME)
+@RestController
+@RequestMapping("/areaInfo")
+public class AreaInfoController {
+
+    @Autowired
+    private AreaInfoService areaInfoService;
+
+    /**
+     * 国家城市表列表
+     */
+    @PostMapping("/list")
+    public List<AreaInfo> list(@RequestBody AreaInfoSelectDto dto) {
+        return areaInfoService.getList(dto);
+    }
+
+}

+ 22 - 0
hx-area/src/main/java/com/fjhx/area/entity/dto/AreaInfoSelectDto.java

@@ -0,0 +1,22 @@
+package com.fjhx.area.entity.dto;
+
+import com.ruoyi.common.core.domain.BaseSelectDto;
+import lombok.Getter;
+import lombok.Setter;
+
+/**
+ * 国家城市表列表查询入参实体
+ *
+ * @author 
+ * @since 2023-03-17
+ */
+@Getter
+@Setter
+public class AreaInfoSelectDto extends BaseSelectDto {
+
+    /**
+     * 父id
+     */
+    private String parentId;
+
+}

+ 79 - 0
hx-area/src/main/java/com/fjhx/area/entity/po/AreaInfo.java

@@ -0,0 +1,79 @@
+package com.fjhx.area.entity.po;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import lombok.Getter;
+import lombok.Setter;
+
+import java.io.Serializable;
+
+/**
+ * <p>
+ * 国家城市表
+ * </p>
+ *
+ * @author
+ * @since 2023-03-17
+ */
+@Getter
+@Setter
+@TableName("area_info")
+public class AreaInfo implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+
+    @TableId(value = "id")
+    private String id;
+
+    /**
+     * 父id
+     */
+    private String parentId;
+
+    /**
+     * 祖级列表
+     */
+    private String ancestors;
+
+    /**
+     * 英文名称
+     */
+    private String name;
+
+    /**
+     * 经度
+     */
+    private String lon;
+
+    /**
+     * 维度
+     */
+    private String lat;
+
+    /**
+     * 1国家 2州/省 3城市 4区县
+     */
+    private Integer type;
+
+    /**
+     * 中文名称
+     */
+    private String chineseName;
+
+    /**
+     * 英文简写
+     */
+    private String englishShort;
+
+    /**
+     * 国家图片
+     */
+    private String picturesPath;
+
+    /**
+     * 板块
+     */
+    private Integer plate;
+
+}

+ 16 - 0
hx-area/src/main/java/com/fjhx/area/mapper/AreaInfoMapper.java

@@ -0,0 +1,16 @@
+package com.fjhx.area.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.fjhx.area.entity.po.AreaInfo;
+
+/**
+ * <p>
+ * 国家城市表 Mapper 接口
+ * </p>
+ *
+ * @author
+ * @since 2023-03-17
+ */
+public interface AreaInfoMapper extends BaseMapper<AreaInfo> {
+
+}

+ 31 - 0
hx-area/src/main/java/com/fjhx/area/service/AreaInfoService.java

@@ -0,0 +1,31 @@
+package com.fjhx.area.service;
+
+import com.baomidou.dynamic.datasource.annotation.DS;
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.fjhx.area.entity.dto.AreaInfoSelectDto;
+import com.fjhx.area.entity.po.AreaInfo;
+import com.ruoyi.common.constant.DatasourceConstant;
+
+import java.util.List;
+
+/**
+ * <p>
+ * 国家城市表 服务类
+ * </p>
+ *
+ * @author
+ * @since 2023-03-17
+ */
+public interface AreaInfoService extends IService<AreaInfo> {
+
+    /**
+     * 国家城市表列表
+     */
+    List<AreaInfo> getList(AreaInfoSelectDto dto);
+
+    /**
+     * 赋值地区名称
+     */
+    void setAreaName(List<ISetAreaName> setAreaNameList);
+
+}

+ 35 - 0
hx-area/src/main/java/com/fjhx/area/service/ISetAreaName.java

@@ -0,0 +1,35 @@
+package com.fjhx.area.service;
+
+public interface ISetAreaName {
+
+    /**
+     * 获取国家id
+     */
+    String getCountryId();
+
+    /**
+     * 获取省id
+     */
+    String getProvinceId();
+
+    /**
+     * 市id
+     */
+    String getCityId();
+
+    /**
+     * 赋值国家名称
+     */
+    void setCountryName(String countryName);
+
+    /**
+     * 赋值省名称
+     */
+    void setProvinceName(String provinceName);
+
+    /**
+     * 赋值市id
+     */
+    void setCityName(String cityName);
+
+}

+ 92 - 0
hx-area/src/main/java/com/fjhx/area/service/impl/AreaInfoServiceImpl.java

@@ -0,0 +1,92 @@
+package com.fjhx.area.service.impl;
+
+import cn.hutool.core.util.ObjectUtil;
+import cn.hutool.core.util.StrUtil;
+import com.baomidou.dynamic.datasource.annotation.DS;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.fjhx.area.entity.dto.AreaInfoSelectDto;
+import com.fjhx.area.entity.po.AreaInfo;
+import com.fjhx.area.mapper.AreaInfoMapper;
+import com.fjhx.area.service.AreaInfoService;
+import com.fjhx.area.service.ISetAreaName;
+import com.ruoyi.common.constant.DatasourceConstant;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Propagation;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+/**
+ * <p>
+ * 国家城市表 服务实现类
+ * </p>
+ *
+ * @author
+ * @since 2023-03-17
+ */
+@Service
+public class AreaInfoServiceImpl extends ServiceImpl<AreaInfoMapper, AreaInfo> implements AreaInfoService {
+
+    @Override
+    public List<AreaInfo> getList(AreaInfoSelectDto dto) {
+        String parentId = ObjectUtil.defaultIfNull(dto.getParentId(), "0");
+        return list(Wrappers.<AreaInfo>lambdaQuery().eq(AreaInfo::getParentId, parentId));
+    }
+
+    @Transactional(propagation = Propagation.REQUIRES_NEW)
+    @DS(DatasourceConstant.SLAVE_NAME)
+    @Override
+    public void setAreaName(List<ISetAreaName> areaList) {
+        Set<String> areaIdList = new HashSet<>();
+
+        for (ISetAreaName iSetAreaName : areaList) {
+            if (StrUtil.isNotBlank(iSetAreaName.getCountryId())) {
+                areaIdList.add(iSetAreaName.getCountryId());
+            }
+            if (StrUtil.isNotBlank(iSetAreaName.getProvinceId())) {
+                areaIdList.add(iSetAreaName.getProvinceId());
+            }
+            if (StrUtil.isNotBlank(iSetAreaName.getCityId())) {
+                areaIdList.add(iSetAreaName.getCityId());
+            }
+        }
+
+        if (areaIdList.size() == 0) {
+            return;
+        }
+
+        // 地区
+        List<AreaInfo> areaInfoList = listByIds(areaIdList);
+
+        Map<String, AreaInfo> areaInfoMap = areaInfoList.stream().collect(Collectors.toMap(AreaInfo::getId, item -> item));
+
+        for (ISetAreaName iSetAreaName : areaList) {
+            if (StrUtil.isNotBlank(iSetAreaName.getCountryId())) {
+                AreaInfo areaInfo = areaInfoMap.get(iSetAreaName.getCountryId());
+                if (areaInfo != null) {
+                    iSetAreaName.setCountryName(areaInfo.getChineseName());
+                }
+            }
+            if (StrUtil.isNotBlank(iSetAreaName.getProvinceId())) {
+                AreaInfo areaInfo = areaInfoMap.get(iSetAreaName.getProvinceId());
+                if (areaInfo != null) {
+                    iSetAreaName.setProvinceName(areaInfo.getChineseName());
+                }
+            }
+            if (StrUtil.isNotBlank(iSetAreaName.getCityId())) {
+                AreaInfo areaInfo = areaInfoMap.get(iSetAreaName.getCityId());
+                if (areaInfo != null) {
+                    iSetAreaName.setCityName(areaInfo.getChineseName());
+                }
+            }
+
+        }
+
+    }
+
+}

+ 20 - 0
hx-area/src/main/java/com/fjhx/area/utils/AreaUtil.java

@@ -0,0 +1,20 @@
+package com.fjhx.area.utils;
+
+import cn.hutool.extra.spring.SpringUtil;
+import com.fjhx.area.service.AreaInfoService;
+import com.fjhx.area.service.ISetAreaName;
+
+import java.util.List;
+
+public class AreaUtil {
+
+    private static final AreaInfoService fileInfoService = SpringUtil.getBean(AreaInfoService.class);
+
+    /**
+     * 赋值地区名称
+     */
+    public static void setAreaName(List<ISetAreaName> setAreaNameList) {
+        fileInfoService.setAreaName(setAreaNameList);
+    }
+
+}

+ 5 - 0
hx-area/src/main/resources/mapper/area/AreaInfoMapper.xml

@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.fjhx.area.mapper.AreaInfoMapper">
+
+</mapper>

+ 5 - 0
hx-base/pom.xml

@@ -48,6 +48,11 @@
             <artifactId>hx-tenant</artifactId>
         </dependency>
 
+        <dependency>
+            <groupId>com.ruoyi</groupId>
+            <artifactId>hx-area</artifactId>
+        </dependency>
+
     </dependencies>
 
 </project>

+ 1 - 0
hx-file/src/main/java/com/fjhx/file/service/impl/FileInfoServiceImpl.java

@@ -111,6 +111,7 @@ public class FileInfoServiceImpl extends ServiceImpl<FileInfoMapper, FileInfo> i
         return singVo;
     }
 
+    @Override
     public List<FileInfoVo> getList(FileInfoSelectDto dto) {
 
         if (ObjectUtil.isEmpty(dto.getFileIdList())) {

+ 1 - 1
hx-file/src/main/java/com/fjhx/file/util/ObsFileUtil.java → hx-file/src/main/java/com/fjhx/file/utils/ObsFileUtil.java

@@ -1,4 +1,4 @@
-package com.fjhx.file.util;
+package com.fjhx.file.utils;
 
 import cn.hutool.extra.spring.SpringUtil;
 import com.fjhx.file.entity.ObsFile;

+ 0 - 0
hx-file/src/main/resources/mapper/FileInfoMapper.xml → hx-file/src/main/resources/mapper/file/FileInfoMapper.xml


+ 1 - 1
hx-file/src/test/java/Main.java

@@ -8,7 +8,7 @@ public class Main {
                 .username("fjhx2012mysql")
                 .password("3PN-Mzn#vnP&q6d")
                 .port(9989)
-                .module("hx-flow")
+                .module("hx-area")
                 .parent("com.fjhx.flow")
                 .superServiceClass("com.ruoyi.common.core.service.BaseService")
                 .build();

+ 7 - 0
pom.xml

@@ -174,6 +174,12 @@
                 <version>${ruoyi.version}</version>
             </dependency>
 
+            <dependency>
+                <groupId>com.ruoyi</groupId>
+                <artifactId>hx-area</artifactId>
+                <version>${ruoyi.version}</version>
+            </dependency>
+
         </dependencies>
     </dependencyManagement>
 
@@ -187,6 +193,7 @@
         <module>hx-file</module>
         <module>hx-flow</module>
         <module>hx-tenant</module>
+        <module>hx-area</module>
     </modules>
     <packaging>pom</packaging>
 

+ 15 - 0
ruoyi-common/src/main/java/com/ruoyi/common/core/service/BaseService.java

@@ -8,6 +8,7 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.ruoyi.common.core.domain.BaseIdPo;
+import com.ruoyi.common.exception.ServiceException;
 import com.ruoyi.common.utils.wrapper.IWrapper;
 
 import java.util.List;
@@ -75,4 +76,18 @@ public interface BaseService<T extends BaseIdPo> extends IService<T> {
         return remove(Wrappers.<T>lambdaQuery().func(ObjectUtil.isNotEmpty(consumer), consumer));
     }
 
+    default void nameDuplication(SFunction<T, ?> column, Object value, String errMsg) {
+        T t = getOne(q -> q.eq(column, value));
+        if (t != null) {
+            throw new ServiceException(errMsg);
+        }
+    }
+
+    default void nameDuplication(SFunction<T, ?> column, Object value, Long id, String errMsg) {
+        T t = getOne(q -> q.eq(column, value).ne(T::getId, id));
+        if (t != null) {
+            throw new ServiceException(errMsg);
+        }
+    }
+
 }