Przeglądaj źródła

Merge remote-tracking branch 'origin/master'

wangyanygang 4 lat temu
rodzic
commit
a7130f7576

+ 5 - 1
pom.xml

@@ -179,7 +179,11 @@
             <artifactId>guava</artifactId>
             <version>20.0</version>
         </dependency>
-
+        <!-- 引入aop-->
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-aop</artifactId>
+        </dependency>
     </dependencies>
 
     <build>

+ 28 - 53
user_auth/src/main/resources/application-sit.properties

@@ -1,94 +1,69 @@
-server.port=8322
-spring.application.name=smart-city-v2-user
+server.port=8321
+spring.application.name=user-auth
 logging.level.root=info
-logging.level.com.alibaba.nacos.client.naming=error
-logging.path=/opt/sit/smartcity-user/logs
-#数据库配置
-spring.datasource.url=jdbc:mysql://10.0.0.161:3306/smart_city_v2?characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai&zeroDateTimeBehavior=convertToNull
+logging.path=./logs/user-auth
+#\u6570\u636E\u5E93\u914D\u7F6E
+spring.datasource.url=jdbc:mysql://114.135.61.188:33306/uims?characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai&zeroDateTimeBehavior=convertToNull
 spring.datasource.username=root
 spring.datasource.password=100Zone@123
-spring.datasource.druid.driver-class-name=com.mysql.jdbc.Driver
-spring.datasource.druid.filters=stat
-spring.datasource.druid.minIdle=1
-spring.datasource.druid.pool-prepared-statements=true
-spring.datasource.druid.max-open-prepared-statements=20
-spring.datasource.druid.test-on-return=false
-spring.datasource.druid.test-on-borrow=false
-spring.datasource.druid.test-while-idle=true
-spring.datasource.druid.validation-query=select 'x'
-spring.datasource.druid.min-evictable-idle-time-millis=300000
-spring.datasource.druid.time-between-eviction-runs-millis=60000
-spring.datasource.druid.max-active=20
-spring.datasource.druid.max-wait=60000
-spring.datasource.druid.initial-size=1
+spring.datasource.driver-class-name=com.mysql.jdbc.Driver
 
-mybatis.mapper-locations=classpath*:mapper/*.xml
-mybatis.type-aliases-package=com.zcxk.*.entity
-mybatis.configuration.map-underscore-to-camel-case=true
-mybatis.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl
-mybatis.configuration.use-column-label=true
+mybatis-plus.mapper-locations=classpath:mapper/*.xml
+mybatis-plus.type-aliases-package=com.huaxu.entity
+mybatis-plus.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl
 
 spring.jackson.time-zone=GMT+8
 #spring.jackson.date-format=yyyy-MM-dd HH:mm:ss
 #spring.jackson.joda-date-time-format: yyyy-MM-dd HH:mm:ss
 
 # redis
-spring.redis.host=10.0.0.161
-spring.redis.port=6379
+spring.redis.host=114.135.61.188
+spring.redis.port=26379
 spring.redis.password=zoniot
-spring.redis.database=13
+spring.redis.database=2
 spring.redis.timeout=36000
 
 # Lettuce
-# 连接池最大连接数(使用负值表示没有限制)
+# \u8FDE\u63A5\u6C60\u6700\u5927\u8FDE\u63A5\u6570\uFF08\u4F7F\u7528\u8D1F\u503C\u8868\u793A\u6CA1\u6709\u9650\u5236\uFF09
 spring.redis.lettuce.pool.max-active=8
-# 连接池最大阻塞等待时间(使用负值表示没有限制)
+# \u8FDE\u63A5\u6C60\u6700\u5927\u963B\u585E\u7B49\u5F85\u65F6\u95F4\uFF08\u4F7F\u7528\u8D1F\u503C\u8868\u793A\u6CA1\u6709\u9650\u5236\uFF09
 spring.redis.lettuce.pool.max-wait=100
-# 连接池中的最大空闲连接
+# \u8FDE\u63A5\u6C60\u4E2D\u7684\u6700\u5927\u7A7A\u95F2\u8FDE\u63A5
 spring.redis.lettuce.pool.max-idle=8
-# 连接池中的最小空闲连接
+# \u8FDE\u63A5\u6C60\u4E2D\u7684\u6700\u5C0F\u7A7A\u95F2\u8FDE\u63A5
 spring.redis.lettuce.pool.min-idle=0
-# 关闭超时时间
+# \u5173\u95ED\u8D85\u65F6\u65F6\u95F4
 spring.redis.lettuce.shutdown-timeout=100
 
 
+security.oauth2.client.client-id=smart-city-v2
+security.oauth2.client.client-secret=smart-city-v2-123
+
+
 spring.servlet.multipart.max-file-size=100MB
 spring.servlet.multipart.max-request-size=100MB
-spring.servlet.multipart.location=/opt/sit/smartcity-user/data
+spring.servlet.multipart.location=${logging.path}/data
 
 #kafka server
-spring.kafka.bootstrap-servers=10.0.0.161:6377
+spring.kafka.bootstrap-servers=114.135.61.188:36377
 #kafka consumer config
-spring.kafka.consumer.group-id=user-group-sit
+spring.kafka.consumer.group-id=user-group-dev
 spring.kafka.consumer.auto-offset-reset=latest
 spring.kafka.consumer.enable-auto-commit=true
 #kafka producer config
 spring.kafka.producer.retries=0
 spring.kafka.producer.batch-size=4096
 spring.kafka.producer.buffer-memory=40960
-com.zcxk.kafka.operation-log.topic=operation_log_sit
+
 spring.kafka.producer.value-serializer=org.springframework.kafka.support.serializer.JsonSerializer
 spring.kafka.consumer.value-deserializer=org.springframework.kafka.support.serializer.JsonDeserializer
 spring.kafka.consumer.properties.spring.json.trusted.packages=*
 
 #nacos
-spring.cloud.nacos.discovery.server-addr=10.0.0.154:8321
-
-#dubbo
-dubbo.scan.base-packages=com.zcxk.user
-dubbo.protocol.name=dubbo
-dubbo.protocol.port=-1
-dubbo.registry.address=spring-cloud://localhost
-dubbo.cloud.subscribed-services=smart-city-v2-admin
-spring.main.allow-bean-definition-overriding=true
-
+spring.cloud.nacos.discovery.server-addr=127.0.0.1:8848
+maxSendCodeNum=3
+getSendCodeMax=2
 
-dubbo.application.qos-enable=true
-dubbo.application.qos-port=33333
-dubbo.application.qos-accept-foreign-ip=false
 
-#登录授权推送模板ID
-login.auth.tips.template=7lh0fkmppfPywI4YfrnMOAKQTGXzjueU6awMRD7KRUk
-spring.cloud.stream.bindings.wechat-notify-message.destination=wechat_notify_channel_sit
 
 

+ 4 - 0
user_center/src/main/java/com/huaxu/controller/TenantController.java

@@ -7,6 +7,7 @@ import com.huaxu.common.FileUploadUtil;
 import com.huaxu.dto.TenantDto;
 import com.huaxu.entity.TenantEntity;
 import com.huaxu.entity.UserEntity;
+import com.huaxu.logAdvice.LogAnnotation;
 import com.huaxu.model.AjaxMessage;
 import com.huaxu.model.Pagination;
 import com.huaxu.model.ResultStatus;
@@ -97,6 +98,7 @@ public class TenantController {
      * @param tenantDto 实体类
      * @return Response对象t
      */
+    @LogAnnotation(module = "【租户管理】新增")
     @RequestMapping(value = "insert", method = RequestMethod.POST)
     @ApiOperation(value = "插入租户信息")
     public AjaxMessage<Integer> insert(@ApiParam(value = "租户信息", required = true) @RequestBody TenantDto tenantDto) {
@@ -117,6 +119,7 @@ public class TenantController {
      * @param tenantDto 实体类
      * @return Response对象
      */
+    @LogAnnotation(module = "【租户管理】修改")
     @RequestMapping(value = "update", method = RequestMethod.POST)
     @ApiOperation(value = "修改租户信息")
     public AjaxMessage<Integer> update(@ApiParam(value = "租户信息", required = true) @RequestBody TenantDto tenantDto) {
@@ -138,6 +141,7 @@ public class TenantController {
      * @param id
      * @return Response对象
      */
+    @LogAnnotation(module = "【租户管理】删除")
     @RequestMapping(value = "delete", method = RequestMethod.POST)
     @ApiOperation(value = "删除租户信息")
     public AjaxMessage<Integer> delete(@ApiParam(value = "租户信息", required = true) @RequestParam Integer id) {

+ 3 - 3
user_center/src/main/java/com/huaxu/dao/TenantMapper.java

@@ -100,14 +100,14 @@ public interface TenantMapper  {
      * 创建租户菜单
      * @return
      */
-    int createTenantMenu( @Param("userName") String userName,@Param("tenantId") Integer tenantId, @Param("menuIds") List<Integer> menuIds);
+    int createTenantMenu( @Param("userName") String userName,@Param("tenantId") String tenantId, @Param("menuIds") List<Integer> menuIds);
 
     /**
-     * 通过租户id查询租户菜单id
+     * 通过租户code查询租户菜单id
      * @param tenantId
      * @return
      */
-    List<Integer> selectTenantMenuIds(Integer tenantId);
+    List<Integer> selectTenantMenuIds(String tenantId);
 
     /**
      * 删除租户菜单

+ 2 - 0
user_center/src/main/java/com/huaxu/dto/UserGroupDto.java

@@ -12,4 +12,6 @@ public class UserGroupDto {
     private List<Long> userIds;
     @ApiModelProperty(value = "角色id")
     private Long roleId;
+    @ApiModelProperty(value = "右边全部删除标识")
+    private Integer deleteFlag=1;
 }

+ 3 - 1
user_center/src/main/java/com/huaxu/entity/OperateLogEntity.java

@@ -35,8 +35,10 @@ public class OperateLogEntity implements Serializable {
     @ApiModelProperty(value = "部门id")
     private Integer departmentId;
     @ExcelProperty(value = {"操作日志","操作内容"},index = 4)
-    @ApiModelProperty(value = "操作内容",example = "2020-12-12 12:12:12")
+    @ApiModelProperty(value = "操作内容")
     private String operateContent;
+    @ApiModelProperty(value = "操作参数",hidden = true)
+    private String operateParameter;
     @ExcelProperty(value = {"操作日志","创建时间"},index = 5)
     @ApiModelProperty(value = "创建时间",example = "2020-12-12 12:12:12")
     @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")

+ 16 - 0
user_center/src/main/java/com/huaxu/logAdvice/LogAnnotation.java

@@ -0,0 +1,16 @@
+package com.huaxu.logAdvice;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * 日志注解
+ *
+ */
+@Target({ ElementType.TYPE,ElementType.METHOD })
+@Retention(RetentionPolicy.RUNTIME)
+public @interface LogAnnotation {
+	String module() default "";
+}

+ 90 - 0
user_center/src/main/java/com/huaxu/logAdvice/OperateLogAdvice.java

@@ -0,0 +1,90 @@
+package com.huaxu.logAdvice;
+
+import com.huaxu.dao.OperateLogMapper;
+import com.huaxu.entity.OperateLogEntity;
+import com.huaxu.model.LoginUser;
+import com.huaxu.util.UserUtil;
+import io.swagger.annotations.ApiOperation;
+import org.aspectj.lang.ProceedingJoinPoint;
+import org.aspectj.lang.Signature;
+import org.aspectj.lang.annotation.Around;
+import org.aspectj.lang.annotation.Aspect;
+import org.aspectj.lang.reflect.MethodSignature;
+import org.springframework.stereotype.Component;
+import org.springframework.util.StringUtils;
+
+import javax.annotation.Resource;
+import java.lang.reflect.Method;
+import java.util.Date;
+
+/**
+ * @description 统一日志处理 :通过自定义注解获取操作名称
+ * @auto wangli
+ * @data 2020-11-09 8:43
+ */
+@Aspect
+@Component
+public class OperateLogAdvice {
+
+    @Resource
+    private OperateLogMapper operateLogMapper;
+
+    @Around(value = "@annotation(com.huaxu.logAdvice.LogAnnotation)")
+    public Object logSave(ProceedingJoinPoint joinPoint) throws Throwable {
+        //参数存储
+        StringBuffer stringBuffer=new StringBuffer();
+        try{
+            //1.获取到所有的参数值的数组
+            Object[] args = joinPoint.getArgs();
+            Signature signature = joinPoint.getSignature();
+            MethodSignature methodSignature = (MethodSignature) signature;
+            //2.获取到方法的所有参数名称的字符串数组
+            String[] parameterNames = methodSignature.getParameterNames();
+            //拼装参数
+            for (int i =0 ,len=parameterNames.length;i < len ;i++){
+                stringBuffer.append("\r\n参数名:"+ parameterNames[i] + " = " +args[i]);
+            }
+        }catch (Exception e){
+            e.printStackTrace();
+        }
+
+        OperateLogEntity OperateLogs = new OperateLogEntity();
+        LoginUser user = UserUtil.getCurrentUser();
+        if (user != null) {
+            // 设置当前登录用户
+            OperateLogs.setUserName(user.getUsername());
+            OperateLogs.setPhone(user.getPhoneNumber());
+            OperateLogs.setCompanyId(user.getCompanyId());
+            OperateLogs.setDepartmentId(user.getDepartmentId());
+
+            MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature();
+
+            String module = null;//ApiOperation注解的模块名
+            ApiOperation methodApiOperation = methodSignature.getMethod().getDeclaredAnnotation(ApiOperation.class);
+            if (methodApiOperation != null) {
+                module =methodApiOperation.value();
+            }
+
+            // 没有指定日志module ,获取方法
+            if (StringUtils.isEmpty(module)) {
+                Method method = methodSignature.getMethod();
+                module= method.getDeclaringClass().getName()+method.getName();
+            }
+            OperateLogs.setOperateContent(module);
+
+            try {
+                return  joinPoint.proceed();
+            } catch (Exception e) {
+                OperateLogs.setOperateContent(OperateLogs.getOperateContent()+"__操作抛出异常");
+                throw e;
+            } finally {
+                if (OperateLogs.getUserName() != null) {
+                    OperateLogs.setCreateTime(new Date());
+                    operateLogMapper.insert(OperateLogs);
+                }
+            }
+        }else {
+            return joinPoint.proceed();
+        }
+    }
+}

+ 4 - 4
user_center/src/main/java/com/huaxu/service/impl/TenantServiceImpl.java

@@ -74,7 +74,7 @@ public class TenantServiceImpl implements TenantService {
         TenantDto tenantDto = tenantMapper.selectById(id);
         //获取租户菜单
         if(tenantDto != null){
-            tenantDto.setTenantMenuIds(tenantMapper.selectTenantMenuIds(id));
+            tenantDto.setTenantMenuIds(tenantMapper.selectTenantMenuIds(tenantDto.getCode()));
         }
         return tenantDto;
     }
@@ -123,7 +123,7 @@ public class TenantServiceImpl implements TenantService {
 
         //创建租户菜单信息
         if(tenantDto.getTenantMenuIds().size()>0){
-            tenantMapper.createTenantMenu(tenantDto.getCreateBy(),tenantDto.getId(),tenantDto.getTenantMenuIds());
+            tenantMapper.createTenantMenu(tenantDto.getCreateBy(),tenantDto.getCode(),tenantDto.getTenantMenuIds());
         }
         //创建角色
         Role role = new Role();
@@ -225,14 +225,14 @@ public class TenantServiceImpl implements TenantService {
         //界面传回的租户菜单id
         List<Integer > newTenantMenuIds = tenantDto.getTenantMenuIds();
         //数据库中已存在的租户菜单id
-        List<Integer > oldTenantMenuIds = tenantMapper.selectTenantMenuIds(tenantDto.getId());
+        List<Integer > oldTenantMenuIds = tenantMapper.selectTenantMenuIds(tenantDto.getCode());
         //相同的暂时不改动
 
         //新增的菜单id(需要新增的)
         List<Integer> addTenantMenuIds = newTenantMenuIds.stream().filter(item -> !oldTenantMenuIds.contains(item)).collect(Collectors.toList());
         //创建租户菜单信息
         if(addTenantMenuIds.size()>0){
-            tenantMapper.createTenantMenu(tenantDto.getUpdateBy(),tenantDto.getId(),addTenantMenuIds);
+            tenantMapper.createTenantMenu(tenantDto.getUpdateBy(),tenantDto.getCode(),addTenantMenuIds);
         }
         //去掉的菜单id(需要删除的)
         List<Integer> deleteTenantMenuIds = oldTenantMenuIds.stream().filter(item -> !newTenantMenuIds.contains(item)).collect(Collectors.toList());

+ 7 - 2
user_center/src/main/java/com/huaxu/service/impl/UserGroupServiceImpl.java

@@ -186,8 +186,13 @@ public class UserGroupServiceImpl implements UserGroupService {
         });
 
         userGroupMapper.deleteUserRoles(userGroupDto);
-        userGroupMapper.batchInsertRoles(userRoleEntities);
-        groupUserMapper.batchInsert(groupUsers);
+        if(userGroupDto.getDeleteFlag()==1){
+            userGroupMapper.batchInsertRoles(userRoleEntities);
+            groupUserMapper.batchInsert(groupUsers);
+        }
+
+
+
         return 0;
     }
 }

+ 7 - 4
user_center/src/main/resources/mapper/OperateLogMapper.xml

@@ -92,16 +92,16 @@
     </select>
     <!-- 新增所有列 -->
     <insert id="insert" keyProperty="id" useGeneratedKeys="true">
-        insert into uims_opr_log( USER_NAME, phone, company_id, DEPARTMENT_ID, operate_content, create_time )
-        values ( #{userName}, #{phone}, #{companyId}, #{departmentId}, #{operateContent}, #{createTime})
+        insert into uims_opr_log( USER_NAME, phone, company_id, DEPARTMENT_ID, operate_content, create_time, operate_parameter)
+        values ( #{userName}, #{phone}, #{companyId}, #{departmentId}, #{operateContent}, #{createTime}, #{operateParameter})
     </insert>
     <!-- 批量新增 -->
     <insert id="batchInsert">
-        insert into uims_opr_log( USER_NAME, phone, company_id, DEPARTMENT_ID, operate_content, create_time )
+        insert into uims_opr_log( USER_NAME, phone, company_id, DEPARTMENT_ID, operate_content, create_time, operate_parameter )
         values
         <foreach collection="loginLogs" item="item" index="index" separator=",">
             ( #{item.userName}, #{item.phone}, #{item.companyId}, #{item.departmentId}, #{item.operateContent},
-            #{item.createTime})
+            #{item.createTime}, #{item.operateParameter})
         </foreach>
     </insert>
     <!-- 通过主键修改数据 -->
@@ -126,6 +126,9 @@
             <if test="createTime != null">
                 create_time = #{createTime},
             </if>
+            <if test="operateParameter != null and operateParameter != ''">
+                operate_parameter = #{operateParameter},
+            </if>
         </set>
         where id = #{id}
     </update>

+ 1 - 1
user_center/src/main/resources/mapper/RoleMapper.xml

@@ -246,7 +246,7 @@
         select 	<include refid="userColumns"/>
          from uims_user_role b join uims_user a on b.USER_ID=a.ID
         <include refid="sysAreaJoins"/>
-        where b.ROLE_ID=#{id} and b.status!=0
+        where b.ROLE_ID=#{id} and b.status!=0 and userrole.status!=0
     </select>
     <update id="deleteRoleUser">
         update uims_user_role set status=0 where ROLE_ID=#{id}

+ 2 - 2
user_center/src/main/resources/mapper/UserGroupMapper.xml

@@ -223,8 +223,8 @@
         <if test="id != -1 ">
            and  b.GROUP_ID=#{id} and b.status!=0 and userrole.status!=0
         </if>
-        <if test="id == 0 ">
-          and  b.GROUP_ID is null
+        <if test="id == -1 ">
+          and  b.GROUP_ID is null and userrole.status!=0
         </if>
         <if test="tenantId != null and tenantId != ''">
             and a.TENANT_ID = #{tenantId}