提交 03c6a1c0 作者: xiaowang

功能:租赁商品列表

上级 08d02e17
......@@ -8,12 +8,16 @@ package com.mmc.pms.controller.lease;
import com.mmc.pms.common.ResultBody;
import com.mmc.pms.controller.BaseController;
import com.mmc.pms.model.group.Create;
import com.mmc.pms.model.group.Update;
import com.mmc.pms.model.lease.qo.LeaseGoodsQO;
import com.mmc.pms.model.lease.vo.LeaseGoodsVO;
import com.mmc.pms.service.lease.LeaseGoodsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
......@@ -33,7 +37,7 @@ public class LeaseGoodsController extends BaseController {
@ApiOperation(value = "新增租赁商品")
@PostMapping("addLeaseGoods")
@ApiResponses({@ApiResponse(code = 200, message = "OK", response = ResultBody.class)})
public ResultBody addLeaseGoods(@RequestBody LeaseGoodsVO leaseGoodsVO, HttpServletRequest request) {
public ResultBody addLeaseGoods(@Validated(value = {Create.class}) @RequestBody LeaseGoodsVO leaseGoodsVO, HttpServletRequest request) {
return leaseGoodsService.addLeaseGoods(leaseGoodsVO, this.getUserLoginInfoFromRedis(request).getUserAccountId());
}
......@@ -55,7 +59,14 @@ public class LeaseGoodsController extends BaseController {
@ApiOperation(value = "编辑租赁商品")
@PostMapping("editLeaseGoods")
@ApiResponses({@ApiResponse(code = 200, message = "OK", response = ResultBody.class)})
public ResultBody editLeaseGoods(@RequestBody LeaseGoodsVO leaseGoodsVO, HttpServletRequest request) {
public ResultBody editLeaseGoods(@Validated(value = {Update.class}) @RequestBody LeaseGoodsVO leaseGoodsVO, HttpServletRequest request) {
return leaseGoodsService.editLeaseGoods(leaseGoodsVO, this.getUserLoginInfoFromRedis(request).getUserAccountId());
}
@ApiOperation(value = "租赁商品列表")
@PostMapping("leaseGoodsList")
@ApiResponses({@ApiResponse(code = 200, message = "OK", response = LeaseGoodsVO.class)})
public ResultBody leaseGoodsList(@RequestBody LeaseGoodsQO param, HttpServletRequest request) {
return leaseGoodsService.leaseGoodsList(param, this.getUserLoginInfoFromRedis(request));
}
}
......@@ -4,6 +4,7 @@ import com.mmc.pms.entity.lease.*;
import com.mmc.pms.entity.mall.MallGoodsResourcesDO;
import com.mmc.pms.entity.mall.SpecAttrDO;
import com.mmc.pms.entity.mall.SpecAttrValueDO;
import com.mmc.pms.model.lease.qo.LeaseGoodsQO;
import com.mmc.pms.model.lease.vo.LeaseGoodsVO;
import com.mmc.pms.model.mall.SpecAttrVO;
import org.apache.ibatis.annotations.Mapper;
......@@ -61,4 +62,8 @@ public interface LeaseGoodsDao {
void updateSpecAttr(SpecAttrVO specAttrVO);
void deleteSpecAttrValue(List<Integer> delValueIds);
int countLeaseGoods(LeaseGoodsQO param);
List<LeaseGoodsDO> listLeaseGoods(LeaseGoodsQO param);
}
......@@ -4,9 +4,12 @@ import com.mmc.pms.model.lease.vo.LeaseGoodsVO;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.collections4.CollectionUtils;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
/**
* 租赁商品信息(LeaseGoodsDO)实体类
......@@ -92,6 +95,18 @@ public class LeaseGoodsDO implements Serializable {
private Integer sort;
/**
* 辅助字段 begin
*/
// 图片
private List<LeaseGoodsResourcesDO> leaseGoodsResources;
// 规格排列组合
private List<LeasePriceStockDO> priceStockList;
/**
* 辅助字段end
*/
public LeaseGoodsDO(LeaseGoodsVO leaseGoodsVO) {
this.id = leaseGoodsVO.getId();
this.tradeName = leaseGoodsVO.getTradeName();
......@@ -118,7 +133,11 @@ public class LeaseGoodsDO implements Serializable {
.productParam(productParam).productDetails(productDetails).minLeaseTerm(minLeaseTerm)
.maxLeaseTerm(maxLeaseTerm).shipAddress(shipAddress).returnAddress(returnAddress)
.logisticsCompany(logisticsCompany).modeOfDelivery(modeOfDelivery).createTime(createTime)
.userAccountId(userAccountId).build();
.userAccountId(userAccountId).resourcesList(CollectionUtils.isEmpty(leaseGoodsResources)
? null : leaseGoodsResources.stream().map(LeaseGoodsResourcesDO::buildGoodsResourcesVO).collect(Collectors.toList()))
.priceStock(CollectionUtils.isEmpty(priceStockList)
? null : priceStockList.stream().map(LeasePriceStockDO::buildPriceStockVO).collect(Collectors.toList()))
.build();
}
}
package com.mmc.pms.model.lease.qo;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.data.domain.Page;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
/**
* @Author LW
* @date 2023/8/15 10:47
* 概要:
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class LeaseGoodsQO implements Serializable {
private static final long serialVersionUID = -3779375235771767532L;
@ApiModelProperty(value = "上架状态 0下架 1上架")
private Integer shelfStatus;
@ApiModelProperty(value = "商品标题", example = "商品标题")
private String tradeName;
@ApiModelProperty(value = "商品类型id", example = "1")
private Integer productTypeId;
@ApiModelProperty(value = "品牌id", example = "2")
private Integer brandInfoId;
@ApiModelProperty(value = "用户id", hidden = true)
private Integer userAccountId;
@ApiModelProperty(value = "页码", required = true)
@NotNull(message = "页码不能为空", groups = Page.class)
@Min(value = 1, groups = Page.class)
private Integer pageNo;
@ApiModelProperty(value = "每页显示数", required = true)
@NotNull(message = "每页显示数不能为空", groups = Page.class)
@Min(value = 1, groups = Page.class)
private Integer pageSize;
public void buildCurrentPage() {
this.pageNo = (pageNo - 1) * pageSize;
}
}
......@@ -10,7 +10,6 @@ import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
......@@ -34,7 +33,7 @@ public class LeaseGoodsVO implements Serializable {
private Integer id;
@ApiModelProperty(value = "商品标题", example = "商品标题", required = true)
@NotBlank(message = "商品标题不能为空", groups = {Update.class, Create.class})
@NotEmpty(message = "商品标题不能为空", groups = {Update.class, Create.class})
private String tradeName;
@ApiModelProperty(value = "商品卖点", example = "商品卖点")
......@@ -43,7 +42,7 @@ public class LeaseGoodsVO implements Serializable {
@ApiModelProperty(value = "商品成新", example = "1", required = true)
private Integer level;
@ApiModelProperty(value = "商品状态", example = "1", required = true)
@ApiModelProperty(value = "商品状态 :0下架 1上架", example = "1", required = true)
@NotNull(message = "商品状态不能为空", groups = {Update.class, Create.class})
private Integer shelfStatus;
......@@ -102,4 +101,13 @@ public class LeaseGoodsVO implements Serializable {
@ApiModelProperty(value = "店铺id 小程序用", hidden = true)
private Integer userAccountId;
@ApiModelProperty(value = "押金范围", hidden = true)
private String cashPledgeRange;
@ApiModelProperty(value = "租金范围", hidden = true)
private String rentalRange;
@ApiModelProperty(value = "库存", hidden = true)
private Integer stock;
}
package com.mmc.pms.model.lease.vo;
import com.mmc.pms.model.group.Create;
import com.mmc.pms.model.group.Update;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import javax.validation.constraints.Max;
import javax.validation.constraints.NotEmpty;
import java.io.Serializable;
import java.math.BigDecimal;
......@@ -25,6 +29,7 @@ public class LeasePriceStockVO implements Serializable {
private Integer id;
@ApiModelProperty(value = "商品规格", example = "示例:{\"颜色\":\"蓝色\",\"尺寸\":\"1寸\",\"大小\":\"小\"} 或 [\"颜色\":\"蓝色\",\"尺寸\":\"1寸\",\"大小\":\"小\"] 或 你怎么方便怎么来")
@NotEmpty(message = "商品规格不能为空", groups = {Update.class, Create.class})
private String productSpec;
@ApiModelProperty(value = "押金", example = "1")
......@@ -52,6 +57,7 @@ public class LeasePriceStockVO implements Serializable {
private String skuImage;
@ApiModelProperty(value = "库存", example = "10")
@Max(message = "最大不能超过9999", groups = {Update.class, Create.class}, value = 9999)
private Integer stock;
@ApiModelProperty(value = "是否缺货 0:否 1:是")
......
package com.mmc.pms.service.lease;
import com.mmc.pms.auth.dto.LoginSuccessDTO;
import com.mmc.pms.common.ResultBody;
import com.mmc.pms.model.lease.qo.LeaseGoodsQO;
import com.mmc.pms.model.lease.vo.LeaseGoodsVO;
/**
......@@ -16,5 +18,6 @@ public interface LeaseGoodsService {
ResultBody leaseGoodsDetails(Integer id);
ResultBody editLeaseGoods(LeaseGoodsVO leaseGoodsVO, Integer userAccountId);
ResultBody leaseGoodsList(LeaseGoodsQO param, LoginSuccessDTO loginSuccessDTO);
}
package com.mmc.pms.service.lease.impl;
import com.mmc.pms.auth.dto.LoginSuccessDTO;
import com.mmc.pms.common.ResultBody;
import com.mmc.pms.dao.lease.LeaseGoodsDao;
import com.mmc.pms.entity.lease.*;
import com.mmc.pms.model.lease.qo.LeaseGoodsQO;
import com.mmc.pms.model.lease.vo.LeaseGoodsVO;
import com.mmc.pms.model.lease.vo.LeasePartsListVO;
import com.mmc.pms.model.lease.vo.LeasePriceStockVO;
import com.mmc.pms.page.PageResult;
import com.mmc.pms.service.lease.LeaseGoodsService;
import com.mmc.pms.service.mall.MallGoodsService;
import org.apache.commons.collections4.CollectionUtils;
......@@ -12,8 +16,12 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.Comparator;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
import java.util.stream.Stream;
/**
* @Author LW
......@@ -106,4 +114,52 @@ public class LeaseGoodsServiceImpl implements LeaseGoodsService {
mallGoodsService.updateSpecInfo(null, leaseGoodsVO);
return ResultBody.success();
}
@Override
public ResultBody leaseGoodsList(LeaseGoodsQO param, LoginSuccessDTO loginSuccessDTO) {
if (loginSuccessDTO.getRoleInfo().getSuperAdmin().equals(1)) {
// 超级管理员获取所有商品信息
return ResultBody.success(getMallGoodsInfo(param));
} else {
// 非超级管理员获取自家的商品信息
param.setUserAccountId(loginSuccessDTO.getUserAccountId());
return ResultBody.success(getMallGoodsInfo(param));
}
}
private PageResult getMallGoodsInfo(LeaseGoodsQO param) {
int count = leaseGoodsDao.countLeaseGoods(param);
if (count == 0) {
return PageResult.buildPage(param.getPageNo(), param.getPageSize(), count);
}
Integer pageNo = param.getPageNo();
param.buildCurrentPage();
List<LeaseGoodsDO> leaseGoodsDOList = leaseGoodsDao.listLeaseGoods(param);
// 转成vo
List<LeaseGoodsVO> leaseGoodsVOList = leaseGoodsDOList.stream().map(LeaseGoodsDO::buildLeaseGoodsVO).collect(Collectors.toList());
leaseGoodsVOList = leaseGoodsVOList.stream().peek(d -> {
// 获取最低押金及最高押金
List<LeasePriceStockVO> list = d.getPriceStock().stream().sorted(Comparator.comparing(LeasePriceStockVO::getCashPledge)).collect(Collectors.toList());
LeasePriceStockVO lastElement = list.get(list.size() - 1);
LeasePriceStockVO firstElement = list.get(0);
d.setCashPledgeRange("¥" + firstElement.getCashPledge() + "~" + "¥" + lastElement.getCashPledge());
// 获取最低租金
BigDecimal minPrice = list.stream()
.map(o -> Stream.of(o.getThreeDaysRental(), o.getSevenDaysRental(), o.getThirtyDaysRental(), o.getNinetyDaysRental(), o.getMaxDaysRental())
.filter(Objects::nonNull)
.min(BigDecimal::compareTo)
.orElse(BigDecimal.ZERO))
.min(Comparator.naturalOrder()).get();
// 获取最高租金
BigDecimal maxPrice = list.stream()
.map(o -> Stream.of(o.getThreeDaysRental(), o.getSevenDaysRental(), o.getThirtyDaysRental(), o.getNinetyDaysRental(), o.getMaxDaysRental())
.filter(Objects::nonNull)
.max(BigDecimal::compareTo)
.orElse(BigDecimal.ZERO))
.max(Comparator.naturalOrder()).get();
d.setRentalRange("¥" + minPrice + "~" + "¥" + maxPrice);
d.setStock(list.stream().mapToInt(LeasePriceStockVO::getStock).sum());
}).collect(Collectors.toList());
return PageResult.buildPage(pageNo, param.getPageSize(), count, leaseGoodsVOList);
}
}
......@@ -286,4 +286,87 @@
)
</where>
</select>
<select id="countLeaseGoods" resultType="java.lang.Integer">
select count(*) from lease_goods
<where>
<if test="shelfStatus != null">
and shelf_status = #{shelfStatus}
</if>
<if test="tradeName != null and tradeName != ''">
and (trade_name LIKE CONCAT('%',#{tradeName},'%'))
</if>
<if test="productTypeId != null">
and product_type_id = #{productTypeId}
</if>
<if test="brandInfoId != null">
and brand_info_id = #{brandInfoId}
</if>
<if test="userAccountId != null">
and user_account_id = #{userAccountId}
</if>
</where>
</select>
<resultMap id="leaseGoodsMap" type="com.mmc.pms.entity.lease.LeaseGoodsDO">
<id column="id" property="id"/>
<result column="trade_name" property="tradeName"/>
<result column="product_type_id" property="productTypeId"/>
<result column="shelf_status" property="shelfStatus"/>
<collection property="leaseGoodsResources" javaType="java.util.List"
ofType="com.mmc.pms.entity.lease.LeaseGoodsResourcesDO">
<id column="resourceId" property="id"/>
<result column="type" property="type"/>
<result column="url" property="url"/>
</collection>
<collection property="priceStockList" javaType="java.util.List"
ofType="com.mmc.pms.entity.lease.LeasePriceStockDO">
<result column="cash_pledge" property="cashPledge"/>
<result column="three_days_rental" property="threeDaysRental"/>
<result column="seven_days_rental" property="sevenDaysRental"/>
<result column="thirty_days_rental" property="thirtyDaysRental"/>
<result column="ninety_days_rental" property="ninetyDaysRental"/>
<result column="max_days_rental" property="maxDaysRental"/>
<result column="stock" property="stock"/>
</collection>
</resultMap>
<select id="listLeaseGoods" resultMap="leaseGoodsMap">
SELECT
lg.id,
lg.trade_name,
lg.product_type_id,
lg.shelf_status,
lg.create_time,
lgr.id resourceId,
lgr.type,
lgr.url,
lps.cash_pledge,
lps.three_days_rental,
lps.seven_days_rental,
lps.thirty_days_rental,
lps.ninety_days_rental,
lps.max_days_rental,
lps.stock
FROM
lease_goods lg
LEFT JOIN lease_goods_resources lgr ON lgr.lease_goods_id = lg.id
LEFT JOIN lease_price_stock lps ON lps.lease_goods_id = lg.id
<where>
<if test="shelfStatus != null">
and shelf_status = #{shelfStatus}
</if>
<if test="tradeName != null and tradeName != ''">
and (trade_name LIKE CONCAT('%',#{tradeName},'%'))
</if>
<if test="productTypeId != null">
and product_type_id = #{productTypeId}
</if>
<if test="brandInfoId != null">
and brand_info_id = #{brandInfoId}
</if>
<if test="userAccountId != null">
and user_account_id = #{userAccountId}
</if>
</where>
order by lg.shelf_status DESC, lg.sort DESC
limit #{pageNo},#{pageSize}
</select>
</mapper>
\ No newline at end of file
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论