Commit b516760c by liqiuwei

调整mybaties使用用例

parent 29218419
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>matrix-sample-mybatis</artifactId>
<groupId>com.secoo.mall</groupId>
<version>2.0.1.RELEASE</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>matrix-sample-mybatis-biz</artifactId>
</project>
\ No newline at end of file
package com.secoo.mall.appms.bean.domain;
import com.alibaba.fastjson.annotation.JSONField;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.secoo.mall.common.core.bean.AbsBaseBean;
import com.secoo.mall.common.util.colletion.CollectionUtil;
import com.secoo.mall.common.util.json.FastJsonUtil;
import com.secoo.mall.common.util.string.StringUtil;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.Date;
import java.util.List;
//@ApiModel(value = "应用详细信息", description = "作用于project对象")
@Data
public class Project extends AbsBaseBean {
@ApiModelProperty(value = "应用id")
private Long id;
@ApiModelProperty(value = "仓库id")
private Long repositoryId;
@ApiModelProperty(value = "树id")
private Long opsTreeId;
@ApiModelProperty(value = "应用唯一标识")
private String name;
@ApiModelProperty(value = "应用中文名称")
private String cnName;
/**
* 如果sorce唯一用时间戳创建编码
*/
@ApiModelProperty(value = "应用编码")
private String code;
@ApiModelProperty(value = "应用等级:1-10,数值越大等级越低")
private Integer level;
/**
* 冗余字段
*/
@ApiModelProperty(value = "分组", position = 30)
private String groupName;
/**
* 冗余字段
*/
@ApiModelProperty(value = "gitlab地址", position = 40)
private String gitUrl;
/**
* 冗余字段
*/
@ApiModelProperty(value = "开发语言:1.java;2.lua;10、其他", position = 50)
private Integer language;
@JSONField(serialize = false)
private String tags;
@ApiModelProperty(value = "标签tags的参数形式")
@TableField(exist = false)
private List<String> tagList;
@ApiModelProperty(value = "备注")
private String remark;
@ApiModelProperty(value = "状态:0、删除 1、正常;")
private Integer status;
@ApiModelProperty(value = "负责人id")
private Long owner;
@ApiModelProperty(value = "负责人")
private String ownerName;
@ApiModelProperty(value = "创建人id")
private Long creater;
@ApiModelProperty(value = "创建人")
private String createrName;
@ApiModelProperty(value = "创建时间", hidden = true)
@TableField(fill = FieldFill.INSERT)
private Date createTime;
@ApiModelProperty(value = "修改时间", hidden = true)
private Date updateTime;
public List<String> getTagList() {
if (StringUtil.isNotEmpty(this.tags)) {
tagList = FastJsonUtil.toList(this.tags);
}
return tagList;
}
public void setTagList(List<String> tagList) {
if (CollectionUtil.isNotEmpty(tagList)) {
String tags = FastJsonUtil.toString(tagList);
this.setTags(tags);
}
this.tagList = tagList;
}
}
package com.secoo.mall.appms.bean.domain;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.secoo.mall.common.core.bean.AbsBaseBean;
import io.swagger.annotations.ApiModelProperty;
import java.util.Date;
//@ApiModel(value = "用户登录信息", description = "作用于user对象")
public class User extends AbsBaseBean {
@ApiModelProperty(value = "用户id")
private Long id;
@ApiModelProperty(value = "用户名")
private String name;
@ApiModelProperty(value = "中文用户名")
private String cnName;
@ApiModelProperty(value = "工号")
private String workNum;
@ApiModelProperty(value = "邮箱")
private String email;
@ApiModelProperty(value = "手机号")
private String mobile;
@ApiModelProperty(value = "角色类型:1、admin;2、owner;3、dev;4、guest")
private Integer roleType;
@ApiModelProperty(value = "备注")
private String remark;
@ApiModelProperty(value = "状态:0、删除 1、正常;")
private Integer status;
@ApiModelProperty(value = "创建时间", hidden = true)
@TableField(fill = FieldFill.INSERT)
private Date createTime;
@ApiModelProperty(value = "修改时间", hidden = true)
private Date updateTime;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Date getCreateTime() {
return createTime;
}
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
public Date getUpdateTime() {
return updateTime;
}
public void setUpdateTime(Date updateTime) {
this.updateTime = updateTime;
}
public String getEmail() {
return email;
}
public String getMobile() {
return mobile;
}
public String getRemark() {
return remark;
}
public Integer getStatus() {
return status;
}
public void setEmail(String email) {
this.email = email;
}
public void setMobile(String mobile) {
this.mobile = mobile;
}
public void setRemark(String remark) {
this.remark = remark;
}
public void setStatus(Integer status) {
this.status = status;
}
public String getCnName() {
return cnName;
}
public void setCnName(String cnName) {
this.cnName = cnName;
}
public Integer getRoleType() {
return roleType;
}
public void setRoleType(Integer roleType) {
this.roleType = roleType;
}
public String getWorkNum() {
return workNum;
}
public void setWorkNum(String workNum) {
this.workNum = workNum;
}
}
\ No newline at end of file
package com.secoo.mall.appms.bean.domain;
import com.alibaba.fastjson.annotation.JSONField;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.secoo.mall.common.core.bean.AbsBaseBean;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.Date;
//@ApiModel(value = "用户应用关联关系表", description = "作用于user和project对象")
@Data
public class UserProjectRelation extends AbsBaseBean {
@ApiModelProperty(value = "主键id")
private Long id;
@ApiModelProperty(value = "用户id")
private Long userId;
@ApiModelProperty(value = "应用id")
private Long projectId;
//冗余字段
@ApiModelProperty(value = "仓库id")
private Long repositoryId;
@ApiModelProperty(value = "角色类型:10、admin;20、owner;30、dev;40、guest")
private Integer roleType;
@ApiModelProperty(value = "接收报警标识。0、不接收,1、接收")
private Integer warnFlag;
@JSONField(serialize = false)
@ApiModelProperty(value = "报警接收渠道。用逗号分隔")
private String warnChannels;
@ApiModelProperty(value = "修改时间", hidden = true)
private Date updateTime;
@ApiModelProperty(value = "创建时间", hidden = true)
@TableField(fill = FieldFill.INSERT)
private Date createTime;
}
\ No newline at end of file
package com.secoo.mall.appms.bean.vo;
import com.secoo.mall.appms.bean.domain.UserProjectRelation;
import com.secoo.mall.appms.util.constant.UserProjectRelationConstant;
import com.secoo.mall.common.util.colletion.CollectionUtil;
import com.secoo.mall.common.util.json.FastJsonUtil;
import com.secoo.mall.common.util.string.StringUtil;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.List;
@Data
public class UserProjectRelationVo extends UserProjectRelation {
@ApiModelProperty(value = "用户Id")
private Long userId;
@ApiModelProperty(value = "用户名")
private String userName;
@ApiModelProperty(value = "中文用户名")
private String userCnName;
@ApiModelProperty(value = "工号")
private String workNum;
@ApiModelProperty(value = "邮箱")
private String email;
@ApiModelProperty(value = "手机号")
private String mobile;
@ApiModelProperty(value = "用于转换数组")
private List<Integer> warnChannelList;
/**
* 由view到db
*
* @param warnChannelList
*/
public void setWarnChannelList(List<Integer> warnChannelList) {
if (UserProjectRelationConstant.WarnFlag.REJECT.equals(this.getWarnFlag())) {
warnChannelList = null;
}
if (CollectionUtil.isNotEmpty(warnChannelList)) {
this.setWarnChannels(FastJsonUtil.toString(warnChannelList));
}
}
/**
* 由db到view
*
* @param warnChannels
*/
@Override
public void setWarnChannels(String warnChannels) {
if (StringUtil.isNotEmpty(warnChannels)) {
this.warnChannelList = FastJsonUtil.toList(warnChannels, Integer.class);
}
super.setWarnChannels(warnChannels);
}
}
\ No newline at end of file
package com.secoo.mall.mybatis.config;
/**
* @Description:
* @Copyright: Copyright (c) 2020 ALL RIGHTS RESERVED.
* @Company: Secoo
* @Author: qiuwei.li
* @CreateDate: 2020/4/8 10:27
* @UpdateDate: 2020/4/8 10:27
* @UpdateRemark: init
* @Version: 1.0
* @menu ${description}
*/
public class DataConfig {
}
package com.secoo.mall.appms.dao.mapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.secoo.mall.appms.bean.domain.User;
import com.secoo.mall.appms.util.constant.UserConstant;
import com.secoo.mall.common.util.string.StringUtil;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
@Mapper
public interface UserMapper extends BaseMapper<User> {
default User getByEmail(String email) {
return this.selectOne(new QueryWrapper<User>().lambda().eq(User::getEmail, email).last("limit 1"));
}
default User getByName(String name) {
return this.selectOne(new QueryWrapper<User>().lambda().eq(User::getName, name).last("limit 1"));
}
default List<User> getAllUsers() {
return this.selectList(new QueryWrapper<User>().lambda().eq(User::getStatus, UserConstant.Status.NORMAL));
}
default User getByMobile(String mobile) {
return this.selectOne(new QueryWrapper<User>().lambda().eq(User::getMobile, mobile).last("limit 1"));
}
default User getOne(User user) {
LambdaQueryWrapper<User> queryWrapper = new QueryWrapper<User>().lambda();
if (StringUtil.isNotEmpty(user.getName())) {
queryWrapper.eq(User::getName, user.getName()).or();
}
if (StringUtil.isNotEmpty(user.getWorkNum())) {
queryWrapper.eq(User::getWorkNum, user.getWorkNum()).or();
}
if (StringUtil.isNotEmpty(user.getEmail())) {
queryWrapper.eq(User::getEmail, user.getEmail()).or();
}
return this.selectOne(queryWrapper);
}
default IPage<User> search(User user, Page page) {
LambdaQueryWrapper<User> queryWrapper = new QueryWrapper<User>().lambda().ne(User::getStatus, UserConstant.Status.DELETE);
if (StringUtil.isNotEmpty(user.getName()) || StringUtil.isNotEmpty(user.getCnName()) || StringUtil.isNotEmpty(user.getWorkNum())) {
queryWrapper.and(wapper -> wapper.like(User::getName, user.getName())
.or().like(User::getCnName, user.getCnName())
.or().like(User::getWorkNum, user.getWorkNum()));
}
return this.selectPage(page, queryWrapper);
}
}
\ No newline at end of file
package com.secoo.mall.appms.dao.mapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.secoo.mall.appms.bean.domain.UserProjectRelation;
import com.secoo.mall.appms.bean.vo.UserProjectRelationVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
@Mapper
public interface UserProjectRelationMapper extends BaseMapper<UserProjectRelation> {
IPage<Object> getUsersByIdAndUser(long projectId, String name, String cnName);
List<UserProjectRelationVo> getUsersByProjectId(@Param("projectId") Long projectId);
List<UserProjectRelationVo> getWarnUsersByProjectId(@Param("projectId") Long projectId);
default List<UserProjectRelation> getByUserIdAndProjectIds(Long userId, List<Long> projectIds) {
return this.selectList(new QueryWrapper<UserProjectRelation>().lambda().eq(UserProjectRelation::getUserId, userId).in(UserProjectRelation::getProjectId, projectIds));
}
IPage<UserProjectRelationVo> searchByProjectId(Page<UserProjectRelationVo> page, @Param("projectId") Long projectId, @Param("relationVo") UserProjectRelationVo userProjectRelationVo);
default Integer getCntByReposIdAndUserId(Long repositoryId, Long userId) {
return this.selectCount(new QueryWrapper<UserProjectRelation>().lambda().eq(UserProjectRelation::getRepositoryId, repositoryId).eq(UserProjectRelation::getUserId, userId));
}
default UserProjectRelation getByProjectIdAndUserId(Long projectId, Long userId) {
return this.selectOne(new QueryWrapper<UserProjectRelation>().lambda().eq(UserProjectRelation::getProjectId, projectId).eq(UserProjectRelation::getUserId, userId));
}
default UserProjectRelation getByUserIdAndProjectId(Long userId, Long projectId) {
return this.selectOne(new QueryWrapper<UserProjectRelation>().lambda().eq(UserProjectRelation::getUserId, userId).eq(UserProjectRelation::getProjectId, projectId));
}
default Integer deleteByUserId(Long userId) {
return this.delete(new QueryWrapper<UserProjectRelation>().lambda().eq(UserProjectRelation::getUserId, userId));
}
default Integer deleteByProjectId(Long projectId) {
return this.delete(new QueryWrapper<UserProjectRelation>().lambda().eq(UserProjectRelation::getProjectId, projectId));
}
}
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.secoo.mall.appms.dao.mapper.UserProjectRelationMapper">
<sql id="base_feild_List">
id, user_id , project_id, update_time, create_time
</sql>
<sql id="user_map_field_List">
b.id,a.id as userId, a.name as userName,a.work_num,a.cn_name as userCnName,a.email ,a.mobile,b.role_type as roleType,b.warn_flag ,b.warn_channels
</sql>
<sql id="search_where">
<where>
<if test="relationVo.userName != null and relationVo.userName != ''">
AND a.name =TRIM(#{relationVo.userName,jdbcType=VARCHAR})
</if>
</where>
</sql>
<select id="getUsersByProjectId" resultType="com.secoo.mall.appms.bean.vo.UserProjectRelationVo">
select
<include refid="user_map_field_List"/>
from user a inner join user_project_relation b on a.id=b.user_id and b.project_id=#{projectId}
</select>
<select id="getWarnUsersByProjectId" resultType="com.secoo.mall.appms.bean.vo.UserProjectRelationVo">
select
<include refid="user_map_field_List"/>
from user a inner join user_project_relation b on a.id=b.user_id and b.project_id=#{projectId} and b.warn_flag=1
</select>
<select id="searchByProjectId" resultType="com.secoo.mall.appms.bean.vo.UserProjectRelationVo">
select
<include refid="user_map_field_List"/>
from user a inner join user_project_relation b on a.id=b.user_id and b.project_id=#{projectId}
<include refid="search_where"/>
</select>
<!--
<select id="getUsersByIdAndUser" resultType="java.util.Map"
parameterType="com.secoo.mall.appms.bean.vo.UserProjectVo">
SELECT
u.id,
u.name,
u.email,
u.mobile,
u.remark,
u.cn_name as 'cnName',
u.work_num as 'workNum',
u.status,
u.create_time as 'createTime',
u.update_time as 'updateTime'
FROM
user_project_relation up
INNER JOIN user u on u.id = up.user_id
INNER JOIN project p on p.id = up.project_id
WHERE 1=1
<if test="projectId != null">
and p.id = #{projectId,jdbcType=BIGINT}
</if>
<if test="name != null">
and u.name like CONCAT('%',TRIM(#{name,jdbcType=VARCHAR}),'%')
</if>
<if test="cnName != null">
and u.cn_name like CONCAT('%',TRIM(#{cnName,jdbcType=VARCHAR}),'%')
</if>
GROUP BY u.id
</select>
<select id="search" resultType="java.util.Map"
parameterType="com.secoo.mall.appms.bean.vo.UserProjectVo">
SELECT
up.id,
up.user_id,
up.project_id,
up.update_time ,
up.create_time ,
u.name as 'user_name',
u.email,
u.mobile,
u.remark as 'user_remark',
u.status as 'user_status',
u.create_time as 'user_create_time',
u.update_time as 'user_update_time',
p.name as 'project_name',
p.git_url ,
p.group_name ,
p.owner_id ,
p.owner_name ,
p.remark as 'project_remark',
p.status as 'project_status',
p.create_time as 'project_create_time',
p.update_time as 'project_update_time'
FROM
user_project_relation up
INNER JOIN user u on u.id = up.user_id
INNER JOIN project p on p.id = up.project_id
WHERE 1=1
<if test="id != null">
and up.id = #{id,jdbcType=BIGINT}
</if>
<if test="userId != null">
and u.id = #{userId,jdbcType=BIGINT}
</if>
<if test="projectId != null">
and p.id = #{projectId,jdbcType=BIGINT}
</if>
<if test="owner != null">
and p.owner_id = #{owner,jdbcType=BIGINT}
</if>
<if test="userName != null">
and u.name like CONCAT('%',TRIM(#{userName,jdbcType=VARCHAR}),'%')
</if>
<if test="email != null">
and u.email like CONCAT('%',TRIM(#{email,jdbcType=VARCHAR}),'%')
</if>
<if test="mobile != null">
and u.mobile like CONCAT('%',TRIM(#{mobile,jdbcType=VARCHAR}),'%')
</if>
<if test="projectName != null">
and p.name like CONCAT('%',TRIM(#{projectName,jdbcType=VARCHAR}),'%')
</if>
<if test="gitUrl != null">
and p.git_url like CONCAT('%',TRIM(#{gitUrl,jdbcType=VARCHAR}),'%')
</if>
<if test="groupName != null">
and p.group_name like CONCAT('%',TRIM(#{groupName,jdbcType=VARCHAR}),'%')
</if>
<if test="ownerName != null">
and p.owner_name like CONCAT('%',TRIM(#{ownerName,jdbcType=VARCHAR}),'%')
</if>
<if test="ascSort != null and descSort == null ">
order by ${ascSort} asc
</if>
<if test="descSort != null and ascSort == null ">
order by ${descSort} desc
</if>
<if test="descSort != null and ascSort != null ">
order by ${ascSort} asc,${descSort} desc
</if>
limit #{page,jdbcType=BIGINT},#{pageSize,jdbcType=BIGINT}
</select>-->
</mapper>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>matrix-sample-mybatis</artifactId>
<groupId>com.secoo.mall</groupId>
<version>2.0.1.RELEASE</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>matrix-sample-mybatis-spring</artifactId>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>matrix-sample-mybatis</artifactId>
<groupId>com.secoo.mall</groupId>
<version>2.0.1.RELEASE</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>matrix-sample-mybatis-springboot</artifactId>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>matrix-sample</artifactId>
<groupId>com.secoo.mall</groupId>
<version>2.0.1.RELEASE</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>matrix-sample-mybaties</artifactId>
</project>
\ No newline at end of file
......@@ -18,6 +18,7 @@
<dependency>
<groupId>com.secoo.mall</groupId>
<artifactId>matrix-datahelper-redis-starter</artifactId>
<version>2.0.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment