Browse Source

用户名自动生成

Lifan 1 year ago
parent
commit
7522f68b22

+ 4 - 1
application/doc/数据库序列,用于生成编号

@@ -20,4 +20,7 @@ CREATE SEQUENCE nx_materials_management_sequence;
 CREATE SEQUENCE nx_storehouse_management_sequence;
 
 --预案
-CREATE SEQUENCE nx_reserve_plan_sequence;
+CREATE SEQUENCE nx_reserve_plan_sequence;
+
+--用户名
+CREATE SEQUENCE sys_user_sequence;

+ 7 - 0
application/src/main/java/org/thingsboard/server/controller/nanxi/CommonController.java

@@ -9,6 +9,7 @@ import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 import org.thingsboard.server.domain.BaseOutput;
+import org.thingsboard.server.domain.SysAreaTreeInfo;
 import org.thingsboard.server.domain.UserInfo;
 import org.thingsboard.server.domain.vo.UserInfoViews;
 import org.thingsboard.server.glossary.enums.EventDataSource;
@@ -40,4 +41,10 @@ public class CommonController {
         return BaseOutput.success(commonService.getUserInfos(id));
     }
 
+    @PostMapping("/areaTree")
+    @ApiOperation(value = "获取用户信息树", notes = "获取用户信息")
+    public BaseOutput<List<SysAreaTreeInfo>> getSysAreaTree(Long code){
+        return BaseOutput.success(commonService.getSysAreaTree(code));
+    }
+
 }

+ 4 - 0
application/src/main/java/org/thingsboard/server/domain/NxReservePlan.java

@@ -60,6 +60,10 @@ public class NxReservePlan extends BaseEntity{
      * 附件
      */
     private String annex;
+    /**
+     * 印发日期
+     */
+    private Date printDate;
     
 
 }

+ 28 - 0
application/src/main/java/org/thingsboard/server/domain/SysAreaTreeInfo.java

@@ -0,0 +1,28 @@
+package org.thingsboard.server.domain;
+
+import io.swagger.annotations.ApiModel;
+import lombok.Data;
+
+import java.util.List;
+
+
+@Data
+@ApiModel(value = "SysAreaTreeInfo", description = "对象 user")
+public class SysAreaTreeInfo {
+    /**
+     * 编号
+     */
+    private Long code;
+    /**
+     * 名称
+     */
+    private String name;
+    /**
+     * 级别
+     */
+    private String level;
+    /**
+     * 子区域
+     */
+    List<SysAreaTreeInfo> areas;
+}

+ 5 - 0
application/src/main/java/org/thingsboard/server/mapper/CommonMapper.java

@@ -1,6 +1,9 @@
 package org.thingsboard.server.mapper;
 
 import org.apache.ibatis.annotations.Mapper;
+import org.thingsboard.server.domain.SysAreaTreeInfo;
+
+import java.util.List;
 
 /**
  * @author Mu
@@ -12,4 +15,6 @@ import org.apache.ibatis.annotations.Mapper;
 public interface CommonMapper {
 
     String getSequenceValue(String sequenceName);
+
+    List<SysAreaTreeInfo> getSysAreaTree(Long code);
 }

+ 8 - 0
application/src/main/java/org/thingsboard/server/service/nanxi/ICommonService.java

@@ -4,6 +4,7 @@ import org.thingsboard.server.common.data.yunteng.dto.OrganizationDTO;
 import org.thingsboard.server.common.data.yunteng.dto.SysAreaDTO;
 import org.thingsboard.server.common.data.yunteng.dto.SysDictItemDTO;
 import org.thingsboard.server.dao.yunteng.entities.SysDeptEntity;
+import org.thingsboard.server.domain.SysAreaTreeInfo;
 import org.thingsboard.server.domain.UserInfo;
 import org.thingsboard.server.domain.vo.UserInfoViews;
 
@@ -65,4 +66,11 @@ public interface ICommonService {
      * @return
      */
     String numberGenerator(Long areaCode, String sequenceName);
+
+    /**
+     * 查询区域树
+     * @param code
+     * @return
+     */
+    List<SysAreaTreeInfo> getSysAreaTree(Long code);
 }

+ 7 - 1
application/src/main/java/org/thingsboard/server/service/nanxi/impl/CommonServiceImpl.java

@@ -6,6 +6,7 @@ import org.thingsboard.server.common.data.yunteng.dto.OrganizationDTO;
 import org.thingsboard.server.common.data.yunteng.dto.SysAreaDTO;
 import org.thingsboard.server.common.data.yunteng.dto.SysDictItemDTO;
 import org.thingsboard.server.dao.yunteng.entities.SysDeptEntity;
+import org.thingsboard.server.domain.SysAreaTreeInfo;
 import org.thingsboard.server.domain.UserInfo;
 import org.thingsboard.server.domain.vo.UserInfoViews;
 import org.thingsboard.server.mapper.CommonMapper;
@@ -78,7 +79,12 @@ public class CommonServiceImpl implements ICommonService {
         if(areaCode == null){
             return null;
         }
-        return String.valueOf(areaCode) + NumberUtils.numberFormat(commonMapper.getSequenceValue(sequenceName));
+        return areaCode + NumberUtils.numberFormat(commonMapper.getSequenceValue(sequenceName));
+    }
+
+    @Override
+    public List<SysAreaTreeInfo> getSysAreaTree(Long code) {
+        return commonMapper.getSysAreaTree(code);
     }
 }
 

+ 24 - 0
application/src/main/resources/mapper/CommonMapper.xml

@@ -7,5 +7,29 @@
         SELECT nextval(#{sequenceName});
     </select>
 
+    <select id="getSysAreaTree" resultMap="AreaTreeMap">
+        select t1.code,t1.name,t1.level,t2.code town_code,t2.name town_name,t2.level town_level,
+        t3.code village_code,t3.name village_name,t3.level village_level
+        from sys_area t1
+        left join sys_area t2 on t1.code = t2.parent_id
+        left join sys_area t3 on t2.code = t3.parent_id
+        where t1.code = '511503'
+    </select>
+
+    <resultMap id="AreaTreeMap" type="org.thingsboard.server.domain.SysAreaTreeInfo">
+        <result column="code" property="code"/>
+        <result column="name" property="name"/>
+        <result column="level" property="level"/>
+        <collection property="areas" ofType="org.thingsboard.server.domain.SysAreaTreeInfo">
+            <result column="town_code" property="code"/>
+            <result column="town_name" property="name"/>
+            <result column="town_level" property="level"/>
+            <collection property="areas" ofType="org.thingsboard.server.domain.SysAreaTreeInfo">
+                <result column="village_code" property="code"/>
+                <result column="village_name" property="name"/>
+                <result column="village_level" property="level"/>
+            </collection>
+        </collection>
+    </resultMap>
 </mapper>
 

+ 7 - 1
common/data/src/main/java/org/thingsboard/server/common/data/yunteng/dto/UserDTO.java

@@ -17,7 +17,7 @@ import java.util.Set;
 public class UserDTO extends BaseDTO {
 
   @ApiModelProperty(value = "用户名")
-  @NotEmpty(message = "用户名不能为空或字符串", groups = AddGroup.class)
+//  @NotEmpty(message = "用户名不能为空或字符串", groups = AddGroup.class)
   private String username;
 
   @ApiModelProperty(value = "真实名称")
@@ -87,4 +87,10 @@ public class UserDTO extends BaseDTO {
 
   @ApiModelProperty(value = "账号锁定状态")
   private Boolean locked;
+
+  @ApiModelProperty(value = "用户所属区域")
+  private Long areaCode;
+
+  @ApiModelProperty(value = "职务")
+  private Long expertTitleId;
 }

+ 15 - 0
dao/src/main/java/org/thingsboard/server/dao/util/yunteng/NumberUtils.java

@@ -0,0 +1,15 @@
+package org.thingsboard.server.dao.util.yunteng;
+
+import org.apache.commons.lang3.StringUtils;
+
+public class NumberUtils {
+
+    public static String numberFormat(String num){
+        if(StringUtils.isNotEmpty(num) && num.length() < 3){
+            // 如果数字长度小于3,则在数字前补足0,使得数字长度为3
+            num = String.format("%0" + (3 - num.length()) + "d%s", 0, num);
+        }
+        return num;
+    }
+
+}

+ 4 - 0
dao/src/main/java/org/thingsboard/server/dao/yunteng/entities/SysUserEntity.java

@@ -44,4 +44,8 @@ public class SysUserEntity extends TenantBaseEntity {
   private Integer level;
 
   private String  remark;
+
+  private Long areaCode;
+
+  private Long expertTitleId;
 }

+ 3 - 0
dao/src/main/java/org/thingsboard/server/dao/yunteng/impl/SysUserServiceImpl.java

@@ -38,6 +38,7 @@ import org.thingsboard.server.common.data.yunteng.enums.UserStatusEnum;
 import org.thingsboard.server.common.data.yunteng.utils.ReflectUtils;
 import org.thingsboard.server.common.data.yunteng.utils.tools.TkPageData;
 import org.thingsboard.server.dao.user.UserService;
+import org.thingsboard.server.dao.util.yunteng.NumberUtils;
 import org.thingsboard.server.dao.yunteng.entities.*;
 import org.thingsboard.server.dao.yunteng.mapper.*;
 import org.thingsboard.server.dao.yunteng.service.*;
@@ -123,6 +124,8 @@ public class SysUserServiceImpl extends AbstractBaseService<UserMapper, SysUserE
           isTenantAdminOperate
               ? FastIotConstants.LevelValue.IS_CUSTOMER_USER
               : FastIotConstants.LevelValue.IS_PLATFORM_ADMIN);
+      if(user.getAreaCode() != null)
+      user.setUsername(user.getAreaCode() + NumberUtils.numberFormat(userRoleMapper.numberGenerator("sys_user_sequence")));
       baseMapper.insert(user);
       for (String roleId : userDTO.getRoleIds()) {
         // 添加用户角色信息

+ 1 - 0
dao/src/main/java/org/thingsboard/server/dao/yunteng/mapper/UserRoleMapper.java

@@ -7,4 +7,5 @@ import org.thingsboard.server.dao.yunteng.entities.SysUserRoleEntity;
 
 @Mapper
 public interface UserRoleMapper extends BaseMapper<SysUserRoleEntity> {
+    String numberGenerator(String sysUserSequence);
 }

+ 3 - 0
dao/src/main/resources/mapper/UserRoleMapper.xml

@@ -6,4 +6,7 @@
         <result property="userId" column="user_id"/>
         <result property="roleId" column="role_id"/>
     </resultMap>
+    <select id="numberGenerator" resultType="String">
+        SELECT nextval(#{sequenceName});
+    </select>
 </mapper>