商城商品管理;多数据源;商城新增统一查询品牌

This commit is contained in:
DB 2023-10-23 18:28:52 +08:00
parent 0c55cd317f
commit 224866c670
34 changed files with 1243 additions and 21 deletions

View File

@ -34,4 +34,9 @@ public class MallStaffLoginInfo extends SysUser {
* 角色id
*/
private String roleId;
/**
* 品牌id
*/
private String brandId;
}

View File

@ -80,7 +80,7 @@ public class SysLoginInfoBuild extends AbstractLoginInfoBuild {
if (!staffLoginInfo.getUserName().equals(Constants.SUPER_ADMIN)) {
Row row = DbChain.table("cp_mall_staff")
.select("cms.id", "cms.name", "cms.user_id")
.select("cmrb.role_id")
.select("cmrb.role_id", "cmrb.brand_id")
.from("cp_mall_staff").as("cms")
.leftJoin("cp_mall_role_brand").as("cmrb").on("cmrb.id = cms.role_brand_id")
.where("cms.user_id = ?", staffLoginInfo.getUserId())
@ -92,6 +92,7 @@ public class SysLoginInfoBuild extends AbstractLoginInfoBuild {
staffLoginInfo.setRoleId(row.getString("roleId"));
staffLoginInfo.setName(row.getString("name"));
staffLoginInfo.setId(row.getString("id"));
staffLoginInfo.setBrandId(row.getString("brandId"));
} else {
staffLoginInfo.setName(Constants.SUPER_ADMIN);
}

View File

@ -24,6 +24,12 @@ public class CardTemplateListVo implements Serializable {
@ApiModelProperty(value = "主键")
private String id;
/**
* 品牌id
*/
@ApiModelProperty(value = "品牌id")
private String brandId;
/**
* 云品牌id
*/

View File

@ -16,10 +16,6 @@ cpop:
spring:
application:
name: Cpop-Mall-Dev
datasource:
url: jdbc:mysql://localhost:3306/cpop-dev?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
username: root
password: root
#redis配置
redis:
#地址
@ -57,6 +53,15 @@ server:
mybatis-flex:
configuration:
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
datasource:
mall:
url: jdbc:mysql://localhost:3306/cpop-dev?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
username: root
password: root
jambox:
url: jdbc:mysql://sh-cynosdbmysql-grp-fggo83js.sql.tencentcdb.com:20965/jambox_test?useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true
username: root
password: Customer0401
# springdoc-openapi项目配置
knife4j:
@ -73,11 +78,18 @@ knife4j:
terms-of-service-url: https://api.jamboxsys.com
group:
#商城
Mall:
group-name: Mall
Mall-Backstage:
#后台
group-name: Mall-Backstage
api-rule: package
api-rule-resources:
- com.cpop.mall
- com.cpop.mall.business.controller.backstage
Mall-Mini:
#后台
group-name: Mall-Mini
api-rule: package
api-rule-resources:
- com.cpop.mall.business.controller.mini
#系统
System:
group-name: System

View File

@ -77,7 +77,6 @@ public class MallRoleBo implements Serializable {
/**
* 品牌id
*/
@NotBlank(message = "品牌id不能为空")
@ApiModelProperty(value = "品牌id",required = true)
@ApiModelProperty(value = "品牌id")
private String brandId;
}

View File

@ -0,0 +1,89 @@
package com.cpop.mall.business.bo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.util.List;
/**
* @author DB
* @createTime 2023/10/23 12:01
* @description
*/
@Data
@Accessors(chain = true)
@ApiModel(value = "商城商品请求对象")
public class ProductBo implements Serializable {
/**
* 主键
*/
@ApiModelProperty("主键")
private String id;
/**
* 商品名
*/
@NotBlank(message = "商品名不能为空")
@ApiModelProperty("商品名")
private String productName;
/**
* 产品类型(0:课卡;1:周边;2:优惠卷:3:其他)
*/
@NotNull(message = "产品类型不能为空")
@ApiModelProperty("产品类型(0:课卡;1:周边;2:优惠卷:3:其他)")
private Integer productType;
/**
* 品牌id
*/
@ApiModelProperty("品牌id")
private String brandId;
/**
* 商店(校区)集合
*/
@ApiModelProperty("商店(校区)集合")
private String storeIds;
/**
* 描述
*/
@NotBlank(message = "描述不能为空")
@ApiModelProperty("描述")
private String description;
/**
* 商品图地址
*/
@NotBlank(message = "商品图地址不能为空")
@ApiModelProperty("商品图地址")
private String picUrl;
/**
* 购买限制(0:会员限制;1:新客限定;2:用户限购)
*/
@NotNull(message = "购买限制不能为空")
@ApiModelProperty("购买限制(0:会员限制;1:新客限定;2:用户限购)")
private Integer buyRestrict;
/**
* 规格集合
*/
@ApiModelProperty("规格集合")
private List<ProductSpecificationBo> specificationList;
/**
* 规格详情
*/
@NotEmpty(message = "规格详情不能为空")
@ApiModelProperty("规格详情")
private List<ProductRecordBo> recordList;
}

View File

@ -0,0 +1,27 @@
package com.cpop.mall.business.bo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import java.io.Serializable;
/**
* @author DB
* @createTime 2023/10/23 11:53
* @description
*/
@Data
@Accessors(chain = true)
@ApiModel(value = "商城商品分页请求对象")
public class ProductPageBo implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 商品名
*/
@ApiModelProperty("商品名")
private String productName;
}

View File

@ -0,0 +1,50 @@
package com.cpop.mall.business.bo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import java.io.Serializable;
import java.math.BigDecimal;
/**
* @author DB
* @createTime 2023/10/23 16:29
* @description
*/
@Data
@Accessors(chain = true)
@ApiModel(value = "商城商品规格详情对象")
public class ProductRecordBo implements Serializable {
/**
* 主键
*/
@ApiModelProperty("主键")
private String id;
/**
* 记录集合
*/
@ApiModelProperty("记录集合")
private String recordNames;
/**
* 数量
*/
@ApiModelProperty("数量")
private Integer recordNum;
/**
* 记录消耗金额
*/
@ApiModelProperty("记录消耗金额")
private BigDecimal recordPrice;
/**
* 记录消耗积分
*/
@ApiModelProperty("记录消耗积分")
private Integer recordPoints;
}

View File

@ -0,0 +1,40 @@
package com.cpop.mall.business.bo;
import com.mybatisflex.annotation.Id;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import java.io.Serializable;
/**
* @author DB
* @createTime 2023/10/23 16:41
* @description
*/
@Data
@Accessors(chain = true)
@ApiModel(value = "商城商品规格对象")
public class ProductSpecificationBo implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 主键
*/
@ApiModelProperty("主键")
private String id;
/**
* 产品id
*/
@ApiModelProperty("产品id")
private String productId;
/**
* 规格名
*/
@ApiModelProperty("规格名")
private String specificationNames;
}

View File

@ -1,4 +1,4 @@
package com.cpop.mall.business.controller;
package com.cpop.mall.business.controller.backstage;
import com.cpop.core.base.R;
import com.cpop.mall.business.bo.MallRoleBo;
@ -26,8 +26,8 @@ import java.util.List;
*/
@RestController
@Api(tags = "商城角色定制接口")
@RequestMapping("/mallRole")
public class MallRoleController {
@RequestMapping("/backstage/mallRole")
public class BackstageMallRoleController {
@Autowired
private RoleBrandService roleBrandService;

View File

@ -0,0 +1,153 @@
package com.cpop.mall.business.controller.backstage;
import com.cpop.core.base.R;
import com.cpop.core.utils.SpringUtils;
import com.cpop.jambox.business.entity.CardTemplate;
import com.cpop.jambox.business.vo.CardTemplateListVo;
import com.cpop.mall.business.bo.ProductBo;
import com.cpop.mall.business.bo.ProductPageBo;
import com.cpop.mall.business.service.ProductRecordService;
import com.cpop.mall.business.service.ProductSpecificationService;
import com.cpop.mall.business.vo.ProductPageVo;
import com.mybatisflex.core.paginate.Page;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.beans.factory.annotation.Autowired;
import com.cpop.mall.business.service.ProductService;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import java.io.Serializable;
import java.util.List;
import static com.cpop.mall.business.entity.table.ProductRecordTableDef.PRODUCT_RECORD;
import static com.cpop.mall.business.entity.table.ProductSpecificationTableDef.PRODUCT_SPECIFICATION;
/**
* 商城-商品表 控制层
*
* @author DB
* @since 2023-10-23
*/
@RestController
@Api(tags = "商城-商品管理")
@RequestMapping("/backstage/product")
public class BackstageProductController {
@Autowired
private ProductService productService;
/**
* @descriptions 分页查询商城-商品
* @author DB
* @date 2023/10/23 11:56
* @param bo 分页参数
* @return: com.cpop.core.base.R<com.mybatisflex.core.paginate.Page<com.cpop.mall.business.entity.Product>>
*/
@GetMapping("/getProductPage")
@ApiOperation("分页查询商城-商品")
public R<Page<ProductPageVo>> getProductPage(@ApiParam("分页参数") ProductPageBo bo) {
Page<ProductPageVo> page = productService.getProductPage(bo);
return R.ok(page);
}
/**
* @descriptions 获取果酱课卡模板
* @author DB
* @date 2023/10/23 11:56
* @return: com.cpop.core.base.R<com.mybatisflex.core.paginate.Page<com.cpop.mall.business.entity.Product>>
*/
@GetMapping("/getJamboxCardTemplate")
@ApiOperation("获取果酱课卡模板")
public R<List<CardTemplateListVo>> getJamboxCardTemplate() {
List<CardTemplateListVo> list = productService.getJamboxCardTemplate();
return R.ok(list);
}
/**
* @descriptions 创建规格
* @author DB
* @date 2023/10/23 12:15
* @param specificationGroups 规格集合
* @return: com.cpop.core.base.R<java.lang.Void>
*/
@PostMapping("/createSpecification")
@ApiOperation("创建规格")
public R<List<String>> createSpecification(@RequestBody @ApiParam("规格集合") List<List<String>> specificationGroups) {
List<String> list = productService.createSpecification(specificationGroups);
return R.ok(list);
}
/**
* @descriptions 保存商城-商品
* @author DB
* @date 2023/10/23 12:15
* @param bo 商城-商品
* @return: com.cpop.core.base.R<java.lang.Void>
*/
@PostMapping("/insertProduct")
@ApiOperation("保存商城-商品")
public R<Void> insertProduct(@RequestBody @Validated @ApiParam("商城-商品") ProductBo bo) {
productService.insertProduct(bo);
return R.ok();
}
/**
* @descriptions 根据主键重置商城商品
* @author DB
* @date 2023/10/23 12:15
* @param id 商城-商品id
* @return: com.cpop.core.base.R<java.lang.Void>
*/
@PutMapping("/resetProduct/{id}")
@ApiOperation("根据主键重置商城商品")
public R<Void> update(@PathVariable String id) {
productService.resetProduct(id);
return R.ok();
}
/**
* @descriptions 根据主键重置商城商品
* @author DB
* @date 2023/10/23 12:15
* @param bo 商城-商品
* @return: com.cpop.core.base.R<java.lang.Void>
*/
@PutMapping("/updateProduct")
@ApiOperation("根据主键更新商城-商品")
public R<Void> updateProduct(@RequestBody @Validated @ApiParam("商城-商品") ProductBo bo) {
productService.updateProduct(bo);
return R.ok();
}
/**
* 根据主键删除商城-商品表
*
* @param id 主键
* @return {@code true} 删除成功{@code false} 删除失败
*/
@DeleteMapping("/removeById/{id}")
@ApiOperation("根据主键商城-商品表")
@Transactional(rollbackFor = Exception.class)
public R<Void> removeById(@PathVariable @ApiParam("商城-商品主键") Serializable id) {
productService.removeById(id);
//删规格
ProductSpecificationService productSpecificationService = SpringUtils.getBean(ProductSpecificationService.class);
productSpecificationService.updateChain().where(PRODUCT_SPECIFICATION.PRODUCT_ID.eq(id)).remove();
//删商品记录详情
ProductRecordService specificationRecordService = SpringUtils.getBean(ProductRecordService.class);
specificationRecordService.updateChain().where(PRODUCT_RECORD.PRODUCT_ID.eq(id)).remove();
return R.ok();
}
}

View File

@ -1,4 +1,4 @@
package com.cpop.mall.business.controller;
package com.cpop.mall.business.controller.backstage;
import com.alibaba.fastjson.JSONObject;
import com.cpop.common.constant.Constants;
@ -48,8 +48,8 @@ import static com.cpop.system.business.entity.table.RoleTableDef.ROLE;
*/
@RestController
@Api(tags = "商城员工接口")
@RequestMapping("/mallStaff")
public class StaffController {
@RequestMapping("/backstage/mallStaff")
public class BackstageStaffController {
@Autowired
private StaffService staffService;

View File

@ -0,0 +1,82 @@
package com.cpop.mall.business.entity;
import com.cpop.core.base.entity.BaseEntity;
import com.cpop.core.base.entity.BaseInsertListener;
import com.cpop.core.base.entity.BaseUpdateListener;
import com.mybatisflex.annotation.Column;
import com.mybatisflex.annotation.Id;
import com.mybatisflex.annotation.Table;
import java.io.Serializable;
import java.time.LocalDateTime;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;
import lombok.experimental.Accessors;
/**
* 商城-商品表 实体类
*
* @author DB
* @since 2023-10-23
*/
@Data
@EqualsAndHashCode(callSuper=false)
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Accessors(chain = true)
@Table(value = "cp_mall_product", onInsert = BaseInsertListener.class, onUpdate = BaseUpdateListener.class, mapperGenerateEnable = false)
public class Product extends BaseEntity implements Serializable {
/**
* 主键
*/
@Id
private String id;
/**
* 商品名
*/
private String productName;
/**
* 产品类型(0:课卡;1:周边;2:优惠卷:3:其他)
*/
private Integer productType;
/**
* 品牌id
*/
private String brandId;
/**
* 商店(校区)集合
*/
private String storeIds;
/**
* 描述
*/
private String description;
/**
* 商品图地址
*/
private String picUrl;
/**
* 购买限制(0:会员限制;1:新客限定;2:用户限购)
*/
private Integer buyRestrict;
/**
* 逻辑删除0否1是
*/
@Column(isLogicDelete = true)
private Boolean isDelete;
}

View File

@ -0,0 +1,67 @@
package com.cpop.mall.business.entity;
import com.cpop.core.base.entity.BaseEntity;
import com.cpop.core.base.entity.BaseInsertListener;
import com.cpop.core.base.entity.BaseUpdateListener;
import com.mybatisflex.annotation.Column;
import com.mybatisflex.annotation.Id;
import com.mybatisflex.annotation.Table;
import java.io.Serializable;
import java.math.BigDecimal;
import lombok.*;
import lombok.experimental.Accessors;
/**
* 商城-商品-规格记录 实体类
*
* @author DB
* @since 2023-10-23
*/
@Data
@EqualsAndHashCode(callSuper=false)
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Accessors(chain = true)
@Table(value = "cp_mall_product_specification_record", onInsert = BaseInsertListener.class, onUpdate = BaseUpdateListener.class, mapperGenerateEnable = false)
public class ProductRecord extends BaseEntity implements Serializable {
/**
* 主键
*/
@Id
private String id;
/**
* 商品id
*/
private String productId;
/**
* 规格集合
*/
private String recordNames;
/**
* 数量
*/
private Integer recordNum;
/**
* 记录消耗金额
*/
private BigDecimal recordPrice;
/**
* 记录消耗积分
*/
private Integer recordPoints;
/**
* 逻辑删除0否1是
*/
@Column(isLogicDelete = true)
private Boolean isDelete;
}

View File

@ -0,0 +1,53 @@
package com.cpop.mall.business.entity;
import com.cpop.core.base.entity.BaseEntity;
import com.cpop.core.base.entity.BaseInsertListener;
import com.cpop.core.base.entity.BaseUpdateListener;
import com.mybatisflex.annotation.Column;
import com.mybatisflex.annotation.Id;
import com.mybatisflex.annotation.Table;
import java.io.Serializable;
import java.time.LocalDateTime;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;
import lombok.experimental.Accessors;
/**
* 商城-商品-规格 实体类
*
* @author DB
* @since 2023-10-23
*/
@Data
@EqualsAndHashCode(callSuper=false)
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Accessors(chain = true)
@Table(value = "cp_mall_product_specification", onInsert = BaseInsertListener.class, onUpdate = BaseUpdateListener.class, mapperGenerateEnable = false)
public class ProductSpecification extends BaseEntity implements Serializable {
/**
* 主键
*/
@Id
private String id;
/**
* 产品id
*/
private String productId;
/**
* 规格名
*/
private String specificationNames;
/**
* 逻辑删除0否1是
*/
@Column(isLogicDelete = true)
private Boolean isDelete;
}

View File

@ -37,7 +37,7 @@ public class RoleBrand extends BaseEntity implements Serializable {
private String roleId;
/**
* 校区id
* 品牌id
*/
private String brandId;

View File

@ -0,0 +1,14 @@
package com.cpop.mall.business.mapper;
import com.mybatisflex.core.BaseMapper;
import com.cpop.mall.business.entity.Product;
/**
* 商城-商品表 映射层
*
* @author DB
* @since 2023-10-23
*/
public interface ProductMapper extends BaseMapper<Product> {
}

View File

@ -0,0 +1,14 @@
package com.cpop.mall.business.mapper;
import com.mybatisflex.core.BaseMapper;
import com.cpop.mall.business.entity.ProductRecord;
/**
* 商城-商品-规格记录 映射层
*
* @author DB
* @since 2023-10-23
*/
public interface ProductRecordMapper extends BaseMapper<ProductRecord> {
}

View File

@ -0,0 +1,14 @@
package com.cpop.mall.business.mapper;
import com.mybatisflex.core.BaseMapper;
import com.cpop.mall.business.entity.ProductSpecification;
/**
* 商城-商品-规格 映射层
*
* @author DB
* @since 2023-10-23
*/
public interface ProductSpecificationMapper extends BaseMapper<ProductSpecification> {
}

View File

@ -0,0 +1,14 @@
package com.cpop.mall.business.service;
import com.mybatisflex.core.service.IService;
import com.cpop.mall.business.entity.ProductRecord;
/**
* 商城-商品-规格记录 服务层
*
* @author DB
* @since 2023-10-23
*/
public interface ProductRecordService extends IService<ProductRecord> {
}

View File

@ -0,0 +1,75 @@
package com.cpop.mall.business.service;
import com.cpop.jambox.business.entity.CardTemplate;
import com.cpop.jambox.business.vo.CardTemplateListVo;
import com.cpop.mall.business.bo.ProductBo;
import com.cpop.mall.business.bo.ProductPageBo;
import com.cpop.mall.business.vo.ProductPageVo;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.service.IService;
import com.cpop.mall.business.entity.Product;
import java.util.List;
/**
* 商城-商品表 服务层
*
* @author DB
* @since 2023-10-23
*/
public interface ProductService extends IService<Product> {
/**
* @descriptions 分页查询商城-商品
* @author DB
* @date 2023/10/23 11:59
* @param bo 请求参数
* @return: com.mybatisflex.core.paginate.Page<com.cpop.mall.business.entity.Product>
*/
Page<ProductPageVo> getProductPage(ProductPageBo bo);
/**
* @descriptions 创建规格
* @author DB
* @date 2023/10/23 12:43
* @param specificationGroups 请求参数
* @return: java.util.List<com.cpop.mall.business.vo.ProductSpecificationCreateVo>
*/
List<String> createSpecification(List<List<String>> specificationGroups);
/**
* @descriptions 保存商城-商品
* @author DB
* @date 2023/10/23 12:15
* @param bo 请求参数
* @return: void
*/
void insertProduct(ProductBo bo);
/**
* @descriptions 根据主键更新商城-商品
* @author DB
* @date 2023/10/23 16:51
* @param bo 请求参数
* @return: void
*/
void updateProduct(ProductBo bo);
/**
* @descriptions 根据主键重置商城商品
* @author DB
* @date 2023/10/23 17:21
* @param id
* @return: void
*/
void resetProduct(String id);
/**
* @descriptions 获取果酱课卡模板
* @author DB
* @date 2023/10/23 18:11
* @param
* @return: java.util.List<com.cpop.jambox.business.entity.CardTemplate>
*/
List<CardTemplateListVo> getJamboxCardTemplate();
}

View File

@ -0,0 +1,14 @@
package com.cpop.mall.business.service;
import com.mybatisflex.core.service.IService;
import com.cpop.mall.business.entity.ProductSpecification;
/**
* 商城-商品-规格 服务层
*
* @author DB
* @since 2023-10-23
*/
public interface ProductSpecificationService extends IService<ProductSpecification> {
}

View File

@ -0,0 +1,18 @@
package com.cpop.mall.business.service.impl;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import com.cpop.mall.business.entity.ProductRecord;
import com.cpop.mall.business.mapper.ProductRecordMapper;
import com.cpop.mall.business.service.ProductRecordService;
import org.springframework.stereotype.Service;
/**
* 商城-商品-规格记录 服务层实现
*
* @author DB
* @since 2023-10-23
*/
@Service("productSpecificationRecordService")
public class ProductRecordServiceImpl extends ServiceImpl<ProductRecordMapper, ProductRecord> implements ProductRecordService {
}

View File

@ -0,0 +1,200 @@
package com.cpop.mall.business.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.cpop.common.utils.StringUtils;
import com.cpop.common.utils.bean.BeanUtils;
import com.cpop.core.base.entity.PageDomain;
import com.cpop.core.utils.SecurityUtils;
import com.cpop.core.utils.SpringUtils;
import com.cpop.core.utils.sql.SqlUtils;
import com.cpop.jambox.business.entity.CardTemplate;
import com.cpop.jambox.business.vo.CardTemplateListVo;
import com.cpop.mall.business.bo.ProductBo;
import com.cpop.mall.business.bo.ProductPageBo;
import com.cpop.mall.business.entity.ProductSpecification;
import com.cpop.mall.business.entity.ProductRecord;
import com.cpop.mall.business.service.ProductRecordService;
import com.cpop.mall.business.service.ProductSpecificationService;
import com.cpop.mall.business.vo.ProductPageVo;
import com.mybatisflex.core.datasource.DataSourceKey;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.core.row.Db;
import com.mybatisflex.core.row.Row;
import com.mybatisflex.core.row.RowUtil;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import com.cpop.mall.business.entity.Product;
import com.cpop.mall.business.mapper.ProductMapper;
import com.cpop.mall.business.service.ProductService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.List;
import static com.cpop.mall.business.entity.table.ProductRecordTableDef.PRODUCT_RECORD;
import static com.cpop.mall.business.entity.table.ProductSpecificationTableDef.PRODUCT_SPECIFICATION;
import static com.cpop.mall.business.entity.table.ProductTableDef.PRODUCT;
/**
* 商城-商品表 服务层实现
*
* @author DB
* @since 2023-10-23
*/
@Service("productService")
public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> implements ProductService {
/**
* @descriptions 分页查询商城-商品
* @author DB
* @date 2023/10/23 11:59
* @param bo 请求参数
* @return: com.mybatisflex.core.paginate.Page<com.cpop.mall.business.entity.Product>
*/
@Override
public Page<ProductPageVo> getProductPage(ProductPageBo bo) {
//获取当前用户品牌
JSONObject loginStaffInfo = SecurityUtils.getInstance().getLoginStaffInfo();
PageDomain pageDomain = SqlUtils.getInstance().getPageDomain();
return this.mapper.paginateWithRelationsAs(pageDomain.getPageNum(), pageDomain.getPageSize(),
QueryWrapper.create()
.where(PRODUCT.BRAND_ID.eq(loginStaffInfo.getString("brandId")))
.and(PRODUCT.PRODUCT_NAME.like(bo.getProductName()))
.orderBy(PRODUCT.CREATE_TIME.asc())
,
ProductPageVo.class);
}
/**
* @descriptions 创建规格
* @author DB
* @date 2023/10/23 12:43
* @param specificationGroups 请求参数
* @return: java.util.List<com.cpop.mall.business.vo.ProductSpecificationCreateVo>
*/
@Override
public List<String> createSpecification(List<List<String>> specificationGroups) {
return recursionCreateSpecification(specificationGroups, 0, "", new ArrayList<>());
}
/**
* @descriptions 递归创建
* @author DB
* @date 2023/10/23 16:20
* @param list 属性值列表
* @param index 下标
* @param str 初始化数据
* @param newObjs 新obj
* @return: java.util.List<java.lang.String>
*/
private List<String> recursionCreateSpecification(List<List<String>> list, int index, String str, List<String> newObjs) {
if (index == list.size()) {
newObjs.add(str);
return newObjs;
}
for (String dataStr : list.get(index)) {
if (StringUtils.isBlank(str)) {
recursionCreateSpecification(list, index + 1, str + dataStr, newObjs);
} else {
recursionCreateSpecification(list, index + 1, str + "," + dataStr, newObjs);
}
}
return newObjs;
}
/**
* @descriptions 保存商城-商品
* @author DB
* @date 2023/10/23 12:15
* @param bo 请求参数
* @return: void
*/
@Override
@Transactional(rollbackFor = Exception.class)
public void insertProduct(ProductBo bo) {
Product product = BeanUtils.mapToClass(bo, Product.class);
if (StringUtils.isBlank(bo.getBrandId())){
JSONObject loginStaffInfo = SecurityUtils.getInstance().getLoginStaffInfo();
product.setBrandId(loginStaffInfo.getString("brandId"));
}
this.save(product);
//保存规格
ProductSpecificationService productSpecificationService = SpringUtils.getBean(ProductSpecificationService.class);
List<ProductSpecification> productSpecifications = BeanUtils.mapToList(bo.getSpecificationList(), ProductSpecification.class);
productSpecifications.forEach(item -> {
item.setProductId(product.getId());
});
productSpecificationService.saveBatch(productSpecifications);
//保存商品记录
List<ProductRecord> recordList = BeanUtils.mapToList(bo.getRecordList(), ProductRecord.class);
ProductRecordService specificationRecordService = SpringUtils.getBean(ProductRecordService.class);
recordList.forEach(item -> {
item.setProductId(product.getId());
});
specificationRecordService.saveBatch(recordList);
}
/**
* @descriptions 根据主键更新商城-商品
* @author DB
* @date 2023/10/23 16:51
* @param bo 请求参数
* @return: void
*/
@Override
@Transactional(rollbackFor = Exception.class)
public void updateProduct(ProductBo bo) {
Product product = BeanUtils.mapToClass(bo, Product.class);
this.updateById(product);
//保存规格
ProductSpecificationService productSpecificationService = SpringUtils.getBean(ProductSpecificationService.class);
List<ProductSpecification> productSpecifications = BeanUtils.mapToList(bo.getSpecificationList(), ProductSpecification.class);
productSpecifications.forEach(item -> {
item.setProductId(product.getId());
});
productSpecificationService.saveBatch(productSpecifications);
//存商品记录详情
List<ProductRecord> recordList = BeanUtils.mapToList(bo.getRecordList(), ProductRecord.class);
ProductRecordService specificationRecordService = SpringUtils.getBean(ProductRecordService.class);
specificationRecordService.updateChain().where(PRODUCT_RECORD.PRODUCT_ID.eq(product.getId())).remove();
recordList.forEach(item -> {
item.setProductId(product.getId());
});
specificationRecordService.saveBatch(recordList);
}
/**
* @descriptions 根据主键重置商城商品
* @author DB
* @date 2023/10/23 17:21
* @param id 主键
* @return: void
*/
@Override
public void resetProduct(String id) {
//删规格
ProductSpecificationService productSpecificationService = SpringUtils.getBean(ProductSpecificationService.class);
productSpecificationService.updateChain().where(PRODUCT_SPECIFICATION.PRODUCT_ID.eq(id)).remove();
//删商品记录详情
ProductRecordService specificationRecordService = SpringUtils.getBean(ProductRecordService.class);
specificationRecordService.updateChain().where(PRODUCT_RECORD.PRODUCT_ID.eq(id)).remove();
}
/**
* @descriptions 获取果酱课卡模板
* @author DB
* @date 2023/10/23 18:11
* @return: java.util.List<com.cpop.jambox.business.entity.CardTemplate>
*/
@Override
public List<CardTemplateListVo> getJamboxCardTemplate() {
JSONObject loginStaffInfo = SecurityUtils.getInstance().getLoginStaffInfo();
//多数据源
DataSourceKey.use("jambox");
List<Row> rowList = Db.selectListByQuery("t_card_template", QueryWrapper.create()
.select("template_id AS id,brand_id,name")
.where("brand_id = ?", loginStaffInfo.getString("brandId")));
return RowUtil.toEntityList(rowList, CardTemplateListVo.class);
}
}

View File

@ -0,0 +1,18 @@
package com.cpop.mall.business.service.impl;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import com.cpop.mall.business.entity.ProductSpecification;
import com.cpop.mall.business.mapper.ProductSpecificationMapper;
import com.cpop.mall.business.service.ProductSpecificationService;
import org.springframework.stereotype.Service;
/**
* 商城-商品-规格 服务层实现
*
* @author DB
* @since 2023-10-23
*/
@Service("productSpecificationService")
public class ProductSpecificationServiceImpl extends ServiceImpl<ProductSpecificationMapper, ProductSpecification> implements ProductSpecificationService {
}

View File

@ -1,6 +1,7 @@
package com.cpop.mall.business.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.cpop.common.utils.StringUtils;
import com.cpop.common.utils.bean.BeanUtils;
import com.cpop.core.base.entity.PageDomain;
import com.cpop.core.utils.SecurityUtils;
@ -103,8 +104,14 @@ public class RoleBrandServiceImpl extends ServiceImpl<RoleBrandMapper, RoleBrand
}
//录入商城角色品牌表
RoleBrand roleBrand = new RoleBrand();
roleBrand.setRoleId(role.getId())
.setBrandId(bo.getBrandId());
if (StringUtils.isBlank(bo.getBrandId())){
JSONObject loginStaffInfo = SecurityUtils.getInstance().getLoginStaffInfo();
roleBrand.setRoleId(role.getId())
.setBrandId(loginStaffInfo.getString("brandId"));
} else {
roleBrand.setRoleId(role.getId())
.setBrandId(bo.getBrandId());
}
this.save(roleBrand);
}

View File

@ -117,8 +117,7 @@ public class StaffServiceImpl extends ServiceImpl<StaffMapper, Staff> implements
} else {
//获取当前用户信息
JSONObject loginStaffInfo = SecurityUtils.getInstance().getLoginStaffInfo();
RoleBrand roleBrandId = roleBrandService.queryChain().where(ROLE_BRAND.ID.eq(loginStaffInfo.get("roleBrandId"))).one();
roleBrand.setBrandId(roleBrandId.getBrandId());
roleBrand.setBrandId(loginStaffInfo.getString("brandId"));
}
roleBrand.setRoleId(bo.getRoleId());
//设置中间表

View File

@ -0,0 +1,84 @@
package com.cpop.mall.business.vo;
import com.cpop.mall.business.entity.ProductSpecification;
import com.mybatisflex.annotation.RelationOneToMany;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import java.io.Serializable;
import java.util.List;
/**
* @author DB
* @createTime 2023/10/23 11:57
* @description
*/
@Data
@Accessors(chain = true)
@ApiModel(value = "商城商品分页返回对象")
public class ProductPageVo implements Serializable {
/**
* 主键
*/
@ApiModelProperty("主键")
private String id;
/**
* 商品名
*/
@ApiModelProperty("商品名")
private String productName;
/**
* 产品类型(0:课卡;1:周边;2:优惠卷:3:其他)
*/
@ApiModelProperty("产品类型(0:课卡;1:周边;2:优惠卷:3:其他)")
private Integer productType;
/**
* 品牌id
*/
@ApiModelProperty("品牌id")
private String brandId;
/**
* 商店(校区)集合
*/
@ApiModelProperty("商店(校区)集合")
private String storeIds;
/**
* 描述
*/
@ApiModelProperty("描述")
private String description;
/**
* 商品图地址
*/
@ApiModelProperty("商品图地址")
private String picUrl;
/**
* 购买限制(0:会员限制;1:新客限定;2:用户限购)
*/
@ApiModelProperty("购买限制(0:会员限制;1:新客限定;2:用户限购)")
private Integer buyRestrict;
/**
* 产品规格
*/
@RelationOneToMany(selfField = "id", targetField = "productId")
@ApiModelProperty("产品规格")
private List<ProductSpecificationVo> productSpecificationVos;
/**
* 产品规格记录
*/
@RelationOneToMany(selfField = "id", targetField = "productId")
@ApiModelProperty("产品规格记录")
private List<ProductRecordVo> productRecordVos;
}

View File

@ -0,0 +1,59 @@
package com.cpop.mall.business.vo;
import com.cpop.core.annontation.StringArrayConvert;
import com.mybatisflex.annotation.Id;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import java.io.Serializable;
import java.math.BigDecimal;
/**
* @author DB
* @createTime 2023/10/23 17:36
* @description
*/
@Data
@Accessors(chain = true)
@ApiModel(value = "商城商品记录返回对象")
public class ProductRecordVo implements Serializable {
/**
* 主键
*/
@ApiModelProperty("主键")
private String id;
/**
* 商品id
*/
@ApiModelProperty("商品id")
private String productId;
/**
* 规格集合
*/
@StringArrayConvert
@ApiModelProperty("规格集合")
private String recordNames;
/**
* 数量
*/
@ApiModelProperty("数量")
private Integer recordNum;
/**
* 记录消耗金额
*/
@ApiModelProperty("记录消耗金额")
private BigDecimal recordPrice;
/**
* 记录消耗积分
*/
@ApiModelProperty("记录消耗积分")
private Integer recordPoints;
}

View File

@ -0,0 +1,47 @@
package com.cpop.mall.business.vo;
import com.cpop.core.annontation.StringArrayConvert;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.List;
/**
* @author DB
* @createTime 2023/10/23 12:37
* @description
*/
@Data
@Accessors(chain = true)
@ApiModel(value = "商城商品规格创建返回对象")
public class ProductSpecificationCreateVo implements Serializable {
/**
* 规格名
*/
@StringArrayConvert
@ApiModelProperty("规格名")
private String specificationNames;
/**
* 数量
*/
@ApiModelProperty("数量")
private Integer recordNum;
/**
* 记录消耗金额
*/
@ApiModelProperty("记录消耗金额")
private BigDecimal recordPrice;
/**
* 记录消耗积分
*/
@ApiModelProperty("记录消耗积分")
private Integer recordPoints;
}

View File

@ -0,0 +1,40 @@
package com.cpop.mall.business.vo;
import com.cpop.core.annontation.StringArrayConvert;
import com.mybatisflex.annotation.Id;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import java.io.Serializable;
/**
* @author DB
* @createTime 2023/10/23 17:33
* @description
*/
@Data
@Accessors(chain = true)
@ApiModel(value = "商城商品规格返回对象")
public class ProductSpecificationVo implements Serializable {
/**
* 主键
*/
@ApiModelProperty("主键")
private String id;
/**
* 产品id
*/
@ApiModelProperty("产品id")
private String productId;
/**
* 规格名
*/
@ApiModelProperty("规格名")
@StringArrayConvert
private String specificationNames;
}

View File

@ -0,0 +1,7 @@
<?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.cpop.mall.business.mapper.ProductMapper">
</mapper>

View File

@ -0,0 +1,7 @@
<?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.cpop.mall.business.mapper.ProductRecordMapper">
</mapper>

View File

@ -0,0 +1,7 @@
<?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.cpop.mall.business.mapper.ProductSpecificationMapper">
</mapper>