Browse Source

修改了用户、部门编码自增

wuweihao 5 years ago
parent
commit
cd341a2fea

+ 4 - 0
README.md

@@ -35,6 +35,10 @@ http://localhost:8085/xiaoan-web/#/login
     访问url:
     前端:192.168.1.8:8011/dist
     后端:192.1.68.1.8:8011/doc.html
+    
+    对外访问:
+        前端:http://218.17.126.170:9996/dist
+        后端:http://218.17.126.170:9996/doc.html
 	
 mysql	
 	218.17.126.170

+ 0 - 6
xiaoan-application/src/main/resources/application-dev.properties

@@ -1,11 +1,5 @@
 
 #DB
-#spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
-#spring.datasource.driverClassName=com.mysql.jdbc.Driver
-#spring.datasource.url=jdbc:mysql://localhost:3306/xiaoan?useUnicode=true&characterEncoding=utf8&characterSetResults=utf-8&useSSL=false
-#spring.datasource.username=root
-#spring.datasource.password=root
-
 spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
 spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
 spring.datasource.druid.url=jdbc:mysql://localhost:3306/xiaoan?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=utf8&characterSetResults=utf8

+ 2 - 4
xiaoan-application/src/main/resources/application-uat.properties

@@ -2,13 +2,11 @@
 #DB
 spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
 spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
-spring.datasource.druid.url=jdbc:mysql://218.17.126.170:9998/xiaoan?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=utf8&characterSetResults=utf8
+#spring.datasource.druid.url=jdbc:mysql://218.17.126.170:9998/4dkankan_v2?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=utf8&characterSetResults=utf8
+spring.datasource.druid.url=jdbc:mysql://localhost:3306/4dkankan_v2?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=utf8&characterSetResults=utf8
 spring.datasource.druid.username=root
 spring.datasource.druid.password=12345678
 
-
-
-
 # 初始连接数
 spring.datasource.druid.initial-size=5
 # 最小连接池数量

+ 4 - 3
xiaoan-common/src/main/java/com/xiaoan/common/util/PasswordUtils.java

@@ -168,14 +168,15 @@ public class PasswordUtils {
 
     public static void main(String[] args) {
         // 13138102395 13112311178 Aa11111111
-        String userName = "zhiguang";
-        String password = "123456";
+        String userName = "13112311178";
+        String password = "Aa11111111";
 
         try {
             byte[] salt = PasswordUtils.getStaticSalt();
             String ciphertext = PasswordUtils.encrypt(userName, password, salt);
             System.out.println("用户密文密码: " + ciphertext);
-            String plaintext = PasswordUtils.decrypt(ciphertext, userName, salt);
+//            String plaintext = PasswordUtils.decrypt(ciphertext, userName, salt);
+            String plaintext = PasswordUtils.decrypt("970e6cd78216ca8c", "owen", salt);
             System.out.println("用户明文密码:" + plaintext);
         } catch (Exception e) {
             e.printStackTrace();

+ 4 - 0
xiaoan-dao/src/main/java/com/xiaoan/dao/backend/DepartmentRepository.java

@@ -15,4 +15,8 @@ public interface DepartmentRepository extends IBaseMapper<DepartmentEntity, Long
 
     @Select(value = "select * from tb_department d where d.name = #{name}")
     DepartmentEntity findByName(String name);
+
+    /** 获取最大值 */
+    @Select(value = "select MAX(num)  from tb_department")
+    Integer findByMaxNum();
 }

+ 5 - 0
xiaoan-dao/src/main/java/com/xiaoan/dao/backend/UserRepository.java

@@ -54,4 +54,9 @@ public interface UserRepository extends IBaseMapper<UserEntity, Long> {
 
     @Select(value = "select * from tb_user where rec_status = 'A' ORDER BY view_count desc LIMIT #{num}")
     List<UserEntity> findAllByViewCountLimit(int num);
+
+
+    /** 获取最大值 */
+    @Select(value = "select MAX(user_num)  from tb_user")
+    Integer findByMaxNum();
 }

+ 2 - 0
xiaoan-service/src/main/java/com/xiaoan/service/backend/DepartmentService.java

@@ -11,4 +11,6 @@ import org.springframework.data.domain.Page;
 public interface DepartmentService extends IBaseService<DepartmentEntity, Long> {
 
     DepartmentEntity findByName(String name);
+
+    Integer findByMaxNum();
 }

+ 2 - 0
xiaoan-service/src/main/java/com/xiaoan/service/backend/UserService.java

@@ -34,4 +34,6 @@ public interface UserService extends IBaseService<UserEntity, Long> {
     Integer findAllByViewCount();
 
     List<UserEntity> findAllByViewCountLimit(int num);
+
+    Integer findByMaxNum();
 }

+ 5 - 0
xiaoan-service/src/main/java/com/xiaoan/service/backend/impl/DepartmentServiceImpl.java

@@ -28,4 +28,9 @@ public class DepartmentServiceImpl extends BaseServiceImpl<DepartmentEntity, Lon
     public DepartmentEntity findByName(String name) {
         return departmentRepository.findByName(name);
     }
+
+    @Override
+    public Integer findByMaxNum() {
+        return departmentRepository.findByMaxNum();
+    }
 }

+ 5 - 0
xiaoan-service/src/main/java/com/xiaoan/service/backend/impl/UserServiceImpl.java

@@ -80,5 +80,10 @@ UserServiceImpl extends BaseServiceImpl<UserEntity, Long> implements UserService
         return userRepository.findAllByViewCountLimit(param);
     }
 
+    @Override
+    public Integer findByMaxNum() {
+        return userRepository.findByMaxNum();
+    }
+
 
 }

+ 12 - 1
xiaoan-web/src/main/java/com/xiaoan/web/backend/DepartmentController.java

@@ -56,7 +56,7 @@ public class DepartmentController extends BaseController {
     @WebControllerLog(description = "部门信息-新增/修改部门")
     @PostMapping("save")
     public ResultJson save(@RequestBody DepartmentRequest param){
-        if(StringUtils.isEmpty(param.getName()) || StringUtils.isEmpty(param.getNum())){
+        if(StringUtils.isEmpty(param.getName())){
             return new ResultJson(MsgCode.e_COMMON_3001, MsgCode.msg_COMMON_3001);
         }
 
@@ -71,6 +71,17 @@ public class DepartmentController extends BaseController {
 
             entity = new DepartmentEntity();
             BeanUtils.copyProperties(param, entity);
+
+            Integer byMaxNum = departmentService.findByMaxNum();
+
+            // 用于第一条数据
+            if (byMaxNum == null){
+                byMaxNum = 0;
+            }
+
+            byMaxNum = byMaxNum + 1;
+
+            entity.setNum(byMaxNum.toString());
             departmentService.save(entity);
         } else {
             entity = departmentService.findById(id);

+ 11 - 9
xiaoan-web/src/main/java/com/xiaoan/web/backend/IndexController.java

@@ -120,28 +120,30 @@ public class IndexController {
         // 1.获取用户
         UserEntity userEntity = userService.findByUserName(param.getUserName());
         if (userEntity == null){
+            log.error("用户不存在");
             return new ResultJson(MsgCode.e_ADMIN_4001, MsgCode.msg_ADMIN_4001);
         }
-
         // 验证密码,解密出来是明文密码,在跟输入密码比较
-        String pwd = PasswordUtils.decrypt(userEntity.getPassword(), param.getUserName(), PasswordUtils.getStaticSalt());
+        String pwd = PasswordUtils.decrypt(userEntity.getPassword(), userEntity.getUserName(), PasswordUtils.getStaticSalt());
+        log.info("22222222 : {}", pwd);
         if (!pwd.equals(param.getPassword())) {
+            log.error("密码错误");
             return new ResultJson(MsgCode.e_ADMIN_4002, MsgCode.msg_ADMIN_4002);
         }
 
+        log.info("33333333");
         // 检查账号是否启用
         if (userEntity.getStatus() != 0) {
+            log.error("账号已停用: {}", userEntity.getUserName());
             return new ResultJson(MsgCode.e_ADMIN_4003, MsgCode.msg_ADMIN_4003);
         }
 
-        // 获取用户菜单
-//        List<ResourceTree> resourcesByUserMenu = resourceService.getResourcesTreeByUserMenu(userEntity);
-
-//        List<ResourceTree> resourcesTreeByUserPermission = resourceService.getResourcesTreeByUserPermission(userEntity);
         List<ResourceTree> resourcesTreeByUserPermission = resourceService.getResourcesAllByUserPermission(userEntity);
+        log.info("获取权限 success");
 
         // 获取用户角色
         List<String> roles = userService.findRoleByUserId(userEntity.getId());
+        log.info("获取角色 success");
 
 
         // 创建新token
@@ -152,19 +154,18 @@ public class IndexController {
 
 
         String token = JwtUtil2.createJWT(-1, tokenMap);
-//        String token = JwtUtil2.createJWT(tokenExpire, tokenMap);
-//
 
         HashMap<String, Object> result = new HashMap<>();
         result.put("user", userEntity);
         result.put("token", token);
         result.put("permission", resourcesTreeByUserPermission);
-//        result.put("permission", resourcesByUserMenu);
         result.put("role", roles);
+        log.info("token create");
 
 
         // 更新到 redis, 有效期24h, 旧token无效
         redisTemplate.opsForValue().set(userEntity.getUserName(), token, Long.parseLong("23"), TimeUnit.HOURS);
+        log.info("set redis success");
 
         // 更新登录次数
         Integer loginCount = userEntity.getViewCount();
@@ -173,6 +174,7 @@ public class IndexController {
         userEntity.setUpdateTime(new Date());
 
         userService.update(userEntity);
+        log.info("update success");
 
         return new ResultJson(MsgCode.SUCCESS_CODE, result);
 

+ 11 - 0
xiaoan-web/src/main/java/com/xiaoan/web/backend/UserController.java

@@ -79,6 +79,17 @@ public class UserController extends BaseController {
             param.setId(null);
 
             BeanUtils.copyProperties(param, entity);
+
+            Integer byMaxNum = userService.findByMaxNum();
+            // 用于第一条数据
+            if (byMaxNum == null){
+                byMaxNum = 1;
+            }
+            byMaxNum  = byMaxNum +  1;
+
+            entity.setUserNum(byMaxNum.toString());
+
+
             entity.setPassword(PasswordUtils.encrypt(param.getUserName(), "123456", PasswordUtils.getStaticSalt()));
 
             n = userService.save(entity);