Browse Source

日志管理、租户管理修改

wangli 4 years ago
parent
commit
c55fed626a

+ 0 - 3
user_auth/src/main/resources/mapper/LoginLogMapper.xml

@@ -126,9 +126,6 @@
         <include refid="Base_Column_List"/>
         from uims_login_log
         <where>
-            <if test="loginLog.id != null">
-                and id = #{loginLog.id}
-            </if>
             <if test="loginLog.name != null and loginLog.name != ''">
                 and name = #{loginLog.name}
             </if>

+ 2 - 2
user_center/src/main/java/com/huaxu/controller/LoginLogController.java

@@ -117,8 +117,8 @@ public class LoginLogController {
     @ApiOperation(value = "查询登录日志信息列表")
     public AjaxMessage<Pagination<LoginLogDto>> selectPage(
             @ApiParam(value = "登录日志信息", required = true) @RequestBody LoginLogDto loginLogDto,
-            @ApiParam(value = "页数,非必传,默认第一页", defaultValue = "1") int pageNum,
-            @ApiParam(value = "条数,非必传,默认15条", defaultValue = "30") int pageSize
+            @ApiParam(value = "页数,非必传,默认第一页", defaultValue = "1") @RequestParam(required = false, defaultValue = "1") Integer pageNum,
+            @ApiParam(value = "条数,非必传,默认15条", defaultValue = "30") @RequestParam(required = false, defaultValue = "30")Integer pageSize
 
     ) {
         IPage<LoginLogDto> iPage = new Page<>(pageNum, pageSize);

+ 2 - 2
user_center/src/main/java/com/huaxu/controller/OperateLogController.java

@@ -117,8 +117,8 @@ public class OperateLogController {
     @ApiOperation(value = "查询操作日志信息列表")
     public AjaxMessage<Pagination<OperateLogDto>> selectPage(
             @ApiParam(value = "操作日志信息", required = true) @RequestBody OperateLogDto operateLogDto,
-            @ApiParam(value = "页数,非必传,默认第一页",  defaultValue = "1")  int pageNum,
-            @ApiParam(value = "条数,非必传,默认15条",  defaultValue = "30")  int pageSize
+            @ApiParam(value = "页数,非必传,默认第一页",  defaultValue = "1") @RequestParam(required = false, defaultValue = "1") Integer pageNum,
+            @ApiParam(value = "条数,非必传,默认30条",  defaultValue = "30") @RequestParam(required = false, defaultValue = "30") Integer pageSize
 
     ) {
         IPage<OperateLogDto> iPage = new Page<>(pageNum, pageSize);

+ 34 - 21
user_center/src/main/java/com/huaxu/controller/TenantController.java

@@ -3,11 +3,13 @@ package com.huaxu.controller;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.huaxu.common.FileUploadUtil;
+import com.huaxu.dto.TenantDto;
 import com.huaxu.entity.TenantEntity;
 import com.huaxu.model.AjaxMessage;
 import com.huaxu.model.Pagination;
 import com.huaxu.model.ResultStatus;
 import com.huaxu.service.TenantService;
+import com.huaxu.service.UserService;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import io.swagger.annotations.ApiParam;
@@ -28,11 +30,16 @@ import java.util.List;
 @RequestMapping("/tenant")
 @Api(tags = "租户管理")
 public class TenantController {
+
+
     /**
      * 租户
      */
     @Autowired
     private TenantService tenantService;
+    @Autowired
+    private UserService userService;
+
     @Value("${UMIS.sys_config_path}")
     private String baseDir;
 
@@ -44,9 +51,9 @@ public class TenantController {
      */
     @RequestMapping(value = "get", method = RequestMethod.POST)
     @ApiOperation(value = "根据id查询租户")
-    public AjaxMessage<TenantEntity> selectOne(
+    public AjaxMessage<TenantDto> selectOne(
             @ApiParam(value = "租户信息", required = true) @RequestParam Integer id) {
-        TenantEntity result = tenantService.selectById(id);
+        TenantDto result = tenantService.selectById(id);
 
         return new AjaxMessage<>(ResultStatus.OK, result);
     }
@@ -54,20 +61,20 @@ public class TenantController {
     /**
      * 查询租户信息
      *
-     * @param tenantEntity 参数对象
+     * @param tenantDto 参数对象
      * @return 多条数据
      */
     @RequestMapping(value = "selectList", method = RequestMethod.POST)
     @ApiOperation(value = "查询租户信息")
-    public AjaxMessage<List<TenantEntity>> selectList(
-            @ApiParam(value = "租户信息", required = true) @RequestBody TenantEntity tenantEntity) {
-        List<TenantEntity> result = tenantService.selectList(tenantEntity);
+    public AjaxMessage<List<TenantDto>> selectList(
+            @ApiParam(value = "租户信息") @RequestBody TenantDto tenantDto) {
+        List<TenantDto> result = tenantService.selectList(tenantDto);
 
         return new AjaxMessage<>(ResultStatus.OK, result);
     }
 
     /**
-     * 新增
+     * 新增租户logo
      */
     @RequestMapping(value = "addTenantLogo", method = RequestMethod.POST)
     @ResponseBody
@@ -87,13 +94,19 @@ public class TenantController {
     /**
      * 新增一条数据
      *
-     * @param tenantEntity 实体类
-     * @return Response对象
+     * @param tenantDto 实体类
+     * @return Response对象t
      */
     @RequestMapping(value = "insert", method = RequestMethod.POST)
     @ApiOperation(value = "插入租户信息")
-    public AjaxMessage<Integer> insert(@ApiParam(value = "租户信息", required = true) @RequestBody TenantEntity tenantEntity) {
-        int result = tenantService.insert(tenantEntity);
+    public AjaxMessage<Integer> insert(@ApiParam(value = "租户信息", required = true) @RequestBody TenantDto tenantDto) {
+        if (tenantDto.getPhone() != null) {
+            boolean isExsit = userService.checkMobileUnique(tenantDto.getPhone());
+            if (isExsit) {
+                return new AjaxMessage<>(ResultStatus.MEMBER_TELPHONE_ALREADY_EXISTS, 0);
+            }
+        }
+        int result = tenantService.insert(tenantDto);
 
         return new AjaxMessage<>(ResultStatus.OK, result);
     }
@@ -101,13 +114,13 @@ public class TenantController {
     /**
      * 修改一条数据
      *
-     * @param tenantEntity 实体类
+     * @param tenantDto 实体类
      * @return Response对象
      */
     @RequestMapping(value = "update", method = RequestMethod.POST)
     @ApiOperation(value = "修改租户信息")
-    public AjaxMessage<Integer> update(@ApiParam(value = "租户信息", required = true) @RequestBody TenantEntity tenantEntity) {
-        int result = tenantService.update(tenantEntity);
+    public AjaxMessage<Integer> update(@ApiParam(value = "租户信息", required = true) @RequestBody TenantDto tenantDto) {
+        int result = tenantService.update(tenantDto);
         return new AjaxMessage<>(ResultStatus.OK, result);
 
     }
@@ -135,17 +148,17 @@ public class TenantController {
      */
     @RequestMapping(value = "selectPage", method = RequestMethod.POST)
     @ApiOperation(value = "查询租户信息列表")
-    public AjaxMessage<Pagination<TenantEntity>> selectPage(
-            @ApiParam(value = "租户信息", required = true) @RequestBody TenantEntity tenantEntity,
-            @ApiParam(value = "页数,非必传,默认第一页",  defaultValue = "1")  int pageNum,
-            @ApiParam(value = "条数,非必传,默认15条",  defaultValue = "30")  int pageSize
+    public AjaxMessage<Pagination<TenantDto>> selectPage(
+            @ApiParam(value = "租户名称")  TenantDto tenantDto,
+            @ApiParam(value = "页数,非必传,默认第一页",  defaultValue = "1") @RequestParam(required = false, defaultValue = "1") Integer pageNum,
+            @ApiParam(value = "条数,非必传,默认30条",  defaultValue = "30") @RequestParam(required = false, defaultValue = "30") Integer pageSize
 
     ) {
-        IPage<TenantEntity> iPage = new Page<>(pageNum, pageSize);
+        IPage<TenantDto> iPage = new Page<>(pageNum, pageSize);
 
-        iPage = tenantService.selectPage(tenantEntity, iPage);
+        iPage = tenantService.selectPage(iPage, tenantDto );
 
-        Pagination<TenantEntity> pages = new Pagination<>(iPage);
+        Pagination<TenantDto> pages = new Pagination<>(iPage);
 
         return new AjaxMessage<>(ResultStatus.OK, pages);
     }

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

@@ -1,8 +1,12 @@
 package com.huaxu.dao;
 
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.huaxu.dto.TenantDto;
 import com.huaxu.entity.TenantEntity;
+import com.huaxu.entity.UserEntity;
 import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
 
 import java.util.List;
 
@@ -12,7 +16,7 @@ import java.util.List;
  * @data 2020-10-26 10:05
  */
 @Mapper
-public interface TenantMapper {
+public interface TenantMapper  {
 
     /**
      * 通过ID查询单条数据
@@ -20,22 +24,22 @@ public interface TenantMapper {
      * @param id 主键
      * @return 实例对象
      */
-    TenantEntity selectById(Integer id);
+    TenantDto selectById(Integer id);
     
     /**
      * 查询全部
      *
      * @return 对象列表
      */
-    List<TenantEntity> selectAll();
+    List<TenantDto> selectAll();
 
     /**
      * 通过实体作为筛选条件查询
      *
-     * @param tenantEntity 实例对象
+     * @param tenantDto 实例对象
      * @return 对象列表
      */
-    List<TenantEntity> selectList(TenantEntity tenantEntity);
+    List<TenantDto> selectList(TenantDto tenantDto);
 
     /**
      * 新增数据
@@ -76,8 +80,32 @@ public interface TenantMapper {
      */
     int count();
 
-    IPage<TenantEntity> selectPage(IPage<TenantEntity> page, TenantEntity tenantEntity);
+    /**
+     *  分页查询
+     * @param page
+     * @param tenantDto
+     * @return
+     */
+    IPage<TenantDto> selectPage( IPage<TenantDto> page, TenantDto tenantDto);
 
+    /**
+     * 创建租户菜单
+     * @return
+     */
+    int createTenantMenu( @Param("userName") String userName,@Param("tenantId") Integer tenantId, @Param("menuIds") List<Integer> menuIds);
 
+    /**
+     * 通过租户id查询租户菜单id
+     * @param tenantId
+     * @return
+     */
+    List<Integer> selectTenantMenuIds(Integer tenantId);
 
+    /**
+     * 删除租户菜单
+     * @param tenantId
+     * @param menuIds
+     * @return
+     */
+    Integer deleteTenantMenuIds( @Param("tenantId") Integer tenantId,@Param("menuIds")List<Integer> menuIds);
 }

+ 29 - 0
user_center/src/main/java/com/huaxu/dto/TenantDto.java

@@ -0,0 +1,29 @@
+package com.huaxu.dto;
+
+import com.huaxu.entity.TenantEntity;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.util.Date;
+import java.util.List;
+
+/**
+ * @description 租户信息
+ * @auto wangli
+ * @data 2020-10-31 18:08
+ */
+@Data
+@Api(value = "租户信息")
+public class TenantDto extends TenantEntity {
+
+    @ApiModelProperty("用户id")
+    private Long userId;
+    @ApiModelProperty("管理员姓名")
+    private String userName;
+    @ApiModelProperty("手机号")
+    private String phone;
+    @ApiModelProperty("租户菜单id")
+    private List<Integer> tenantMenuIds;
+
+}

+ 11 - 8
user_center/src/main/java/com/huaxu/entity/TenantEntity.java

@@ -1,15 +1,16 @@
 package com.huaxu.entity;
 
+import com.fasterxml.jackson.annotation.JsonFormat;
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
 
-import javax.validation.constraints.NotNull;
 import java.io.Serializable;
 import java.time.LocalDateTime;
+import java.util.Date;
 
 
- /**
+/**
  * @description 租户实体类(uims_tenant)
  * @auto wangli
  * @data 2020-10-26 15:44
@@ -24,31 +25,33 @@ public class TenantEntity implements Serializable {
     @ApiModelProperty(value = "主键id")
     private Integer id;
     @ApiModelProperty(value = "租户名称")
-    @NotNull(message = "租户名称不能为空")
     private String tenantName;
     @ApiModelProperty(value = "租户标识")
-    @NotNull(message = "租户标识不能为空")
     private String code;
     @ApiModelProperty(value = "租户Logo")
     private String logo;
     @ApiModelProperty(value = "租户域名")
     private String webUrl;
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss" , timezone = "GMT+8")
     @ApiModelProperty(value = "租期开始日期")
-    private LocalDateTime startDate;
+    private Date startDate;
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss" , timezone = "GMT+8")
     @ApiModelProperty(value = "租期结束日期")
-    private LocalDateTime endDate;
+    private Date endDate;
     @ApiModelProperty(value = "租户状态")
     private Integer tenantState;
     @ApiModelProperty(value = "备注")
     private String remark;
     @ApiModelProperty(value = "数据删除标识")
     private Integer status;
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss" , timezone = "GMT+8")
     @ApiModelProperty(value = "创建时间")
-    private LocalDateTime dateCreate;
+    private Date dateCreate;
     @ApiModelProperty(value = "创建人")
     private String createBy;
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss" , timezone = "GMT+8")
     @ApiModelProperty(value = "更新时间")
-    private LocalDateTime dateUpdate;
+    private Date dateUpdate;
     @ApiModelProperty(value = "更新人")
     private String updateBy;
 }

+ 10 - 17
user_center/src/main/java/com/huaxu/service/TenantService.java

@@ -1,6 +1,7 @@
 package com.huaxu.service;
 
 import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.huaxu.dto.TenantDto;
 import com.huaxu.entity.TenantEntity;
 
 import java.util.List;
@@ -18,7 +19,7 @@ public interface TenantService {
      * @param id 主键
      * @return 实例对象
      */
-    TenantEntity selectById(Integer id);
+    TenantDto selectById(Integer id);
 
 
     /**
@@ -26,39 +27,31 @@ public interface TenantService {
      *
      * @return 对象列表
      */
-    List<TenantEntity> selectAll();
+    List<TenantDto> selectAll();
 
     /**
      * 通过实体作为筛选条件查询
      *
-     * @param tenantEntity 实例对象
+     * @param tenantDto 实例对象
      * @return 对象列表
      */
-    List<TenantEntity> selectList(TenantEntity tenantEntity);
+    List<TenantDto> selectList(TenantDto tenantDto);
 
     /**
      * 新增数据
      *
-     * @param tenantEntity 实例对象
+     * @param tenantDto 实例对象
      * @return 影响行数
      */
-    int insert(TenantEntity tenantEntity);
-
-    /**
-     * 批量新增
-     *
-     * @param apps 实例对象的集合
-     * @return 影响行数
-     */
-    int batchInsert(List<TenantEntity> apps);
+    Integer insert(TenantDto tenantDto);
 
     /**
      * 修改数据
      *
-     * @param tenantEntity 实例对象
+     * @param tenantDto 实例对象
      * @return 修改
      */
-    int update(TenantEntity tenantEntity);
+    int update(TenantDto tenantDto);
 
     /**
      * 通过主键删除数据
@@ -75,5 +68,5 @@ public interface TenantService {
      */
     int count();
 
-    IPage<TenantEntity> selectPage(TenantEntity tenantEntity, IPage<TenantEntity> page);
+    IPage<TenantDto> selectPage( IPage<TenantDto> page, TenantDto tenantDto);
 }

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

@@ -2,24 +2,38 @@ package com.huaxu.service.impl;
 
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.huaxu.dao.TenantMapper;
+import com.huaxu.dao.UserMapper;
+import com.huaxu.dto.TenantDto;
 import com.huaxu.entity.TenantEntity;
+import com.huaxu.entity.UserEntity;
+import com.huaxu.model.LoginUser;
 import com.huaxu.service.TenantService;
-import org.springframework.beans.factory.annotation.Autowired;
+import com.huaxu.service.UserService;
+import com.huaxu.util.UserUtil;
+import io.swagger.annotations.ApiModelProperty;
 import org.springframework.stereotype.Service;
 
+import javax.annotation.Resource;
+import java.time.LocalDateTime;
+import java.util.Date;
 import java.util.List;
+import java.util.stream.Collectors;
 
 
- /**
+/**
  * @description 租户管理实现类
  * @auto wangli
  * @data 2020-10-26 15:44
  */
 @Service("tenantService")
 public class TenantServiceImpl implements TenantService {
-    @Autowired
+
+    @Resource
     private TenantMapper tenantMapper;
 
+     @Resource
+     private UserService userService;
+
     /**
      * 通过ID查询单条数据
      *
@@ -27,8 +41,13 @@ public class TenantServiceImpl implements TenantService {
      * @return 实例对象
      */
     @Override
-    public TenantEntity selectById(Integer id) {
-        return this.tenantMapper.selectById(id);
+    public TenantDto selectById(Integer id) {
+        TenantDto tenantDto = tenantMapper.selectById(id);
+        //获取租户菜单
+        if(tenantDto != null){
+            tenantDto.setTenantMenuIds(tenantMapper.selectTenantMenuIds(id));
+        }
+        return tenantDto;
     }
 
 
@@ -38,8 +57,8 @@ public class TenantServiceImpl implements TenantService {
      * @return 实例对象的集合
      */
     @Override
-    public List<TenantEntity> selectAll() {
-        return this.tenantMapper.selectAll();
+    public List<TenantDto> selectAll() {
+        return tenantMapper.selectAll();
     }
 
     /**
@@ -48,42 +67,90 @@ public class TenantServiceImpl implements TenantService {
      * @return 实例对象的集合
      */
     @Override
-    public List<TenantEntity> selectList(TenantEntity tenantEntity) {
-        return this.tenantMapper.selectList(tenantEntity);
+    public List<TenantDto> selectList(TenantDto tenantDto) {
+        return tenantMapper.selectList(tenantDto);
     }
 
     /**
      * 新增数据
      *
-     * @param tenantEntity 实例对象
+     * @param tenantDto 实例对象
      * @return 实例对象
      */
     @Override
-    public int insert(TenantEntity tenantEntity) {
-        return this.tenantMapper.insert(tenantEntity);
+    public Integer insert(TenantDto tenantDto) {
+//        LoginUser loginUser = UserUtil.getCurrentUser();
+        //创建租户信息
+//        tenantDto.setCreateBy(loginUser.getUsername());
+//        tenantDto.setDateCreate(new Date());
+//        tenantDto.setUpdateBy(loginUser.getUsername());
+//        tenantDto.setDateUpdate(new Date());
+        tenantDto.setStatus(0);
+        tenantMapper.insert(tenantDto);
+        //创建管理员信息
+        UserEntity userEntity =new UserEntity();
+        userEntity.setTenantId(tenantDto.getCode());//此字段到底取标识还是id
+        userEntity.setCreateBy(tenantDto.getCreateBy());
+        userEntity.setDateCreate(new Date());
+        userEntity.setUpdateBy(tenantDto.getUpdateBy());
+        userEntity.setDateUpdate(new Date());
+        userEntity.setStatus(0);
+        userEntity.setPhone(tenantDto.getPhone());
+        userEntity.setUsername(tenantDto.getUserName());
+        userService.addUser(userEntity);
+        //创建租户菜单信息
+        if(tenantDto.getTenantMenuIds().size()>0){
+            tenantMapper.createTenantMenu(tenantDto.getCreateBy(),tenantDto.getId(),tenantDto.getTenantMenuIds());
+        }
+        return 1;
     }
 
-    /**
-     * 批量新增
-     *
-     * @param apps 实例对象的集合
-     * @return 生效的条数
-     */
-    @Override
-    public int batchInsert(List<TenantEntity> apps) {
-        return this.tenantMapper.batchInsert(apps);
-    }
 
     /**
      * 修改数据
      *
-     * @param tenantEntity 实例对象
+     * @param tenantDto 实例对象
      * @return 实例对象
      */
     @Override
-    public int update(TenantEntity tenantEntity) {
+    public int update(TenantDto tenantDto) {
+//        LoginUser loginUser = UserUtil.getCurrentUser();
+        if(tenantDto.getId() == null){
+            return 0;
+        }
+        //修改租户信息
+//        tenantDto.setUpdateBy(loginUser.getUsername());
+//        tenantDto.setDateUpdate(new Date());
+        tenantMapper.update(tenantDto);
+        //修改管理员信息
+        UserEntity userEntity =new UserEntity();
+        userEntity.setId(tenantDto.getUserId());
+        userEntity.setTenantId(tenantDto.getCode());//此字段到底取标识还是id
+        userEntity.setUpdateBy(tenantDto.getUpdateBy());
+        userEntity.setDateUpdate(new Date());
+        userEntity.setPhone(tenantDto.getPhone());
+        userEntity.setUsername(tenantDto.getUserName());
+        userService.updateUserById(userEntity);
+        //修改租户菜单信息
+        //界面传回的租户菜单id
+        List<Integer > newTenantMenuIds = tenantDto.getTenantMenuIds();
+        //数据库中已存在的租户菜单id
+        List<Integer > oldTenantMenuIds = tenantMapper.selectTenantMenuIds(tenantDto.getId());
+        //相同的暂时不改动
+
+        //新增的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);
+        }
+        //去掉的id(需要删除的)
+        List<Integer> deleteTenantMenuIds = oldTenantMenuIds.stream().filter(item -> !newTenantMenuIds.contains(item)).collect(Collectors.toList());
+        if(deleteTenantMenuIds.size()>0){
+            tenantMapper.deleteTenantMenuIds(tenantDto.getId(),deleteTenantMenuIds);
+        }
 
-        return this.tenantMapper.update(tenantEntity);
+        return 1;
     }
 
     /**
@@ -94,7 +161,9 @@ public class TenantServiceImpl implements TenantService {
      */
     @Override
     public int deleteById(Integer id) {
-        return this.tenantMapper.deleteById(id);
+        //先删除租户菜单
+        tenantMapper.deleteTenantMenuIds(id,null);
+        return tenantMapper.deleteById(id);
     }
 
     /**
@@ -104,7 +173,7 @@ public class TenantServiceImpl implements TenantService {
      */
     @Override
     public int count() {
-        return this.tenantMapper.count();
+        return tenantMapper.count();
     }
 
     /**
@@ -113,7 +182,7 @@ public class TenantServiceImpl implements TenantService {
      * @return 对象列表
      */
     @Override
-    public IPage<TenantEntity> selectPage(TenantEntity tenantEntity, IPage<TenantEntity> page) {
-        return this.tenantMapper.selectPage(page, tenantEntity);
+    public IPage<TenantDto> selectPage(IPage<TenantDto> page, TenantDto tenantDto) {
+        return tenantMapper.selectPage(page, tenantDto);
     }
 }

+ 6 - 6
user_center/src/main/resources/mapper/LoginLog.xml

@@ -147,23 +147,23 @@
         from uims_login_log a
         <include refid="loginLogJoins"/>
         <where>
-            <if test="id != null">
+            <if test="loginLogDto.id != null">
                 and a.id = #{loginLogDto.id}
             </if>
-            <if test="condition != null and condition != ''">
+            <if test="loginLogDto.condition != null and loginLogDto.condition != ''">
                 and (a.name like concat('%', #{loginLogDto.condition},'%')
                 or a.phone like concat('%', #{loginLogDto.condition},'%'))
             </if>
-            <if test="companyId != null">
+            <if test="loginLogDto.companyId != null">
                 and a.company_id = #{loginLogDto.companyId}
             </if>
-            <if test="departmentId != null">
+            <if test="loginLogDto.departmentId != null">
                 and a.DEPARTMENT_ID = #{loginLogDto.departmentId}
             </if>
-            <if test="beginTime != null">
+            <if test="loginLogDto.beginTime != null">
                 and a.create_time >= #{loginLogDto.beginTime}
             </if>
-            <if test="endTime != null">
+            <if test="loginLogDto.endTime != null">
                 and a.create_time &lt;= #{loginLogDto.endTime}
             </if>
         </where>

+ 6 - 6
user_center/src/main/resources/mapper/OperateLog.xml

@@ -143,23 +143,23 @@
         from uims_opr_log a
         <include refid="loginLogJoins"/>
         <where>
-            <if test="id != null">
+            <if test="operateLogDto.id != null">
                 and a.id = #{operateLogDto.id}
             </if>
-            <if test="condition != null and condition != ''">
+            <if test="operateLogDto.condition != null and operateLogDto.condition != ''">
                 and (a.USER_NAME like concat('%', #{operateLogDto.condition},'%')
                 or a.phone like concat('%', #{operateLogDto.condition},'%'))
             </if>
-            <if test="companyId != null">
+            <if test="operateLogDto.companyId != null">
                 and a.company_id = #{operateLogDto.companyId}
             </if>
-            <if test="departmentId != null">
+            <if test="operateLogDto.departmentId != null">
                 and a.DEPARTMENT_ID = #{operateLogDto.departmentId}
             </if>
-            <if test="beginTime != null">
+            <if test="operateLogDto.beginTime != null">
                 and a.create_time >= #{operateLogDto.beginTime}
             </if>
-            <if test="endTime != null">
+            <if test="operateLogDto.endTime != null">
                 and a.create_time &lt;= #{operateLogDto.endTime}
             </if>
         </where>

+ 68 - 25
user_center/src/main/resources/mapper/TenantMapper.xml

@@ -18,39 +18,47 @@
         <result property="dateUpdate" column="DATE_UPDATE" jdbcType="TIMESTAMP"/>
         <result property="updateBy" column="UPDATE_BY" jdbcType="VARCHAR"/>
     </resultMap>
+
     <sql id="Base_Column_List">
-        ID ,TENANT_NAME ,CODE ,LOGO ,WEB_URL ,START_DATE ,END_DATE ,TENANT_STATE ,REMARK ,STATUS ,DATE_CREATE ,CREATE_BY ,DATE_UPDATE ,UPDATE_BY
+        t.TENANT_NAME as "tenantName"
+        ,u.id as "userId"
+        ,u.USERNAME as "userName"
+        ,u.PHONE as "phone"
+        ,t.`CODE` as "code"
+        ,t.LOGO as "logo"
+        ,t.WEB_URL as "webUrl"
+        ,t.DATE_CREATE as "dateCreate"
     </sql>
 
-    <select id="selectById" resultMap="TenantMap">
+    <sql id="tenantJoins">
+        left join uims_user u on t.ID=u.TENANT_ID and u.USER_TYPE=2
+    </sql>
+    <select id="selectById" resultType="com.huaxu.dto.TenantDto">
         select
         <include refid="Base_Column_List"/>
-        from uims_tenant
-        where ID = #{id}
+        from uims_tenant t
+        <include refid="tenantJoins"/>
+        where t.ID = #{id}
     </select>
 
     <!-- 查询全部 -->
-    <select id="selectAll" resultMap="TenantMap">
+    <select id="selectAll" resultType="com.huaxu.dto.TenantDto">
         select
         <include refid="Base_Column_List"/>
-        from uims_tenant
+        from uims_tenant t
+        <include refid="tenantJoins"/>
     </select>
 
     <!--通过实体作为筛选条件查询-->
-    <select id="selectList" resultMap="TenantMap">
+    <select id="selectList" resultType="com.huaxu.dto.TenantDto">
         select
         <include refid="Base_Column_List"/>
-        from uims_tenant
+        from uims_tenant t
+        <include refid="tenantJoins"/>
         <where>
-            <if test="id != null">
-                and ID = #{id}
-            </if>
             <if test="tenantName != null and tenantName != ''">
                 and TENANT_NAME like concat('%',#{tenantName},'%')
             </if>
-            <if test="code != null and code != ''">
-                and CODE = #{code}
-            </if>
         </where>
     </select>
 
@@ -121,21 +129,56 @@
     <select id="count" resultType="int">
         select count(*) from uims_tenant
     </select>
-
-    <select id="selectPage" resultMap="TenantMap">
+    <!-- 分页查询 -->
+    <select id="selectPage" resultType="com.huaxu.dto.TenantDto">
         select
         <include refid="Base_Column_List"/>
-        from uims_tenant
+        from uims_tenant t
+        <include refid="tenantJoins"/>
         <where>
-            <if test="id != null">
-                and ID = #{app.id}
-            </if>
-            <if test="tenantName != null and tenantName != ''">
-                and TENANT_NAME like concat('%',#{app.tenantName},'%')
-            </if>
-            <if test="code != null and code != ''">
-                and CODE = #{app.code}
+            <if test="tenantDto.tenantName != null and tenantDto.tenantName != ''">
+                and t.TENANT_NAME like concat('%',#{tenantDto.tenantName},'%')
             </if>
         </where>
     </select>
+
+    <!-- 生成租户菜单 -->
+    <insert id="createTenantMenu">
+        insert into uims_tenant_menu (TENANT_ID ,MENU_ID ,MENU_NAME ,MENU_IMAGE ,MENU_SEQ ,LINK_PATH ,STATUS
+        ,DATE_CREATE ,CREATE_BY ,DATE_UPDATE ,UPDATE_BY)
+        select
+            #{tenantId},
+            id,
+            name,
+            menu_image,
+            seq,
+            LINK_PATH,
+            0,
+            now(),
+            #{userName},
+            now(),
+            #{userName}
+        from uims_menu
+        where id in (
+        <foreach collection="menuIds" item="item" index="index" separator=",">
+         #{item}
+        </foreach>
+        )
+    </insert>
+    <!-- 通过租户id查询租户菜单id -->
+    <select id="selectTenantMenuIds" resultType="java.lang.Integer">
+        select id from uims_tenant_menu where TENANT_ID = #{tenantId}
+    </select>
+
+    <delete id="deleteTenantMenuIds">
+    delete from uims_tenant_menu
+    where TENANT_ID=#{tenantId}
+    <if test="menuIds != null">
+        and  MENU_ID in (
+            <foreach collection="menuIds" item="item" index="index" separator=",">
+                #{item}
+            </foreach>
+        )
+    </if>
+    </delete>
 </mapper>