瀏覽代碼

重构部门所属区域功能,支持1对多关系。

bruce 2 年之前
父節點
當前提交
873ca71bde

+ 5 - 8
imcs-bt-be/imcs-authority-biz/src/main/java/com/github/zuihou/authority/dao/core/OrgMapper.java

@@ -7,16 +7,13 @@ import org.springframework.stereotype.Repository;
 import java.util.List;
 
 /**
- * <p>
- * Mapper 接口
- * 组织
- * </p>
+ * 组织Mapper接口
  *
- * @author zuihou
+ *  @author zuihou
  * @date 2019-07-22
  */
 @Repository
-public interface OrgMapper extends SuperMapper<Org> {
-
+public interface OrgMapper extends SuperMapper<Org>
+{
     List<Org> getOrgList(Org org);
-}
+}

+ 49 - 0
imcs-bt-be/imcs-authority-biz/src/main/java/com/github/zuihou/authority/dao/core/OrgRegionMapper.java

@@ -0,0 +1,49 @@
+package com.github.zuihou.authority.dao.core;
+
+import com.github.zuihou.authority.entity.core.OrgRegion;
+import com.github.zuihou.base.mapper.SuperMapper;
+import org.apache.ibatis.annotations.Delete;
+import org.apache.ibatis.annotations.MapKey;
+import org.apache.ibatis.annotations.Select;
+import org.springframework.stereotype.Repository;
+
+import java.util.Map;
+
+/**
+ * 组织-所属区域Mapper接口
+ *
+ * @author bruce
+ * @date 2023-02-23
+ */
+@Repository
+public interface OrgRegionMapper extends SuperMapper<OrgRegion>
+{
+    /**
+     * 按照组织分组汇总统计所属区域
+     *
+     * @param ids 组织ID列表
+     * @return {@link Map}<{@link String}, {@link Map}<{@link String}, {@link Object}>>
+     */
+    @MapKey("OrgId")
+    @Select
+    (
+      "SELECT c.org_id AS OrgId, GROUP_CONCAT(c.region_id) AS RegionIds, GROUP_CONCAT(c.name) AS Regions " +
+      "FROM" +
+      "(" +
+      "  SELECT a.org_id, a.region_id, b.name " +
+      "  FROM bt_org_region a " +
+      "  LEFT JOIN c_common_dictionary_item b ON a.region_id = b.id " +
+      "  WHERE a.org_id IN (${ids})" +
+      ") c " +
+      "GROUP BY c.org_id"
+    )
+    Map<Long, Map<String, Object>> findByOrgIds(String ids);
+
+    /**
+     * 删除组织所属区域
+     *
+     * @param id id
+     */
+    @Delete("DELETE FROM bt_org_region WHERE org_id = #{id}")
+    void deleteByOrgId(Long id);
+}

+ 0 - 1
imcs-bt-be/imcs-authority-biz/src/main/java/com/github/zuihou/authority/service/core/impl/OrgServiceImpl.java

@@ -8,7 +8,6 @@ import com.github.zuihou.authority.entity.auth.RoleOrg;
 import com.github.zuihou.authority.entity.auth.User;
 import com.github.zuihou.authority.entity.core.Org;
 import com.github.zuihou.authority.service.auth.RoleOrgService;
-import com.github.zuihou.authority.service.auth.UserService;
 import com.github.zuihou.authority.service.core.OrgService;
 import com.github.zuihou.base.service.SuperCacheServiceImpl;
 import com.github.zuihou.database.mybatis.conditions.Wraps;

+ 3 - 5
imcs-bt-be/imcs-authority-biz/src/main/resources/mapper_authority/base/core/OrgMapper.xml

@@ -16,14 +16,12 @@
         <result column="status" jdbcType="BIT" property="status"/>
         <result column="describe_" jdbcType="VARCHAR" property="describe"/>
         <result column="com_id" jdbcType="BIGINT" property="comId"/>
-        <result column="region_id" jdbcType="BIGINT" property="regionId"/>
     </resultMap>
 
     <!-- 通用查询结果列 -->
     <sql id="Base_Column_List">
         id, create_time, create_user, update_time, update_user,
-        label, abbreviation, parent_id, tree_path, sort_value, status, describe_,
-        com_id, region_id
+        label, abbreviation, parent_id, tree_path, sort_value, status, describe_, com_id
     </sql>
 
     <select id="getOrgList" resultType="com.github.zuihou.authority.entity.core.Org">
@@ -31,10 +29,10 @@
         <if test="label != null">
           and label like concat('%', #{label}, '%')
         </if>
+
         <if test="status != null ">
             and status = #{status}
         </if>
         order by sort_value
     </select>
-
-</mapper>
+</mapper>

+ 34 - 6
imcs-bt-be/imcs-authority-controller/src/main/java/com/github/zuihou/authority/controller/core/OrgController.java

@@ -1,9 +1,11 @@
 package com.github.zuihou.authority.controller.core;
 
 import cn.hutool.core.convert.Convert;
+import com.github.zuihou.authority.dao.core.OrgRegionMapper;
 import com.github.zuihou.authority.dto.core.OrgSaveDTO;
 import com.github.zuihou.authority.dto.core.OrgUpdateDTO;
 import com.github.zuihou.authority.entity.core.Org;
+import com.github.zuihou.authority.entity.core.OrgRegion;
 import com.github.zuihou.authority.service.core.OrgService;
 import com.github.zuihou.base.R;
 import com.github.zuihou.base.controller.SuperCacheController;
@@ -20,18 +22,15 @@ import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.web.bind.annotation.*;
 
+import javax.annotation.Resource;
 import java.util.List;
 import java.util.Map;
 import java.util.stream.Collectors;
 
 import static com.github.zuihou.utils.StrPool.*;
 
-
 /**
- * <p>
- * 前端控制器
- * 组织
- * </p>
+ * 组织Controller
  *
  * @author zuihou
  * @date 2019-07-22
@@ -41,21 +40,51 @@ import static com.github.zuihou.utils.StrPool.*;
 @RestController @RequestMapping("/org") @Slf4j
 public class OrgController extends SuperCacheController<OrgService, Long, Org, Org, OrgSaveDTO, OrgUpdateDTO>
 {
+    @Resource
+    private OrgRegionMapper orgRegionMapper;
+
     @Override
     public R<Org> handlerSave(OrgSaveDTO model)
     {
+        // 1 保存组织
         Org org = BeanPlusUtil.toBean(model, Org.class);
         fillOrg(org);
         this.baseService.save(org);
+
+        // 2 保存所属区域
+        String[] regionIds = org.getRegionIds().split(",");
+        for (String rId : regionIds)
+        {
+            orgRegionMapper.insert(OrgRegion.builder()
+              .orgId(org.getId())
+              .regionId(Long.parseLong(rId))
+              .build());
+        }
+
         return success(org);
     }
 
     @Override
     public R<Org> handlerUpdate(OrgUpdateDTO model)
     {
+        // 1 修改组织
         Org org = BeanPlusUtil.toBean(model, Org.class);
         fillOrg(org);
         this.baseService.updateAllById(org);
+
+        // 2 保存所属区域
+        // 2.1 删除老数据
+        orgRegionMapper.deleteByOrgId(org.getId());
+        // 2.2 插入新数据
+        String[] regionIds = model.getRegionIds().split(",");
+        for (String rId : regionIds)
+        {
+            orgRegionMapper.insert(OrgRegion.builder()
+              .orgId(org.getId())
+              .regionId(Long.parseLong(rId))
+              .build());
+        }
+
         return success(org);
     }
 
@@ -87,7 +116,6 @@ public class OrgController extends SuperCacheController<OrgService, Long, Org, O
      * 查询系统所有的组织树
      *
      * @param status 状态
-     * @return
      * @author zuihou
      * @date 2019-07-29 11:59
      */

+ 10 - 19
imcs-bt-be/imcs-authority-entity/src/main/java/com/github/zuihou/authority/dto/core/OrgSaveDTO.java

@@ -10,24 +10,16 @@ import javax.validation.constraints.NotNull;
 import java.io.Serializable;
 
 /**
- * <p>
- * 实体类
- * 组织
- * </p>
+ * 组织新增实体类
  *
- * @author zuihou
+ *  @author zuihou
  * @since 2019-07-28
  */
-@Data
-@NoArgsConstructor
-@AllArgsConstructor
-@Accessors(chain = true)
-@ToString(callSuper = true)
-@EqualsAndHashCode(callSuper = false)
-@Builder
 @ApiModel(value = "OrgSaveDTO", description = "组织")
-public class OrgSaveDTO implements Serializable {
-
+@ToString(callSuper = true) @EqualsAndHashCode(callSuper = false)
+@Data @Builder @NoArgsConstructor @AllArgsConstructor @Accessors(chain = true)
+public class OrgSaveDTO implements Serializable
+{
     private static final long serialVersionUID = 1L;
 
     /**
@@ -64,11 +56,10 @@ public class OrgSaveDTO implements Serializable {
     @ApiModelProperty(value = "描述")
     @Length(max = 255, message = "描述长度不能超过255")
     private String describe;
-
     /**
-     * 所属区域ID
+     * 所属区域id列表
      */
     @NotNull(message = "请选择所属区域")
-    @ApiModelProperty(value = "所属区域ID")
-    private Long regionId;
-}
+    @ApiModelProperty(value = "所属区域id列表")
+    private String regionIds;
+}

+ 6 - 17
imcs-bt-be/imcs-authority-entity/src/main/java/com/github/zuihou/authority/dto/core/OrgUpdateDTO.java

@@ -11,22 +11,14 @@ import javax.validation.constraints.NotNull;
 import java.io.Serializable;
 
 /**
- * <p>
- * 实体类
- * 组织
- * </p>
+ * 组织修改实体类
  *
  * @author zuihou
  * @since 2019-07-28
  */
-@Data
-@NoArgsConstructor
-@AllArgsConstructor
-@Accessors(chain = true)
-@ToString(callSuper = true)
-@EqualsAndHashCode(callSuper = false)
-@Builder
 @ApiModel(value = "OrgUpdateDTO", description = "组织")
+@ToString(callSuper = true) @EqualsAndHashCode(callSuper = false)
+@Data @Builder @NoArgsConstructor @AllArgsConstructor @Accessors(chain = true)
 public class OrgUpdateDTO implements Serializable
 {
     private static final long serialVersionUID = 1L;
@@ -34,7 +26,6 @@ public class OrgUpdateDTO implements Serializable
     @ApiModelProperty(value = "主键")
     @NotNull(message = "id不能为空", groups = SuperEntity.Update.class)
     private Long id;
-
     /**
      * 名称
      */
@@ -52,7 +43,6 @@ public class OrgUpdateDTO implements Serializable
      */
     @ApiModelProperty(value = "父ID")
     private Long parentId;
-
     /**
      * 排序
      */
@@ -69,11 +59,10 @@ public class OrgUpdateDTO implements Serializable
     @ApiModelProperty(value = "描述")
     @Length(max = 255, message = "描述长度不能超过255")
     private String describe;
-
     /**
-     * 所属区域ID
+     * 所属区域id列表
      */
     @NotNull(message = "请选择所属区域")
-    @ApiModelProperty(value = "所属区域ID")
-    private Long regionId;
+    @ApiModelProperty(value = "所属区域id列表")
+    private String regionIds;
 }

+ 11 - 3
imcs-bt-be/imcs-authority-entity/src/main/java/com/github/zuihou/authority/entity/core/Org.java

@@ -75,11 +75,19 @@ public class Org extends TreeEntity<Org, Long>
     private Long comId;
 
     /**
-     * 所属区域id
+     * 所属区域id列表
      */
-    @ApiModelProperty(value = "所属区域id")
+    @TableField(exist = false)
     @NotNull(message = "请选择所属区域")
-    private Long regionId;
+    @ApiModelProperty(value = "所属区域id列表")
+    private String regionIds;
+
+    /**
+     * 所属区域列表
+     */
+    @TableField(exist = false)
+    @ApiModelProperty(value = "所属区域列表")
+    private String regions;
 
     @TableField(exist = false)
     private Boolean disabled;

+ 33 - 0
imcs-bt-be/imcs-authority-entity/src/main/java/com/github/zuihou/authority/entity/core/OrgRegion.java

@@ -0,0 +1,33 @@
+package com.github.zuihou.authority.entity.core;
+
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.github.zuihou.base.entity.SuperEntity;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.*;
+import lombok.experimental.Accessors;
+
+/**
+ * 组织-所属区域实体类
+ *
+ * @author bruce
+ * @since 2023-02-23
+ */
+@TableName("bt_org_region")
+@ApiModel(value = "OrgRegion", description = "组织-所属区域")
+@ToString(callSuper = true) @EqualsAndHashCode(callSuper = true)
+@Data @Builder @NoArgsConstructor @AllArgsConstructor @Accessors(chain = true)
+public class OrgRegion extends SuperEntity<Long>
+{
+    /**
+     * 组织ID
+     */
+    @ApiModelProperty(value = "组织ID")
+    private Long orgId;
+
+    /**
+     * 所属区域ID
+     */
+    @ApiModelProperty(value = "所属区域ID")
+    private Long regionId;
+}

+ 5 - 0
imcs-bt-be/imcs-business-biz/src/main/java/com/github/zuihou/business/place_region/dao/PlaceRegionMapper.java

@@ -41,6 +41,11 @@ public interface PlaceRegionMapper extends SuperMapper<PlaceRegion>
     )
     Map<Long, Map<String, Object>> findByPlaceIds(String ids);
 
+    /**
+     * 删除场地所属区域
+     *
+     * @param id id
+     */
     @Delete("DELETE FROM bt_place_region WHERE place_id = #{id}")
     void deleteByPlaceId(Long id);
 }

+ 8 - 5
imcs-bt-be/imcs-business-controller/src/main/java/com/github/zuihou/business/controller/place/PlaceController.java

@@ -41,7 +41,7 @@ import java.util.Map;
 import java.util.stream.Collectors;
 
 /**
- * 场地控制器
+ * 场地Controller
  *
  * @author zuihou
  * @date 2022-01-08
@@ -118,10 +118,13 @@ public class PlaceController extends SuperController<PlaceService, Long, Place,
         this.baseService.save(p);
 
         // 2 保存所属区域
-        String[] regionIds = p.getRegionIds().split(",");
+        String[] regionIds = model.getRegionIds().split(",");
         for (String rId : regionIds)
         {
-            placeRegionMapper.insert(PlaceRegion.builder().placeId(p.getId()).regionId(Long.parseLong(rId)).build());
+            placeRegionMapper.insert(PlaceRegion.builder()
+              .placeId(p.getId())
+              .regionId(Long.parseLong(rId))
+              .build());
         }
 
         return success(p);
@@ -130,7 +133,7 @@ public class PlaceController extends SuperController<PlaceService, Long, Place,
     @Override
     public R<Place> handlerUpdate(PlaceUpdateDTO model)
     {
-        // 1 保存场地
+        // 1 修改场地
         Place p = BeanPlusUtil.toBean(model, Place.class);
         this.baseService.updateAllById(p);
 
@@ -138,7 +141,7 @@ public class PlaceController extends SuperController<PlaceService, Long, Place,
         // 2.1 删除老数据
         placeRegionMapper.deleteByPlaceId(p.getId());
         // 2.2 插入新数据
-        String[] regionIds = p.getRegionIds().split(",");
+        String[] regionIds = model.getRegionIds().split(",");
         for (String rId : regionIds)
         {
             placeRegionMapper.insert(PlaceRegion.builder()