Commit 512a3cb7 authored by shiyu's avatar shiyu

Merge remote-tracking branch 'origin/master'

parents 303d8f91 fe971e58
......@@ -73,7 +73,6 @@
<version>1.3.7</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
......
package com.wwdz.ch.db.dao;
import com.wwdz.ch.db.domain.FavoritesCoinsRelation;
import com.wwdz.ch.db.domain.FavoritesCoinsRelationExample;
import java.util.List;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
@Mapper
public interface FavoritesCoinsRelationMapper {
long countByExample(FavoritesCoinsRelationExample example);
int deleteByExample(FavoritesCoinsRelationExample example);
int insert(FavoritesCoinsRelation record);
int batchInsert(List<FavoritesCoinsRelation> list);
int insertSelective(FavoritesCoinsRelation record);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table favorites_coins_relation
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
FavoritesCoinsRelation selectOneByExample(FavoritesCoinsRelationExample example);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table favorites_coins_relation
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
FavoritesCoinsRelation selectOneByExampleSelective(@Param("example") FavoritesCoinsRelationExample example, @Param("selective") FavoritesCoinsRelation.Column ... selective);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table favorites_coins_relation
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
List<FavoritesCoinsRelation> selectByExampleSelective(@Param("example") FavoritesCoinsRelationExample example, @Param("selective") FavoritesCoinsRelation.Column ... selective);
List<FavoritesCoinsRelation> selectByExample(FavoritesCoinsRelationExample example);
int updateByExampleSelective(@Param("record") FavoritesCoinsRelation record, @Param("example") FavoritesCoinsRelationExample example);
int updateByExample(@Param("record") FavoritesCoinsRelation record, @Param("example") FavoritesCoinsRelationExample example);
}
\ No newline at end of file
package com.wwdz.ch.db.dao;
import com.wwdz.ch.db.domain.Favorites;
import com.wwdz.ch.db.domain.FavoritesExample;
import java.util.List;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
@Mapper
public interface FavoritesMapper {
long countByExample(FavoritesExample example);
int deleteByExample(FavoritesExample example);
int deleteByPrimaryKey(Long id);
int insert(Favorites record);
int insertSelective(Favorites record);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table favorites
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
Favorites selectOneByExample(FavoritesExample example);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table favorites
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
Favorites selectOneByExampleSelective(@Param("example") FavoritesExample example, @Param("selective") Favorites.Column ... selective);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table favorites
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
Favorites selectOneByExampleWithBLOBs(FavoritesExample example);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table favorites
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
List<Favorites> selectByExampleSelective(@Param("example") FavoritesExample example, @Param("selective") Favorites.Column ... selective);
List<Favorites> selectByExampleWithBLOBs(FavoritesExample example);
List<Favorites> selectByExample(FavoritesExample example);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table favorites
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
Favorites selectByPrimaryKeySelective(@Param("id") Long id, @Param("selective") Favorites.Column ... selective);
Favorites selectByPrimaryKey(Long id);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table favorites
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
Favorites selectByPrimaryKeyWithLogicalDelete(@Param("id") Long id, @Param("andLogicalDeleted") boolean andLogicalDeleted);
int updateByExampleSelective(@Param("record") Favorites record, @Param("example") FavoritesExample example);
int updateByExampleWithBLOBs(@Param("record") Favorites record, @Param("example") FavoritesExample example);
int updateByExample(@Param("record") Favorites record, @Param("example") FavoritesExample example);
int updateByPrimaryKeySelective(Favorites record);
int updateByPrimaryKeyWithBLOBs(Favorites record);
int updateByPrimaryKey(Favorites record);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table favorites
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
int logicalDeleteByExample(@Param("example") FavoritesExample example);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table favorites
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
int logicalDeleteByPrimaryKey(Long id);
}
\ No newline at end of file
This diff is collapsed.
package com.wwdz.ch.db.domain;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import lombok.Data;
/**
* @author shiyu
* @date 2023/07/18
*/
@Data
public class FavoritesCoinsRelation implements Serializable {
/**
* 收藏册id
*/
private Long favoritesId;
/**
* 钱币id
*/
private Long coinsId;
private static final long serialVersionUID = 1L;
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(getClass().getSimpleName());
sb.append(" [");
sb.append("Hash = ").append(hashCode());
sb.append(", favoritesId=").append(favoritesId);
sb.append(", coinsId=").append(coinsId);
sb.append(", serialVersionUID=").append(serialVersionUID);
sb.append("]");
return sb.toString();
}
@Override
public boolean equals(Object that) {
if (this == that) {
return true;
}
if (that == null) {
return false;
}
if (getClass() != that.getClass()) {
return false;
}
FavoritesCoinsRelation other = (FavoritesCoinsRelation) that;
return (this.getFavoritesId() == null ? other.getFavoritesId() == null : this.getFavoritesId().equals(other.getFavoritesId()))
&& (this.getCoinsId() == null ? other.getCoinsId() == null : this.getCoinsId().equals(other.getCoinsId()));
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((getFavoritesId() == null) ? 0 : getFavoritesId().hashCode());
result = prime * result + ((getCoinsId() == null) ? 0 : getCoinsId().hashCode());
return result;
}
/**
* This enum was generated by MyBatis Generator.
* This enum corresponds to the database table favorites_coins_relation
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
public enum Column {
favoritesId("favorites_id", "favoritesId", "BIGINT", false),
coinsId("coins_id", "coinsId", "BIGINT", false);
/**
* This field was generated by MyBatis Generator.
* This field corresponds to the database table favorites_coins_relation
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
private static final String BEGINNING_DELIMITER = "`";
/**
* This field was generated by MyBatis Generator.
* This field corresponds to the database table favorites_coins_relation
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
private static final String ENDING_DELIMITER = "`";
/**
* This field was generated by MyBatis Generator.
* This field corresponds to the database table favorites_coins_relation
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
private final String column;
/**
* This field was generated by MyBatis Generator.
* This field corresponds to the database table favorites_coins_relation
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
private final boolean isColumnNameDelimited;
/**
* This field was generated by MyBatis Generator.
* This field corresponds to the database table favorites_coins_relation
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
private final String javaProperty;
/**
* This field was generated by MyBatis Generator.
* This field corresponds to the database table favorites_coins_relation
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
private final String jdbcType;
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table favorites_coins_relation
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
public String value() {
return this.column;
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table favorites_coins_relation
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
public String getValue() {
return this.column;
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table favorites_coins_relation
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
public String getJavaProperty() {
return this.javaProperty;
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table favorites_coins_relation
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
public String getJdbcType() {
return this.jdbcType;
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table favorites_coins_relation
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
Column(String column, String javaProperty, String jdbcType, boolean isColumnNameDelimited) {
this.column = column;
this.javaProperty = javaProperty;
this.jdbcType = jdbcType;
this.isColumnNameDelimited = isColumnNameDelimited;
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table favorites_coins_relation
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
public String desc() {
return this.getEscapedColumnName() + " DESC";
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table favorites_coins_relation
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
public String asc() {
return this.getEscapedColumnName() + " ASC";
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table favorites_coins_relation
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
public static Column[] excludes(Column ... excludes) {
ArrayList<Column> columns = new ArrayList<>(Arrays.asList(Column.values()));
if (excludes != null && excludes.length > 0) {
columns.removeAll(new ArrayList<>(Arrays.asList(excludes)));
}
return columns.toArray(new Column[]{});
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table favorites_coins_relation
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
public String getEscapedColumnName() {
if (this.isColumnNameDelimited) {
return new StringBuilder().append(BEGINNING_DELIMITER).append(this.column).append(ENDING_DELIMITER).toString();
} else {
return this.column;
}
}
}
}
\ No newline at end of file
package com.wwdz.ch.db.service;
import com.github.pagehelper.PageInfo;
import com.wwdz.ch.db.domain.FavoritesCoinsRelation;
import java.util.List;
public interface FavoritesCoinsRelationDao {
int add(FavoritesCoinsRelation record);
int batchAdd(List<FavoritesCoinsRelation> list);
int deleteByFavoritesId(Long favoritesId, List<Long> favoritesIds);
List<FavoritesCoinsRelation> listByFavoritesId(Long favoritesId, List<Long> favoritesIds);
PageInfo<FavoritesCoinsRelation> pageByFavoritesId(Long favoritesId, int page, int size);
}
package com.wwdz.ch.db.service;
import com.github.pagehelper.PageInfo;
import com.wwdz.ch.db.domain.Favorites;
import java.util.List;
public interface FavoritesDao {
int add(Favorites record);
int delete(Long id);
int update(Favorites record);
Favorites info(Long id);
PageInfo<Favorites> pageByUid(Long uid, int page, int size);
boolean isExisted(Long id, Long uid, String title);
int delete(Long id, List<Long> ids);
}
package com.wwdz.ch.db.service.impl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wwdz.ch.db.dao.FavoritesCoinsRelationMapper;
import com.wwdz.ch.db.domain.FavoritesCoinsRelation;
import com.wwdz.ch.db.domain.FavoritesCoinsRelationExample;
import com.wwdz.ch.db.service.FavoritesCoinsRelationDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.util.CollectionUtils;
import java.util.List;
@Repository
public class FavoritesCoinsRelationDaoImpl implements FavoritesCoinsRelationDao {
@Autowired
private FavoritesCoinsRelationMapper favoritesCoinsRelationMapper;
@Override
public int add(FavoritesCoinsRelation record) {
return favoritesCoinsRelationMapper.insert(record);
}
@Override
public int batchAdd(List<FavoritesCoinsRelation> list) {
return favoritesCoinsRelationMapper.batchInsert(list);
}
@Override
public int deleteByFavoritesId(Long favoritesId, List<Long> favoritesIds) {
FavoritesCoinsRelationExample example = new FavoritesCoinsRelationExample();
FavoritesCoinsRelationExample.Criteria criteria = example.createCriteria();
if (!CollectionUtils.isEmpty(favoritesIds)) {
criteria.andFavoritesIdIn(favoritesIds);
} else {
criteria.andFavoritesIdEqualTo(favoritesId);
}
return favoritesCoinsRelationMapper.deleteByExample(example);
}
@Override
public List<FavoritesCoinsRelation> listByFavoritesId(Long favoritesId, List<Long> favoritesIds) {
FavoritesCoinsRelationExample example = new FavoritesCoinsRelationExample();
FavoritesCoinsRelationExample.Criteria criteria = example.createCriteria();
if (!CollectionUtils.isEmpty(favoritesIds)) {
criteria.andFavoritesIdIn(favoritesIds);
} else {
criteria.andFavoritesIdEqualTo(favoritesId);
}
return favoritesCoinsRelationMapper.selectByExample(example);
}
@Override
public PageInfo<FavoritesCoinsRelation> pageByFavoritesId(Long favoritesId, int page, int size) {
FavoritesCoinsRelationExample example = new FavoritesCoinsRelationExample();
FavoritesCoinsRelationExample.Criteria criteria = example.createCriteria();
criteria.andFavoritesIdEqualTo(favoritesId);
PageHelper.startPage(page, size);
List<FavoritesCoinsRelation> list = favoritesCoinsRelationMapper.selectByExample(example);
return new PageInfo<>(list);
}
}
package com.wwdz.ch.db.service.impl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wwdz.ch.db.dao.FavoritesMapper;
import com.wwdz.ch.db.domain.Favorites;
import com.wwdz.ch.db.domain.FavoritesExample;
import com.wwdz.ch.db.service.FavoritesDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.util.CollectionUtils;
import java.util.Date;
import java.util.List;
import java.util.Objects;
@Repository
public class FavoritesDaoImpl implements FavoritesDao {
@Autowired
private FavoritesMapper favoritesMapper;
@Override
public int add(Favorites record) {
return favoritesMapper.insert(record);
}
@Override
public int delete(Long id) {
return favoritesMapper.deleteByPrimaryKey(id);
}
@Override
public int update(Favorites record) {
return favoritesMapper.updateByPrimaryKey(record);
}
@Override
public Favorites info(Long id) {
FavoritesExample example = new FavoritesExample();
FavoritesExample.Criteria criteria = example.createCriteria();
criteria.andIdEqualTo(id);
criteria.andDeletedEqualTo(false);
return favoritesMapper.selectByPrimaryKey(id);
}
@Override
public PageInfo<Favorites> pageByUid(Long uid, int page, int size) {
FavoritesExample example = new FavoritesExample();
FavoritesExample.Criteria criteria = example.createCriteria();
criteria.andUidEqualTo(uid);
criteria.andDeletedEqualTo(false);
PageHelper.startPage(page, size);
List<Favorites> list = favoritesMapper.selectByExample(example);
return new PageInfo<>(list);
}
@Override
public boolean isExisted(Long id, Long uid, String title) {
FavoritesExample example = new FavoritesExample();
FavoritesExample.Criteria criteria = example.createCriteria();
criteria.andUidEqualTo(uid);
criteria.andTitleEqualTo(title);
criteria.andDeletedEqualTo(false);
if (Objects.nonNull(id)) {
criteria.andIdNotEqualTo(id);
}
return favoritesMapper.countByExample(example) > 0;
}
@Override
public int delete(Long id, List<Long> ids) {
FavoritesExample example = new FavoritesExample();
FavoritesExample.Criteria criteria = example.createCriteria();
if (!CollectionUtils.isEmpty(ids)) {
criteria.andIdIn(ids);
} else {
criteria.andIdEqualTo(id);
}
Favorites favorites = new Favorites();
favorites.setDeleted(true);
favorites.setUpdateTime(new Date());
return favoritesMapper.updateByExampleSelective(favorites, example);
}
}
<?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.wwdz.ch.db.dao.FavoritesCoinsRelationMapper">
<resultMap id="BaseResultMap" type="com.wwdz.ch.db.domain.FavoritesCoinsRelation">
<result column="favorites_id" jdbcType="BIGINT" property="favoritesId" />
<result column="coins_id" jdbcType="BIGINT" property="coinsId" />
</resultMap>
<sql id="Example_Where_Clause">
<where>
<foreach collection="oredCriteria" item="criteria" separator="or">
<if test="criteria.valid">
<trim prefix="(" prefixOverrides="and" suffix=")">
<foreach collection="criteria.criteria" item="criterion">
<choose>
<when test="criterion.noValue">
and ${criterion.condition}
</when>
<when test="criterion.singleValue">
and ${criterion.condition} #{criterion.value}
</when>
<when test="criterion.betweenValue">
and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
</when>
<when test="criterion.listValue">
and ${criterion.condition}
<foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
#{listItem}
</foreach>
</when>
</choose>
</foreach>
</trim>
</if>
</foreach>
</where>
</sql>
<sql id="Update_By_Example_Where_Clause">
<where>
<foreach collection="example.oredCriteria" item="criteria" separator="or">
<if test="criteria.valid">
<trim prefix="(" prefixOverrides="and" suffix=")">
<foreach collection="criteria.criteria" item="criterion">
<choose>
<when test="criterion.noValue">
and ${criterion.condition}
</when>
<when test="criterion.singleValue">
and ${criterion.condition} #{criterion.value}
</when>
<when test="criterion.betweenValue">
and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
</when>
<when test="criterion.listValue">
and ${criterion.condition}
<foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
#{listItem}
</foreach>
</when>
</choose>
</foreach>
</trim>
</if>
</foreach>
</where>
</sql>
<sql id="Base_Column_List">
favorites_id, coins_id
</sql>
<select id="selectByExample" parameterType="com.wwdz.ch.db.domain.FavoritesCoinsRelationExample" resultMap="BaseResultMap">
select
<if test="distinct">
distinct
</if>
'true' as QUERYID,
<include refid="Base_Column_List" />
from favorites_coins_relation
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
</if>
<if test="orderByClause != null">
order by ${orderByClause}
</if>
</select>
<select id="selectByExampleSelective" parameterType="map" resultMap="BaseResultMap">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
@project https://github.com/itfsw/mybatis-generator-plugin
-->
select
'true' as QUERYID,
<if test="example.distinct">
distinct
</if>
<choose>
<when test="selective != null and selective.length > 0">
<foreach collection="selective" item="column" separator=",">
${column.escapedColumnName}
</foreach>
</when>
<otherwise>
favorites_id, coins_id
</otherwise>
</choose>
from favorites_coins_relation
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
</if>
<if test="example.orderByClause != null">
order by ${example.orderByClause}
</if>
</select>
<delete id="deleteByExample" parameterType="com.wwdz.ch.db.domain.FavoritesCoinsRelationExample">
delete from favorites_coins_relation
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
</if>
</delete>
<insert id="insert" parameterType="com.wwdz.ch.db.domain.FavoritesCoinsRelation">
insert into favorites_coins_relation (favorites_id, coins_id)
values (#{favoritesId,jdbcType=BIGINT}, #{coinsId,jdbcType=BIGINT})
</insert>
<insert id="batchInsert" parameterType="com.wwdz.ch.db.domain.FavoritesCoinsRelation">
insert into favorites_coins_relation (favorites_id, coins_id)
values
<foreach collection="list" item="item" separator=",">
(#{item.favoritesId,jdbcType=BIGINT}, #{item.coinsId,jdbcType=BIGINT})
</foreach>
</insert>
<insert id="insertSelective" parameterType="com.wwdz.ch.db.domain.FavoritesCoinsRelation">
insert into favorites_coins_relation
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="favoritesId != null">
favorites_id,
</if>
<if test="coinsId != null">
coins_id,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="favoritesId != null">
#{favoritesId,jdbcType=BIGINT},
</if>
<if test="coinsId != null">
#{coinsId,jdbcType=BIGINT},
</if>
</trim>
</insert>
<select id="countByExample" parameterType="com.wwdz.ch.db.domain.FavoritesCoinsRelationExample" resultType="java.lang.Long">
select count(*) from favorites_coins_relation
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
</if>
</select>
<update id="updateByExampleSelective" parameterType="map">
update favorites_coins_relation
<set>
<if test="record.favoritesId != null">
favorites_id = #{record.favoritesId,jdbcType=BIGINT},
</if>
<if test="record.coinsId != null">
coins_id = #{record.coinsId,jdbcType=BIGINT},
</if>
</set>
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
</if>
</update>
<update id="updateByExample" parameterType="map">
update favorites_coins_relation
set favorites_id = #{record.favoritesId,jdbcType=BIGINT},
coins_id = #{record.coinsId,jdbcType=BIGINT}
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
</if>
</update>
<select id="selectOneByExample" parameterType="com.wwdz.ch.db.domain.FavoritesCoinsRelationExample" resultMap="BaseResultMap">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
@project https://github.com/itfsw/mybatis-generator-plugin
-->
select
'true' as QUERYID,
<include refid="Base_Column_List" />
from favorites_coins_relation
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
</if>
<if test="orderByClause != null">
order by ${orderByClause}
</if>
limit 1
</select>
<select id="selectOneByExampleSelective" parameterType="map" resultMap="BaseResultMap">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
@project https://github.com/itfsw/mybatis-generator-plugin
-->
select
'true' as QUERYID,
<choose>
<when test="selective != null and selective.length > 0">
<foreach collection="selective" item="column" separator=",">
${column.escapedColumnName}
</foreach>
</when>
<otherwise>
favorites_id, coins_id
</otherwise>
</choose>
from favorites_coins_relation
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
</if>
<if test="example.orderByClause != null">
order by ${example.orderByClause}
</if>
limit 1
</select>
</mapper>
\ No newline at end of file
......@@ -70,6 +70,12 @@
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.24</version>
</dependency>
</dependencies>
<build>
......
package com.wwdz.ch.wx.entity.request;
import com.github.pagehelper.Page;
import com.xxdxxs.support.Delete;
import com.xxdxxs.support.Insert;
import com.xxdxxs.support.Select;
import com.xxdxxs.support.Update;
import lombok.Data;
import org.hibernate.validator.constraints.Length;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.util.List;
@Data
public class FavoritesRequestDto implements Serializable {
private static final long serialVersionUID = 1L;
@NotNull(groups = {Update.class, Select.class}, message = "id不能为空")
private Long id;
@NotBlank(groups = {Insert.class, Update.class}, message = "标题不能为空")
@Length(groups = {Insert.class, Update.class}, max = 20, message = "标题字数不能超过20个字符")
private String title;
@Length(groups = {Insert.class, Update.class}, max = 200, message = "描述字数不能超过200个字符")
private String description;
private String images;
@NotNull(groups = {Insert.class, Update.class, Page.class, Delete.class}, message = "用户id不能为空")
private Long uid;
@NotNull(groups = Page.class, message = "当前页不能为空")
private Integer page;
@NotNull(groups = Page.class, message = "页面大小不能为空")
private Integer size;
private List<Long> ids;
}
package com.wwdz.ch.wx.service;
import com.wwdz.ch.wx.entity.request.FavoritesRequestDto;
public interface FavoritesService {
Object page(FavoritesRequestDto dto);
Object add(FavoritesRequestDto dto);
Object update(FavoritesRequestDto dto);
Object info(FavoritesRequestDto dto);
Object delete(FavoritesRequestDto dto);
Object batchDelete(FavoritesRequestDto dto);
}
package com.wwdz.ch.wx.service.impl;
import com.wwdz.ch.core.util.ResponseUtil;
import com.wwdz.ch.db.domain.Favorites;
import com.wwdz.ch.db.domain.FavoritesCoinsRelation;
import com.wwdz.ch.db.service.FavoritesCoinsRelationDao;
import com.wwdz.ch.db.service.FavoritesDao;
import com.wwdz.ch.wx.entity.request.FavoritesRequestDto;
import com.wwdz.ch.wx.service.FavoritesService;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
import java.util.Date;
import java.util.List;
import java.util.Objects;
@Service
public class FavoritesServiceImpl implements FavoritesService {
private static final Logger logger = LoggerFactory.getLogger(FavoritesServiceImpl.class);
@Autowired
private FavoritesDao favoritesDao;
@Autowired
private FavoritesCoinsRelationDao favoritesCoinsRelationDao;
@Override
public Object page(FavoritesRequestDto dto) {
try {
return ResponseUtil.ok(favoritesDao.pageByUid(dto.getUid(), dto.getPage(), dto.getSize()));
} catch (Exception e) {
logger.error("查询收藏册列表失败,原因:" + e.getMessage(), e);
return ResponseUtil.fail(-1, "查询收藏册列表失败");
}
}
@Transactional(rollbackFor = Exception.class)
@Override
public Object add(FavoritesRequestDto dto) {
try {
// 判断收藏册标题是否已存在
if (favoritesDao.isExisted(null, dto.getUid(), dto.getTitle())) {
return ResponseUtil.fail(-1, "收藏册的标题不能重复");
}
Favorites favorites = new Favorites();
favorites.setUid(dto.getUid());
favorites.setTitle(dto.getTitle());
favorites.setDescription(dto.getDescription());
favorites.setImages(dto.getImages());
Date date = new Date();
favorites.setAddTime(date);
favorites.setUpdateTime(date);
favorites.setDeleted(false);
favoritesDao.add(favorites);
return ResponseUtil.ok();
} catch (Exception e) {
logger.error("新增收藏册失败,原因:" + e.getMessage(), e);
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
return ResponseUtil.fail(-1, "新增收藏册失败");
}
}
@Transactional(rollbackFor = Exception.class)
@Override
public Object update(FavoritesRequestDto dto) {
try {
Favorites favorites = favoritesDao.info(dto.getId());
if (Objects.isNull(favorites)) {
return ResponseUtil.fail(-1, "数据异常,记录不存在");
}
// 判断收藏册标题是否已存在
if (favoritesDao.isExisted(dto.getId(), dto.getUid(), dto.getTitle())) {
return ResponseUtil.fail(-1, "收藏册的标题不能重复");
}
favorites.setTitle(dto.getTitle());
favorites.setDescription(dto.getDescription());
favorites.setImages(dto.getImages());
favorites.setUpdateTime(new Date());
favoritesDao.update(favorites);
return ResponseUtil.ok();
} catch (Exception e) {
logger.error("新增收藏册失败,原因:" + e.getMessage(), e);
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
return ResponseUtil.fail(-1, "新增收藏册失败");
}
}
@Override
public Object info(FavoritesRequestDto dto) {
try {
Favorites favorites = favoritesDao.info(dto.getId());
if (Objects.isNull(favorites)) {
return ResponseUtil.fail(-1, "数据异常,记录不存在");
}
return ResponseUtil.ok(favorites);
} catch (Exception e) {
logger.error("查看收藏册详情失败,原因:" + e.getMessage(), e);
return ResponseUtil.fail(-1, "查看收藏册详情失败");
}
}
@Transactional(rollbackFor = Exception.class)
@Override
public Object delete(FavoritesRequestDto dto) {
try {
List<FavoritesCoinsRelation> list = favoritesCoinsRelationDao.listByFavoritesId(dto.getId(), null);
if (CollectionUtils.isNotEmpty(list)) {
return ResponseUtil.fail(-1, "收藏册内有藏品,清先移除藏品");
}
//TODO 删除该收藏册下用户创建的钱币
// 删除收藏册和钱币的关联
favoritesCoinsRelationDao.deleteByFavoritesId(dto.getId(), null);
// 删除收藏册
favoritesDao.delete(dto.getId(), null);
return ResponseUtil.ok();
} catch (Exception e) {
logger.error("批量删除收藏册失败,原因:" + e.getMessage(), e);
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
return ResponseUtil.fail(-1, "批量删除收藏册失败");
}
}
@Transactional(rollbackFor = Exception.class)
@Override
public Object batchDelete(FavoritesRequestDto dto) {
try {
List<FavoritesCoinsRelation> list = favoritesCoinsRelationDao.listByFavoritesId(null, dto.getIds());
//TODO 删除该收藏册下用户创建的钱币
// 删除收藏册和钱币的关联
favoritesCoinsRelationDao.deleteByFavoritesId(null, dto.getIds());
// 删除收藏册
favoritesDao.delete(null, dto.getIds());
return ResponseUtil.ok();
} catch (Exception e) {
logger.error("批量删除收藏册失败,原因:" + e.getMessage(), e);
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
return ResponseUtil.fail(-1, "批量删除收藏册失败");
}
}
}
package com.wwdz.ch.wx.web;
import com.github.pagehelper.Page;
import com.wwdz.ch.core.util.ResponseUtil;
import com.wwdz.ch.wx.entity.request.FavoritesRequestDto;
import com.wwdz.ch.wx.service.FavoritesService;
import com.xxdxxs.support.Delete;
import com.xxdxxs.support.Insert;
import com.xxdxxs.support.Select;
import com.xxdxxs.support.Update;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.Objects;
@RestController
@RequestMapping("/wx/favorites")
public class WxFavoritesController {
private static final Logger logger = LoggerFactory.getLogger(WxFavoritesController.class);
@Autowired
private FavoritesService favoritesService;
@PostMapping("/page")
public Object page(@RequestBody @Validated(Page.class)FavoritesRequestDto dto) {
return favoritesService.page(dto);
}
@PostMapping("/add")
public Object add(@RequestBody @Validated(Insert.class)FavoritesRequestDto dto) {
return favoritesService.add(dto);
}
@PostMapping("/update")
public Object update(@RequestBody @Validated(Update.class)FavoritesRequestDto dto) {
return favoritesService.update(dto);
}
@PostMapping("/info")
public Object info(@RequestBody @Validated(Select.class) FavoritesRequestDto dto) {
return favoritesService.info(dto);
}
@PostMapping("/delete")
public Object delete(@RequestBody @Validated(Delete.class) FavoritesRequestDto dto) {
if (Objects.isNull(dto.getId())) {
return ResponseUtil.fail(-1, "id不能为空");
}
return favoritesService.delete(dto);
}
@PostMapping("/batchDelete")
public Object batchDelete(@RequestBody @Validated(Delete.class) FavoritesRequestDto dto) {
if (CollectionUtils.isEmpty(dto.getIds())) {
return ResponseUtil.fail(-1, "请选择收藏册");
}
return favoritesService.batchDelete(dto);
}
}
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