Commit ef049323 authored by Fei 张飞's avatar Fei 张飞

实习生java后端培训开发demo

parent 5445eec3
package com.elitesland.itm.param;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
/**
* 品牌(ItmBrand)实体类
*
* @author roman.zhang
* @since 2020-08-17 14:37:45
*/
@Data
@ApiModel(value = "itm_brand", description = "品牌")
public class ItmBrandCreateParam implements Serializable {
private static final long serialVersionUID = 249853184090234468L;
/**
* 唯一编号ID
*/
@ApiModelProperty("唯一编号ID")
private Long id;
/**
* 品牌代码
*/
@ApiModelProperty("品牌代码")
private String brandCode;
/**
* 品牌名称
*/
@ApiModelProperty("品牌名称")
private String brandName;
/**
* 名称2
*/
@ApiModelProperty("名称2")
private String brandName2;
/**
* 简称
*/
@ApiModelProperty("简称")
private String abbrName;
/**
* 品牌状态
*/
@ApiModelProperty("品牌状态")
private String brandStatus;
/**
* 类型 [UDC]COM:BRAND_TYPE
*/
@ApiModelProperty("类型 [UDC]COM:BRAND_TYPE")
private String brandType;
/**
* 类型2
*/
@ApiModelProperty("类型2")
private String brandType2;
/**
* 类型3
*/
@ApiModelProperty("类型3")
private String brandType3;
/**
* 产品组 [UDC]ITM:ITEM_GROUP
*/
@ApiModelProperty("产品组 [UDC]ITM:ITEM_GROUP")
private String itemGroup;
/**
* 品类
*/
@ApiModelProperty("品类")
private String itemCate;
/**
* 品牌阶段 [UDC]COM:BRAND_PHASE
*/
@ApiModelProperty("品牌阶段 [UDC]COM:BRAND_PHASE")
private String brandPhase;
/**
* 品牌层级 [UDC]COM:BRAND_LEVEL
*/
@ApiModelProperty("品牌层级 [UDC]COM:BRAND_LEVEL")
private String brandLevel;
/**
* 上级ID
*/
@ApiModelProperty("上级ID")
private Long pid;
/**
* 路径
*/
@ApiModelProperty("路径")
private String brandPath;
/**
* 代理商
*/
@ApiModelProperty("代理商")
private String agency;
/**
* 品牌经理
*/
@ApiModelProperty("品牌经理")
private Integer managerEmpId;
/**
* 记录创建者ID
*/
@ApiModelProperty("记录创建者ID")
private Long creator;
/**
* 记录创建时间
*/
@ApiModelProperty("记录创建时间")
private Date created;
/**
* 记录最后更新者ID
*/
@ApiModelProperty("记录最后更新者ID")
private Long updater;
/**
* 记录最后更新时间
*/
@ApiModelProperty("记录最后更新时间")
private Date updated;
/**
* 逻辑删除,0:未删除,1:已删除
*/
@ApiModelProperty("逻辑删除,0:未删除,1:已删除")
private Integer deleted;
/**
* 版本信息,前端不用传
*/
@ApiModelProperty("版本信息,前端不用传")
private Integer version;
}
package com.elitesland.itm.param;
import com.elitesland.core.base.param.AbstractOrderQueryParam;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.Date;
/**
* 品牌(ItmBrand)实体类
*
* @author roman.zhang
* @since 2020-08-17 14:37:43
*/
@Data
@ApiModel(value = "itm_brand", description = "品牌")
public class ItmBrandQueryParam extends AbstractOrderQueryParam {
private static final long serialVersionUID = 524201937632725394L;
/**
* 唯一编号ID
*/
@ApiModelProperty("唯一编号ID")
private Long id;
/**
* 品牌代码
*/
@ApiModelProperty("品牌代码")
private String brandCode;
/**
* 品牌名称
*/
@ApiModelProperty("品牌名称")
private String brandName;
/**
* 名称2
*/
@ApiModelProperty("名称2")
private String brandName2;
/**
* 简称
*/
@ApiModelProperty("简称")
private String abbrName;
/**
* 品牌状态
*/
@ApiModelProperty("品牌状态")
private String brandStatus;
/**
* 类型 [UDC]COM:BRAND_TYPE
*/
@ApiModelProperty("类型 [UDC]COM:BRAND_TYPE")
private String brandType;
/**
* 类型2
*/
@ApiModelProperty("类型2")
private String brandType2;
/**
* 类型3
*/
@ApiModelProperty("类型3")
private String brandType3;
/**
* 产品组 [UDC]ITM:ITEM_GROUP
*/
@ApiModelProperty("产品组 [UDC]ITM:ITEM_GROUP")
private String itemGroup;
/**
* 品类
*/
@ApiModelProperty("品类")
private String itemCate;
/**
* 品牌阶段 [UDC]COM:BRAND_PHASE
*/
@ApiModelProperty("品牌阶段 [UDC]COM:BRAND_PHASE")
private String brandPhase;
/**
* 品牌层级 [UDC]COM:BRAND_LEVEL
*/
@ApiModelProperty("品牌层级 [UDC]COM:BRAND_LEVEL")
private String brandLevel;
/**
* 上级ID
*/
@ApiModelProperty("上级ID")
private Long pid;
/**
* 路径
*/
@ApiModelProperty("路径")
private String brandPath;
/**
* 代理商
*/
@ApiModelProperty("代理商")
private String agency;
/**
* 品牌经理
*/
@ApiModelProperty("品牌经理")
private Integer managerEmpId;
/**
* 记录创建者ID
*/
@ApiModelProperty("记录创建者ID")
private Long creator;
/**
* 记录创建时间
*/
@ApiModelProperty("记录创建时间")
private Date created;
/**
* 记录最后更新者ID
*/
@ApiModelProperty("记录最后更新者ID")
private Long updater;
/**
* 记录最后更新时间
*/
@ApiModelProperty("记录最后更新时间")
private Date updated;
/**
* 逻辑删除,0:未删除,1:已删除
*/
@ApiModelProperty("逻辑删除,0:未删除,1:已删除")
private Integer deleted;
/**
* 版本信息,前端不用传
*/
@ApiModelProperty("版本信息,前端不用传")
private Integer version;
}
package com.elitesland.itm.param;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
/**
* 品牌(ItmBrand)实体类
*
* @author roman.zhang
* @since 2020-08-17 14:37:45
*/
@Data
@ApiModel(value = "itm_brand", description = "品牌")
public class ItmBrandUpdateParam implements Serializable {
private static final long serialVersionUID = 720775929227068303L;
/**
* 唯一编号ID
*/
@ApiModelProperty("唯一编号ID")
private Long id;
/**
* 品牌代码
*/
@ApiModelProperty("品牌代码")
private String brandCode;
/**
* 品牌名称
*/
@ApiModelProperty("品牌名称")
private String brandName;
/**
* 名称2
*/
@ApiModelProperty("名称2")
private String brandName2;
/**
* 简称
*/
@ApiModelProperty("简称")
private String abbrName;
/**
* 品牌状态
*/
@ApiModelProperty("品牌状态")
private String brandStatus;
/**
* 类型 [UDC]COM:BRAND_TYPE
*/
@ApiModelProperty("类型 [UDC]COM:BRAND_TYPE")
private String brandType;
/**
* 类型2
*/
@ApiModelProperty("类型2")
private String brandType2;
/**
* 类型3
*/
@ApiModelProperty("类型3")
private String brandType3;
/**
* 产品组 [UDC]ITM:ITEM_GROUP
*/
@ApiModelProperty("产品组 [UDC]ITM:ITEM_GROUP")
private String itemGroup;
/**
* 品类
*/
@ApiModelProperty("品类")
private String itemCate;
/**
* 品牌阶段 [UDC]COM:BRAND_PHASE
*/
@ApiModelProperty("品牌阶段 [UDC]COM:BRAND_PHASE")
private String brandPhase;
/**
* 品牌层级 [UDC]COM:BRAND_LEVEL
*/
@ApiModelProperty("品牌层级 [UDC]COM:BRAND_LEVEL")
private String brandLevel;
/**
* 上级ID
*/
@ApiModelProperty("上级ID")
private Long pid;
/**
* 路径
*/
@ApiModelProperty("路径")
private String brandPath;
/**
* 代理商
*/
@ApiModelProperty("代理商")
private String agency;
/**
* 品牌经理
*/
@ApiModelProperty("品牌经理")
private Integer managerEmpId;
/**
* 记录创建者ID
*/
@ApiModelProperty("记录创建者ID")
private Long creator;
/**
* 记录创建时间
*/
@ApiModelProperty("记录创建时间")
private Date created;
/**
* 记录最后更新者ID
*/
@ApiModelProperty("记录最后更新者ID")
private Long updater;
/**
* 记录最后更新时间
*/
@ApiModelProperty("记录最后更新时间")
private Date updated;
/**
* 逻辑删除,0:未删除,1:已删除
*/
@ApiModelProperty("逻辑删除,0:未删除,1:已删除")
private Integer deleted;
/**
* 版本信息,前端不用传
*/
@ApiModelProperty("版本信息,前端不用传")
private Integer version;
}
package com.elitesland.itm.vo;
import com.elitesland.core.base.BaseModel;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.time.LocalDateTime;
/**
* 品牌(ItmBrand)实体类
*
* @author roman.zhang
* @since 2020-08-17 14:37:41
*/
@Data
@ApiModel(value = "itm_brand", description = "品牌")
public class ItmBrandVO extends BaseModel implements Serializable {
private static final long serialVersionUID = 361192466633942502L;
/**
* 唯一编号ID
*/
@ApiModelProperty("唯一编号ID")
private Long id;
/**
* 品牌代码
*/
@ApiModelProperty("品牌代码")
private String brandCode;
/**
* 品牌名称
*/
@ApiModelProperty("品牌名称")
private String brandName;
/**
* 名称2
*/
@ApiModelProperty("名称2")
private String brandName2;
/**
* 简称
*/
@ApiModelProperty("简称")
private String abbrName;
/**
* 品牌状态
*/
@ApiModelProperty("品牌状态")
private String brandStatus;
/**
* 类型 [UDC]COM:BRAND_TYPE
*/
@ApiModelProperty("类型 [UDC]COM:BRAND_TYPE")
private String brandType;
/**
* 类型2
*/
@ApiModelProperty("类型2")
private String brandType2;
/**
* 类型3
*/
@ApiModelProperty("类型3")
private String brandType3;
/**
* 产品组 [UDC]ITM:ITEM_GROUP
*/
@ApiModelProperty("产品组 [UDC]ITM:ITEM_GROUP")
private String itemGroup;
/**
* 品类
*/
@ApiModelProperty("品类")
private String itemCate;
/**
* 品牌阶段 [UDC]COM:BRAND_PHASE
*/
@ApiModelProperty("品牌阶段 [UDC]COM:BRAND_PHASE")
private String brandPhase;
/**
* 品牌层级 [UDC]COM:BRAND_LEVEL
*/
@ApiModelProperty("品牌层级 [UDC]COM:BRAND_LEVEL")
private String brandLevel;
/**
* 上级ID
*/
@ApiModelProperty("上级ID")
private Long pid;
/**
* 路径
*/
@ApiModelProperty("路径")
private String brandPath;
/**
* 代理商
*/
@ApiModelProperty("代理商")
private String agency;
/**
* 品牌经理
*/
@ApiModelProperty("品牌经理")
private Integer managerEmpId;
/**
* 记录创建者ID
*/
@ApiModelProperty("记录创建者ID")
private Long creator;
/**
* 记录创建时间
*/
@ApiModelProperty("记录创建时间")
private LocalDateTime created;
/**
* 记录最后更新者ID
*/
@ApiModelProperty("记录最后更新者ID")
private Long updater;
/**
* 记录最后更新时间
*/
@ApiModelProperty("记录最后更新时间")
private LocalDateTime updated;
/**
* 逻辑删除,0:未删除,1:已删除
*/
@ApiModelProperty("逻辑删除,0:未删除,1:已删除")
private Integer deleted;
/**
* 版本信息,前端不用传
*/
@ApiModelProperty("版本信息,前端不用传")
private Integer version;
}
package com.elitesland.system.entity;
import static com.querydsl.core.types.PathMetadataFactory.*;
import com.querydsl.core.types.dsl.*;
import com.querydsl.core.types.PathMetadata;
import javax.annotation.Generated;
import com.querydsl.core.types.Path;
import com.querydsl.core.types.dsl.PathInits;
/**
* QCatCodeDO is a Querydsl query type for CatCodeDO
*/
@Generated("com.querydsl.codegen.EntitySerializer")
public class QCatCodeDO extends EntityPathBase<CatCodeDO> {
private static final long serialVersionUID = -2042391316L;
private static final PathInits INITS = PathInits.DIRECT2;
public static final QCatCodeDO catCodeDO = new QCatCodeDO("catCodeDO");
public final DateTimePath<java.time.LocalDateTime> created = createDateTime("created", java.time.LocalDateTime.class);
public final NumberPath<Long> creator = createNumber("creator", Long.class);
public final DateTimePath<java.time.LocalDateTime> datetime01 = createDateTime("datetime01", java.time.LocalDateTime.class);
public final DateTimePath<java.time.LocalDateTime> datetime02 = createDateTime("datetime02", java.time.LocalDateTime.class);
public final DateTimePath<java.time.LocalDateTime> datetime03 = createDateTime("datetime03", java.time.LocalDateTime.class);
public final DateTimePath<java.time.LocalDateTime> datetime04 = createDateTime("datetime04", java.time.LocalDateTime.class);
public final NumberPath<Integer> deleted = createNumber("deleted", Integer.class);
public final StringPath description = createString("description");
public final NumberPath<Double> double01 = createNumber("double01", Double.class);
public final NumberPath<Double> double02 = createNumber("double02", Double.class);
public final NumberPath<Double> double03 = createNumber("double03", Double.class);
public final NumberPath<Double> double04 = createNumber("double04", Double.class);
public final BooleanPath flag01 = createBoolean("flag01");
public final NumberPath<Integer> int01 = createNumber("int01", Integer.class);
public final NumberPath<Integer> int02 = createNumber("int02", Integer.class);
public final NumberPath<Integer> int03 = createNumber("int03", Integer.class);
public final NumberPath<Integer> int04 = createNumber("int04", Integer.class);
public final BooleanPath isHD = createBoolean("isHD");
public final QCatCodeKey key;
public final StringPath string01 = createString("string01");
public final StringPath string02 = createString("string02");
public final StringPath string03 = createString("string03");
public final StringPath string04 = createString("string04");
public final DateTimePath<java.time.LocalDateTime> updated = createDateTime("updated", java.time.LocalDateTime.class);
public final NumberPath<Long> updater = createNumber("updater", Long.class);
public final NumberPath<Integer> version = createNumber("version", Integer.class);
public QCatCodeDO(String variable) {
this(CatCodeDO.class, forVariable(variable), INITS);
}
public QCatCodeDO(Path<? extends CatCodeDO> path) {
this(path.getType(), path.getMetadata(), PathInits.getFor(path.getMetadata(), INITS));
}
public QCatCodeDO(PathMetadata metadata) {
this(metadata, PathInits.getFor(metadata, INITS));
}
public QCatCodeDO(PathMetadata metadata, PathInits inits) {
this(CatCodeDO.class, metadata, inits);
}
public QCatCodeDO(Class<? extends CatCodeDO> type, PathMetadata metadata, PathInits inits) {
super(type, metadata, inits);
this.key = inits.isInitialized("key") ? new QCatCodeKey(forProperty("key")) : null;
}
}
package com.elitesland.system.entity;
import static com.querydsl.core.types.PathMetadataFactory.*;
import com.querydsl.core.types.dsl.*;
import com.querydsl.core.types.PathMetadata;
import javax.annotation.Generated;
import com.querydsl.core.types.Path;
/**
* QCatCodeKey is a Querydsl query type for CatCodeKey
*/
@Generated("com.querydsl.codegen.EmbeddableSerializer")
public class QCatCodeKey extends BeanPath<CatCodeKey> {
private static final long serialVersionUID = 1110386174L;
public static final QCatCodeKey catCodeKey = new QCatCodeKey("catCodeKey");
public final StringPath catCode = createString("catCode");
public final StringPath modCode = createString("modCode");
public final StringPath sysCode = createString("sysCode");
public QCatCodeKey(String variable) {
super(CatCodeKey.class, forVariable(variable));
}
public QCatCodeKey(Path<? extends CatCodeKey> path) {
super(path.getType(), path.getMetadata());
}
public QCatCodeKey(PathMetadata metadata) {
super(CatCodeKey.class, metadata);
}
}
package com.elitesland.system.entity;
import static com.querydsl.core.types.PathMetadataFactory.*;
import com.querydsl.core.types.dsl.*;
import com.querydsl.core.types.PathMetadata;
import javax.annotation.Generated;
import com.querydsl.core.types.Path;
import com.querydsl.core.types.dsl.PathInits;
/**
* QPermissionDO is a Querydsl query type for PermissionDO
*/
@Generated("com.querydsl.codegen.EntitySerializer")
public class QPermissionDO extends EntityPathBase<PermissionDO> {
private static final long serialVersionUID = 1493341084L;
public static final QPermissionDO permissionDO = new QPermissionDO("permissionDO");
public final com.elitesland.core.base.QBaseModel _super = new com.elitesland.core.base.QBaseModel(this);
public final StringPath code = createString("code");
//inherited
public final DateTimePath<java.time.LocalDateTime> created = _super.created;
//inherited
public final NumberPath<Long> creator = _super.creator;
//inherited
public final NumberPath<Integer> deleted = _super.deleted;
//inherited
public final NumberPath<Long> id = _super.id;
public final NumberPath<Integer> level = createNumber("level", Integer.class);
public final StringPath name = createString("name");
public final NumberPath<Integer> parentId = createNumber("parentId", Integer.class);
public final StringPath path = createString("path");
public final StringPath pattern = createString("pattern");
public final NumberPath<Integer> permType = createNumber("permType", Integer.class);
public final SetPath<RoleDO, QRoleDO> roles = this.<RoleDO, QRoleDO>createSet("roles", RoleDO.class, QRoleDO.class, PathInits.DIRECT2);
//inherited
public final DateTimePath<java.time.LocalDateTime> updated = _super.updated;
//inherited
public final NumberPath<Long> updater = _super.updater;
//inherited
public final NumberPath<Integer> version = _super.version;
public QPermissionDO(String variable) {
super(PermissionDO.class, forVariable(variable));
}
public QPermissionDO(Path<? extends PermissionDO> path) {
super(path.getType(), path.getMetadata());
}
public QPermissionDO(PathMetadata metadata) {
super(PermissionDO.class, metadata);
}
}
package com.elitesland.system.entity;
import static com.querydsl.core.types.PathMetadataFactory.*;
import com.querydsl.core.types.dsl.*;
import com.querydsl.core.types.PathMetadata;
import javax.annotation.Generated;
import com.querydsl.core.types.Path;
import com.querydsl.core.types.dsl.PathInits;
/**
* QRoleDO is a Querydsl query type for RoleDO
*/
@Generated("com.querydsl.codegen.EntitySerializer")
public class QRoleDO extends EntityPathBase<RoleDO> {
private static final long serialVersionUID = -1287083517L;
public static final QRoleDO roleDO = new QRoleDO("roleDO");
public final com.elitesland.core.base.QBaseModel _super = new com.elitesland.core.base.QBaseModel(this);
public final StringPath code = createString("code");
//inherited
public final DateTimePath<java.time.LocalDateTime> created = _super.created;
//inherited
public final NumberPath<Long> creator = _super.creator;
//inherited
public final NumberPath<Integer> deleted = _super.deleted;
//inherited
public final NumberPath<Long> id = _super.id;
public final StringPath name = createString("name");
public final SetPath<PermissionDO, QPermissionDO> permissions = this.<PermissionDO, QPermissionDO>createSet("permissions", PermissionDO.class, QPermissionDO.class, PathInits.DIRECT2);
//inherited
public final DateTimePath<java.time.LocalDateTime> updated = _super.updated;
//inherited
public final NumberPath<Long> updater = _super.updater;
public final SetPath<UserDO, QUserDO> users = this.<UserDO, QUserDO>createSet("users", UserDO.class, QUserDO.class, PathInits.DIRECT2);
//inherited
public final NumberPath<Integer> version = _super.version;
public QRoleDO(String variable) {
super(RoleDO.class, forVariable(variable));
}
public QRoleDO(Path<? extends RoleDO> path) {
super(path.getType(), path.getMetadata());
}
public QRoleDO(PathMetadata metadata) {
super(RoleDO.class, metadata);
}
}
package com.elitesland.system.entity;
import static com.querydsl.core.types.PathMetadataFactory.*;
import com.querydsl.core.types.dsl.*;
import com.querydsl.core.types.PathMetadata;
import javax.annotation.Generated;
import com.querydsl.core.types.Path;
import com.querydsl.core.types.dsl.PathInits;
/**
* QUserDO is a Querydsl query type for UserDO
*/
@Generated("com.querydsl.codegen.EntitySerializer")
public class QUserDO extends EntityPathBase<UserDO> {
private static final long serialVersionUID = -1197698024L;
public static final QUserDO userDO = new QUserDO("userDO");
public final com.elitesland.core.base.QBaseModel _super = new com.elitesland.core.base.QBaseModel(this);
//inherited
public final DateTimePath<java.time.LocalDateTime> created = _super.created;
//inherited
public final NumberPath<Long> creator = _super.creator;
//inherited
public final NumberPath<Integer> deleted = _super.deleted;
public final StringPath email = createString("email");
public final StringPath firstName = createString("firstName");
//inherited
public final NumberPath<Long> id = _super.id;
public final StringPath lastName = createString("lastName");
public final StringPath mobile = createString("mobile");
public final StringPath password = createString("password");
public final SetPath<RoleDO, QRoleDO> roles = this.<RoleDO, QRoleDO>createSet("roles", RoleDO.class, QRoleDO.class, PathInits.DIRECT2);
//inherited
public final DateTimePath<java.time.LocalDateTime> updated = _super.updated;
//inherited
public final NumberPath<Long> updater = _super.updater;
public final StringPath username = createString("username");
//inherited
public final NumberPath<Integer> version = _super.version;
public QUserDO(String variable) {
super(UserDO.class, forVariable(variable));
}
public QUserDO(Path<? extends UserDO> path) {
super(path.getType(), path.getMetadata());
}
public QUserDO(PathMetadata metadata) {
super(UserDO.class, metadata);
}
}
......@@ -14,6 +14,7 @@
<properties>
<java.version>11</java.version>
<gson.version>2.8.5</gson.version>
</properties>
<dependencies>
......@@ -27,10 +28,19 @@
<artifactId>interface</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<!--Alibaba-Excel-->
<dependency>
<groupId>com.elitesland</groupId>
<artifactId>system</artifactId>
<version>0.0.1-SNAPSHOT</version>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>${gson.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
......
package com.elitesland.basic;
import com.elitesland.core.base.PagingVO;
import java.util.List;
import java.util.Optional;
/**
* <p>
* jps单表服务
* </p>
*
* @author niuchen
* @date 2020/7/2
*/
public interface BaseJpaService<DO,VO,QueryParam> {
/**
* 检索
* @param queryParam 分类查询、分页和排序对象
* @return 分页结果集
*/
PagingVO<VO> search(QueryParam queryParam);
/**
* 根据关键字段,返回对应的vo
* @param Code code
* @return 对象
*/
Optional<VO> findCodeOne(String Code);
/**
* 根据关键字段,返回对应的
* @param Id ID
* @return 对象
*/
Optional<VO> findIdOne(Long Id);
/**
* 根据关键字段,返回对应的
* @param idList ID集合
* @return 对象
*/
List<VO> findIdBatch(List<Long> idList);
/**
* 创建
*
* @param objDo 对象
*/
Long createOne(DO objDo);
/**
* 创建
*
* @param List 对象集合
*/
List<Long> createBatch(List<DO> List);
/**
* 更新
*
* @param objDo 对象
*/
void update(DO objDo) ;
/**
* 删除
*
* @param Id 对象
*/
void deleteOne(Long Id);
/**
* 删除
*
* @param idList 对象集合
*/
void deleteBatch(List<Long> idList);
/**
* 更新删除标识
*
* @param id id
*/
void updateDeleteFlag(Long id);
}
package com.elitesland.basic;
import com.elitesland.core.base.param.AbstractOrderQueryParam;
import com.querydsl.core.types.Order;
import com.querydsl.core.types.OrderSpecifier;
import com.querydsl.core.types.dsl.EntityPathBase;
import com.querydsl.core.types.dsl.PathBuilder;
import com.querydsl.jpa.impl.JPAQuery;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
/**
* 查询组合接口
* JpaQueryProcInterface
*
* @author niuchen
* @date 2020/6/27
*/
public interface JpaQueryProcInterface {
/**
* 排序与分页
* classObj是继承EntityPathBase的QueryDSL生成的对象 里面存储了对象信息.
* **/
default void openOrderAndLimit(JPAQuery jpaQuery, AbstractOrderQueryParam abstractOrderQueryParam, EntityPathBase classObj){
openOrder( jpaQuery, abstractOrderQueryParam, classObj);
openLimit( jpaQuery, abstractOrderQueryParam);
}
default void openLimit(JPAQuery jpaQuery, AbstractOrderQueryParam abstractOrderQueryParam){
/**如果是0 设置1. 前端传参是1开始, 后端是0开始**/
if(abstractOrderQueryParam.getCurrent()!=null&&abstractOrderQueryParam.getCurrent() ==0){
abstractOrderQueryParam.setCurrent(1);
}
jpaQuery.limit(abstractOrderQueryParam.getSize())
.offset((abstractOrderQueryParam.getCurrent() ) * abstractOrderQueryParam.getSize());
}
/**
* 设置排序路径映射
* abstractOrderQueryParam 里面需要有order参数
* classObj是继承EntityPathBase的QueryDSL生成的对象 里面存储了对象信息.
* 重写排序
* 参考见:http://www.querydsl.com/static/querydsl/3.6.4/apidocs/com/mysema/query/types/path/PathBuilder.html#PathBuilder(java.lang.Class,%20com.mysema.query.types.PathMetadata)
* **/
default void openOrder(JPAQuery jpaQuery, AbstractOrderQueryParam abstractOrderQueryParam, EntityPathBase classObj){
PageRequest pageRequest= abstractOrderQueryParam.getPageRequest();
for (Sort.Order o : pageRequest.getSort()) {
PathBuilder orderByExpression = new PathBuilder(classObj.getClass(),
classObj.getMetadata().getElement().toString());
PathBuilder<Object> objectPathBuilder= orderByExpression.get(o.getProperty());
jpaQuery.orderBy(new OrderSpecifier(o.isAscending() ? Order.ASC
: Order.DESC,objectPathBuilder ));
}
}
}
package com.elitesland.item.config;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.ParameterBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.schema.ModelRef;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.service.Parameter;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
import java.util.ArrayList;
import java.util.List;
/**
* <p>
* 功能说明:品项模块
* </p>
*
* @author niucnen
* @since 2020-07-03 15:32:37
*/
@Configuration
@EnableSwagger2
@RequiredArgsConstructor
public class ItmSwagger2Config {
/**
* 标题
*/
@Value("${swagger.title}")
private String title;
/**
* 基本包
*/
@Value("${swagger.base.package}")
private String basePackage;
/**
* 描述
*/
@Value("${swagger.description}")
private String description;
/**
* URL
*/
@Value("${swagger.url}")
private String url;
/**
* 作者
*/
@Value("${swagger.contact.name}")
private String contactName;
/**
* 作者网址
*/
@Value("${swagger.contact.url}")
private String contactUrl;
/**
* 作者邮箱
*/
@Value("${swagger.contact.email}")
private String contactEmail;
/**
* 版本
*/
@Value("${swagger.version}")
private String version;
@Bean
public Docket createItmRestApi() {
return new Docket(DocumentationType.SWAGGER_2)
.groupName("品项模块")
.apiInfo(apiInfo())
.select()
.apis(RequestHandlerSelectors.basePackage("com.elitesland.item.controller"))
.paths(PathSelectors.any())
.build()
.globalOperationParameters(setHeaderToken())
;
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title(title)
.description(description)
.termsOfServiceUrl(url)
.contact(new Contact(contactName, contactUrl, contactEmail))
.version(version)
.build();
}
private List<Parameter> setHeaderToken() {
List<Parameter> pars = new ArrayList<>();
// token请求头
String testTokenValue = "";
ParameterBuilder tokenPar = new ParameterBuilder();
Parameter tokenParameter = tokenPar
.name("实现生培训:roman.zhang")
.description("JWT Token Request Header")
.modelRef(new ModelRef("string"))
.parameterType("header")
.required(false)
.defaultValue(testTokenValue)
.build();
pars.add(tokenParameter);
return pars;
}
}
package com.elitesland.item.controller;
import com.elitesland.core.base.ApiCode;
import com.elitesland.core.base.ApiResult;
import com.elitesland.core.base.PagingVO;
import com.elitesland.item.entity.ItmBrandDO;
import com.elitesland.item.service.ItmBrandService;
import com.elitesland.itm.param.ItmBrandCreateParam;
import com.elitesland.itm.param.ItmBrandQueryParam;
import com.elitesland.itm.param.ItmBrandUpdateParam;
import com.elitesland.itm.vo.ItmBrandVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.val;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.stream.Collectors;
/**
* <p>
* 功能说明
* </p>
*
* @author roman.zhang
* @since 2020-08-17 14:34:21
*/
@RestController
@RequestMapping("//itmBrand")
@Api(value = "品牌", tags = {"品牌"})
@RequiredArgsConstructor
public class ItmBrandController {
private final ItmBrandService itmBrandService;
/**
* 通过主键查询单条数据
*
* @param id 主键
* @return 单条数据
*/
@GetMapping("/findIdOne/{id}")
@ApiOperation("通过主键查询单条数据")
ApiResult<ItmBrandVO> findIdOne(@PathVariable Long id) {
return itmBrandService.findIdOne(id).map(ApiResult::ok)
.orElse(ApiResult.fail(ApiCode.NOT_FOUND));
}
/**
* 根据关键字段查询数据
*
* @param key 参数
* @return 数据
*/
@GetMapping("/findCodeOne/{key}")
@ApiOperation("根据关键字段查询数据")
public ApiResult<ItmBrandVO> findCodeOne(@PathVariable String key) {
return itmBrandService.findCodeOne(key).map(ApiResult::ok)
.orElse(ApiResult.fail(ApiCode.NOT_FOUND));
}
/**
* 分页查询
*
* @param param 分类查询、分页和排序对象
* @return 多条数据
*/
@PostMapping("/search")
@ApiOperation("分页查询")
public ApiResult<PagingVO<ItmBrandVO>> search(@RequestBody ItmBrandQueryParam param) {
val ret = itmBrandService.search(param);
return ApiResult.ok(ret);
}
/**
* 新增数据
*
* @param param 新增数据
* @return 新增数据情况
*/
@PostMapping("/createOne")
@ApiOperation("新增数据")
public ApiResult<Object> createOne(@RequestBody ItmBrandCreateParam param) {
ItmBrandDO DO = new ItmBrandDO();
BeanUtils.copyProperties(param, DO);
return ApiResult.ok(itmBrandService.createOne(DO));
}
/**
* 批量新增数据
*
* @param list 对象集合
*/
@PostMapping("/createBatch")
@ApiOperation("批量新增数据")
public ApiResult<Object> createBatch(@RequestBody List<ItmBrandDO> list) {
val dos = list.stream().map(i -> {
ItmBrandDO DO = new ItmBrandDO();
BeanUtils.copyProperties(i, DO);
return DO;
}).collect(Collectors.toList());
return ApiResult.ok(itmBrandService.createBatch(dos));
}
/**
* 修改数据
*
* @param param 修改对象
* @return 修改数据详情
*/
@PutMapping("/update")
@ApiOperation("修改数据")
public ApiResult<Object> update(@RequestBody ItmBrandUpdateParam param) {
ItmBrandDO DO = new ItmBrandDO();
BeanUtils.copyProperties(param, DO);
itmBrandService.update(DO);
return ApiResult.ok();
}
/**
* 根据主键删除数据
*
* @param id 主键
* @return 删除情况
*/
@DeleteMapping("/deleteOne/{id}")
@ApiOperation("根据主键删除数据")
public ApiResult<Object> deleteOne(@PathVariable Long id) {
itmBrandService.deleteOne(id);
return ApiResult.ok();
}
/**
* 批量删除
*
* @param ids 删除数据集合
*/
@DeleteMapping("/deleteBatch")
@ApiOperation("批量删除")
public ApiResult<Object> deleteBatch(@RequestBody List<Long> ids) {
itmBrandService.deleteBatch(ids);
return ApiResult.ok();
}
/**
* 逻辑删除
*
* @param id 更新数据
*/
@PutMapping("/updateDeleteFlag/{id}")
@ApiOperation("逻辑删除")
public ApiResult<Object> updateDeleteFlag(@PathVariable Long id) {
itmBrandService.updateDeleteFlag(id);
return ApiResult.ok();
}
}
package com.elitesland.item.convert;
import com.elitesland.item.entity.ItmBrandDO;
import com.elitesland.itm.vo.ItmBrandVO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
/**
* <p>
* 功能说明
* </p>
*
* @author roman.zhang
* @since 2020-08-17 14:34:22
*/
@Mapper
public interface ItmBrandConvert {
ItmBrandConvert INSTANCE = Mappers.getMapper(ItmBrandConvert.class);
ItmBrandVO doToVO(ItmBrandDO itmBrandDO);
}
package com.elitesland.item.entity;
import com.elitesland.core.base.BaseModel;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.io.Serializable;
import java.util.Objects;
/**
* <p>
* 功能说明:品牌
* </p >
*
* @author Roman.Zhang
* @date 2020/7/8
*/
@Entity
@Table(name = "itm_brand")
@DynamicUpdate
@DynamicInsert
@org.hibernate.annotations.Table(appliesTo = "itm_brand", comment = "品牌")
@Data
@Accessors(chain = true)
@ApiModel(value = "ITM_BRAND", description = "品牌")
public class ItmBrandDO extends BaseModel implements Serializable
{
private static final long serialVersionUID = 4735933553085336616L;
@ApiModelProperty("品牌代码")
@Column(columnDefinition = "varchar(8) comment '品牌代码'")
private String brandCode;
@ApiModelProperty("品牌名称")
@Column(columnDefinition = "varchar(64) comment '品牌名称'")
private String brandName;
@ApiModelProperty("名称2")
@Column(columnDefinition = "varchar(64) comment '名称2'")
private String brandName2;
@ApiModelProperty("简称")
@Column(columnDefinition = "varchar(64) comment '简称'")
private String abbrName;
@ApiModelProperty("品牌状态")
@Column(columnDefinition = "varchar(64) comment '品牌状态'")
private String brandStatus;
@ApiModelProperty("类型 [UDC]COM:BRAND_TYPE")
@Column(columnDefinition = "varchar(16) comment '类型 [UDC]COM:BRAND_TYPE'")
private String brandType;
@ApiModelProperty("类型2")
@Column(columnDefinition = "varchar(16) comment '类型2'")
private String brandType2;
@ApiModelProperty("类型3")
@Column(columnDefinition = "varchar(16) comment '类型3'")
private String brandType3;
@ApiModelProperty("产品组 [UDC]ITM:ITEM_GROUP")
@Column(columnDefinition = "varchar(64) comment '产品组 [UDC]ITM:ITEM_GROUP'")
private String itemGroup;
@ApiModelProperty("品类")
@Column(columnDefinition = "varchar(64) comment '品类'")
private String itemCate;
@ApiModelProperty("品牌阶段 [UDC]COM:BRAND_PHASE")
@Column(columnDefinition = "varchar(64) comment '品牌阶段 [UDC]COM:BRAND_PHASE'")
private String brandPhase;
@ApiModelProperty("品牌层级 [UDC]COM:BRAND_LEVEL")
@Column(columnDefinition = "varchar(64) comment '品牌层级 [UDC]COM:BRAND_LEVEL'")
private String brandLevel;
@ApiModelProperty("上级ID")
@Column(columnDefinition = "bigint(18) comment '上级ID'")
private Long pid;
@ApiModelProperty("路径")
@Column(columnDefinition = "varchar(1024) comment '路径'")
private String brandPath;
@ApiModelProperty("代理商")
@Column(columnDefinition = "varchar(64) comment '代理商'")
private String agency;
@ApiModelProperty("品牌经理")
@Column(columnDefinition = "int(18) comment '品牌经理'")
private Long managerEmpId;
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof ItmBrandDO)) {
return false;
}
if (!super.equals(o)) {
return false;
}
ItmBrandDO entity = (ItmBrandDO) o;
return getId().equals(entity.getId());
}
@Override
public int hashCode() {
return Objects.hash(getId());
}
}
package com.elitesland.item.repo;
import com.elitesland.item.entity.ItmBrandDO;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.querydsl.QuerydslPredicateExecutor;
import org.springframework.stereotype.Repository;
/**
* <p>
* 功能说明
* </p>
*
* @author roman.zhang
* @since 2020-08-17 14:36:52
*/
@Repository
public interface ItmBrandRepo extends JpaRepository<ItmBrandDO, Long>, QuerydslPredicateExecutor<ItmBrandDO> {
}
package com.elitesland.item.repo;
import com.elitesland.basic.JpaQueryProcInterface;
import com.elitesland.item.entity.QItmBrandDO;
import com.elitesland.itm.param.ItmBrandQueryParam;
import com.elitesland.itm.vo.ItmBrandVO;
import com.querydsl.core.types.ExpressionUtils;
import com.querydsl.core.types.Predicate;
import com.querydsl.core.types.Projections;
import com.querydsl.jpa.impl.JPAQuery;
import com.querydsl.jpa.impl.JPAQueryFactory;
import lombok.RequiredArgsConstructor;
import lombok.val;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
/**
* <p>
* 功能说明
* </p>
*
* @author roman.zhang
* @since 2020-08-17 14:34:22
*/
@Component
@RequiredArgsConstructor
public class ItmBrandRepoProc implements JpaQueryProcInterface {
private final JPAQueryFactory jpaQueryFactory;
/**
* 查询字段
*/
public JPAQuery<ItmBrandVO> select(ItmBrandQueryParam param) {
val jpaQDo = QItmBrandDO.itmBrandDO;
Predicate predicate = jpaQDo.isNotNull();
val jpaQuery = jpaQueryFactory.select(Projections.bean(ItmBrandVO.class,
jpaQDo.id,
jpaQDo.brandCode,
jpaQDo.brandName,
jpaQDo.brandName2,
jpaQDo.abbrName,
jpaQDo.brandStatus,
jpaQDo.brandType,
jpaQDo.brandType2,
jpaQDo.brandType3,
jpaQDo.itemGroup,
jpaQDo.itemCate,
jpaQDo.brandPhase,
jpaQDo.brandLevel,
jpaQDo.pid,
jpaQDo.brandPath,
jpaQDo.agency,
jpaQDo.managerEmpId
)).from(jpaQDo);
if (param != null) {
jpaQuery.where(where(param));
}
jpaQuery.where(predicate, jpaQDo.deleteFlag.eq(0).or(jpaQDo.deleteFlag.isNull()));
return jpaQuery;
}
/**
* 根据主键查询
*
* @param id 主键
*/
public Predicate where(Long id) {
val jpaQDo = QItmBrandDO.itmBrandDO;
Predicate predicate = jpaQDo.isNotNull().or(jpaQDo.isNull());
ExpressionUtils.and(predicate, jpaQDo.id.eq(id));
return predicate;
}
/**
* 条件查询
*
* @param param 查询条件
*/
public Predicate where(ItmBrandQueryParam param) {
val jpaQDo = QItmBrandDO.itmBrandDO;
Predicate predicate = jpaQDo.isNotNull().or(jpaQDo.isNull());
if (!StringUtils.isEmpty(param.getId())) {
predicate = ExpressionUtils.and(predicate, jpaQDo.id.eq(param.getId()));
}
if (!StringUtils.isEmpty(param.getBrandCode())) {
predicate = ExpressionUtils.and(predicate, jpaQDo.brandCode.eq(param.getBrandCode()));
}
if (!StringUtils.isEmpty(param.getBrandName())) {
predicate = ExpressionUtils.and(predicate, jpaQDo.brandName.eq(param.getBrandName()));
}
if (!StringUtils.isEmpty(param.getBrandName2())) {
predicate = ExpressionUtils.and(predicate, jpaQDo.brandName2.eq(param.getBrandName2()));
}
if (!StringUtils.isEmpty(param.getAbbrName())) {
predicate = ExpressionUtils.and(predicate, jpaQDo.abbrName.eq(param.getAbbrName()));
}
if (!StringUtils.isEmpty(param.getBrandStatus())) {
predicate = ExpressionUtils.and(predicate, jpaQDo.brandStatus.eq(param.getBrandStatus()));
}
if (!StringUtils.isEmpty(param.getBrandType())) {
predicate = ExpressionUtils.and(predicate, jpaQDo.brandType.eq(param.getBrandType()));
}
if (!StringUtils.isEmpty(param.getBrandType2())) {
predicate = ExpressionUtils.and(predicate, jpaQDo.brandType2.eq(param.getBrandType2()));
}
if (!StringUtils.isEmpty(param.getBrandType3())) {
predicate = ExpressionUtils.and(predicate, jpaQDo.brandType3.eq(param.getBrandType3()));
}
if (!StringUtils.isEmpty(param.getItemGroup())) {
predicate = ExpressionUtils.and(predicate, jpaQDo.itemGroup.eq(param.getItemGroup()));
}
if (!StringUtils.isEmpty(param.getItemCate())) {
predicate = ExpressionUtils.and(predicate, jpaQDo.itemCate.eq(param.getItemCate()));
}
if (!StringUtils.isEmpty(param.getBrandPhase())) {
predicate = ExpressionUtils.and(predicate, jpaQDo.brandPhase.eq(param.getBrandPhase()));
}
if (!StringUtils.isEmpty(param.getBrandLevel())) {
predicate = ExpressionUtils.and(predicate, jpaQDo.brandLevel.eq(param.getBrandLevel()));
}
if (!StringUtils.isEmpty(param.getPid())) {
predicate = ExpressionUtils.and(predicate, jpaQDo.pid.eq(param.getPid()));
}
if (!StringUtils.isEmpty(param.getBrandPath())) {
predicate = ExpressionUtils.and(predicate, jpaQDo.brandPath.eq(param.getBrandPath()));
}
if (!StringUtils.isEmpty(param.getAgency())) {
predicate = ExpressionUtils.and(predicate, jpaQDo.agency.eq(param.getAgency()));
}
return predicate;
}
}
package com.elitesland.item.service;
import com.elitesland.basic.BaseJpaService;
import com.elitesland.item.entity.ItmBrandDO;
import com.elitesland.itm.param.ItmBrandQueryParam;
import com.elitesland.itm.vo.ItmBrandVO;
/**
* <p>
* 功能说明
* </p>
*
* @author roman.zhang
* @since 2020-08-17 14:34:22
*/
public interface ItmBrandService extends BaseJpaService<ItmBrandDO, ItmBrandVO, ItmBrandQueryParam> {
}
package com.elitesland.item.service.impl;
import com.elitesland.core.base.ApiCode;
import com.elitesland.core.base.PagingVO;
import com.elitesland.core.exception.BusinessException;
import com.elitesland.item.convert.ItmBrandConvert;
import com.elitesland.item.entity.ItmBrandDO;
import com.elitesland.item.entity.QItmBrandDO;
import com.elitesland.item.repo.ItmBrandRepo;
import com.elitesland.item.repo.ItmBrandRepoProc;
import com.elitesland.item.service.ItmBrandService;
import com.elitesland.itm.param.ItmBrandQueryParam;
import com.elitesland.itm.vo.ItmBrandVO;
import com.elitesland.utils.BeanCopyUtil;
import com.querydsl.core.types.ExpressionUtils;
import com.querydsl.core.types.Predicate;
import com.querydsl.jpa.impl.JPAQuery;
import lombok.RequiredArgsConstructor;
import lombok.val;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
/**
* <p>
* 功能说明
* </p>
*
* @author roman.zhang
* @since 2020-08-17 14:34:22
*/
@Service("itmBrandService")
@RequiredArgsConstructor
public class ItmBrandServiceImpl implements ItmBrandService {
private final ItmBrandRepo itmBrandRepo;
private final ItmBrandRepoProc itmBrandRepoProc;
@Override
public PagingVO<ItmBrandVO> search(ItmBrandQueryParam param) {
val ret = itmBrandRepo.findAll(itmBrandRepoProc.where(param), param.getPageRequest());
val vos = ret.getContent().stream().map(ItmBrandConvert.INSTANCE::doToVO).collect(Collectors.toList());
return PagingVO.<ItmBrandVO>builder()
.total(ret.getTotalElements())
.records(vos)
.build();
}
@Override
public Optional<ItmBrandVO> findCodeOne(String itemCode) {
JPAQuery<ItmBrandVO> jpaQuery = itmBrandRepoProc.select(null);
val jpaQDo = QItmBrandDO.itmBrandDO;
//设置查询条件
//jpaQuery.where(jpaQDo.itemCode.eq(itemCode));
ItmBrandVO vo = jpaQuery.fetchOne();
return Optional.ofNullable(vo);
}
@Override
public Optional<ItmBrandVO> findIdOne(Long id) {
return itmBrandRepo.findById(id).map(ItmBrandConvert.INSTANCE::doToVO);
}
@Override
public List<ItmBrandVO> findIdBatch(List<Long> idList) {
return itmBrandRepo.findAllById(idList).stream().map(
ItmBrandConvert.INSTANCE::doToVO
).collect(Collectors.toList());
}
@Override
@Transactional
public Long createOne(ItmBrandDO itmBrandDO) {
return itmBrandRepo.save(itmBrandDO).getId();
}
@Override
@Transactional
public List<Long> createBatch(List<ItmBrandDO> list) {
return itmBrandRepo.saveAll(list).stream().map(ItmBrandDO::getId).collect(Collectors.toList());
}
@Override
@Transactional
public void update(ItmBrandDO objDo) {
Optional<ItmBrandDO> optional = itmBrandRepo.findById(objDo.getId());
if (optional.isPresent()) {
BeanCopyUtil.beanCopyWithIngore(objDo, optional.get(), BeanCopyUtil.getNullPropertyNames(objDo));
itmBrandRepo.save(optional.get());
} else {
throw new BusinessException(ApiCode.FAIL, "修改失败,数据不存在" + objDo.getId());
}
}
@Override
@Transactional
public void updateDeleteFlag(Long id) {
val jpaQDo = QItmBrandDO.itmBrandDO;
Predicate predicate = jpaQDo.isNotNull();
predicate = ExpressionUtils.and(predicate, jpaQDo.id.eq(id));
Optional<ItmBrandDO> optionalItem = itmBrandRepo.findOne(predicate);
if (optionalItem.isPresent()) {
ItmBrandDO do1 = optionalItem.get();
itmBrandRepo.save(do1);
} else {
throw new BusinessException(ApiCode.FAIL, "修改失败,数据不存在" + id);
}
}
@Override
@Transactional
public void deleteOne(Long id) {
this.itmBrandRepo.deleteById(id);
}
@Override
@Transactional
public void deleteBatch(List<Long> list) {
list.forEach(id -> itmBrandRepo.deleteById(id));
}
}
package com.elitesland.utils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.BeanWrapper;
import org.springframework.beans.BeanWrapperImpl;
import java.util.HashSet;
import java.util.Set;
/**
* <p>
* 功能说明
* </p >
*
* @author Roman.Zhang
* @date 2020/7/9
*/
public class BeanCopyUtil {
//source中的非空属性复制到target中
public static <T> void beanCopy(T source, T target) {
BeanUtils.copyProperties(source, target, getNullPropertyNames(source));
}
//source中的非空属性复制到target中,但是忽略指定的属性,也就是说有些属性是不可修改的(个人业务需要)
public static <T> void beanCopyWithIngore(T source, T target, String... ignoreProperties) {
String[] pns = getNullAndIgnorePropertyNames(source, ignoreProperties);
BeanUtils.copyProperties(source, target, pns);
}
public static String[] getNullAndIgnorePropertyNames(Object source, String... ignoreProperties) {
Set<String> emptyNames = getNullPropertyNameSet(source);
for (String s : ignoreProperties) {
emptyNames.add(s);
}
String[] result = new String[emptyNames.size()];
return emptyNames.toArray(result);
}
public static String[] getNullPropertyNames(Object source) {
Set<String> emptyNames = getNullPropertyNameSet(source);
String[] result = new String[emptyNames.size()];
return emptyNames.toArray(result);
}
public static Set<String> getNullPropertyNameSet(Object source) {
final BeanWrapper src = new BeanWrapperImpl(source);
java.beans.PropertyDescriptor[] pds = src.getPropertyDescriptors();
Set<String> emptyNames = new HashSet<>();
for (java.beans.PropertyDescriptor pd : pds) {
Object srcValue = src.getPropertyValue(pd.getName());
if (srcValue == null){ emptyNames.add(pd.getName());}
}
return emptyNames;
}
}
spring:
profiles:
active: @profileActive@
server:
servlet:
context-path: /el-train
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