提交 066cf45f authored 作者: 吴德鹏's avatar 吴德鹏

修复优惠券不失效bug

上级 0ab80810
package com.example.afrishop_v3.controllers;
import com.example.afrishop_v3.base.Result;
import com.example.afrishop_v3.models.AttributesDesc;
import com.example.afrishop_v3.models.AttributesVo;
import com.example.afrishop_v3.models.TbCfItemParam;
import com.example.afrishop_v3.repository.AttributesDescRepository;
import com.example.afrishop_v3.repository.AttributesRepository;
import com.example.afrishop_v3.repository.TbCfItemParamRepository;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.stream.Collectors;
/**
* @Auther: wudepeng
* @Date: 2020/12/29
* @Description:属性管理
*/
@RestController
@RequestMapping("/attributes")
public class AttributesController {
private final TbCfItemParamRepository itemParamRepository;
private final AttributesRepository attributesRepository;
private final AttributesDescRepository attributesDescRepository;
public AttributesController(TbCfItemParamRepository itemParamRepository, AttributesRepository attributesRepository, AttributesDescRepository attributesDescRepository) {
this.itemParamRepository = itemParamRepository;
this.attributesRepository = attributesRepository;
this.attributesDescRepository = attributesDescRepository;
}
@GetMapping("/getItemAttributesById/{itemId}")
public Result getItemAttributesById(@PathVariable("itemId") String itemId) {
List<TbCfItemParam> list = itemParamRepository.findAllByItemId(itemId);
if (list.size() > 0 && list != null) {
list.forEach(p -> {
AttributesVo attributesVo = new AttributesVo();
attributesVo.setAttrName(attributesRepository.findById(p.getAttrId()).get().getAttrName());
List<AttributesDesc> descs = attributesDescRepository.findByAttrDescIdIn(p.getAttrDescId().split(","));
String descValue = descs.stream().map(AttributesDesc::getAttrValue).collect(Collectors.joining(","));
attributesVo.setAttrValue(descValue);
});
}
return new Result();
}
}
...@@ -65,7 +65,7 @@ public class CartController extends Controller { ...@@ -65,7 +65,7 @@ public class CartController extends Controller {
//Add single item to the cart //Add single item to the cart
@PostMapping @PostMapping
public Result addToCart(@RequestParam("checkFlag") Integer checkFlag, @RequestBody TbCfCartRecordR itemDetail) { public Result addToCart(@RequestParam(value = "checkFlag",required = false) Integer checkFlag, @RequestBody TbCfCartRecordR itemDetail) {
TbCfUserInfo user = this.user.user(); TbCfUserInfo user = this.user.user();
......
...@@ -146,6 +146,7 @@ public class OrderController extends Controller { ...@@ -146,6 +146,7 @@ public class OrderController extends Controller {
if (couponOptional.isPresent()) { if (couponOptional.isPresent()) {
TbCfToicoupon tbCfToicoupon = couponOptional.get();
TbCfCoupon coupon = couponOptional.get().getCoupon(); TbCfCoupon coupon = couponOptional.get().getCoupon();
order.setCoupon(coupon); order.setCoupon(coupon);
} }
...@@ -343,6 +344,9 @@ public class OrderController extends Controller { ...@@ -343,6 +344,9 @@ public class OrderController extends Controller {
if (couponOptional.isPresent()) { if (couponOptional.isPresent()) {
TbCfToicoupon tbCfToicoupon = couponOptional.get();
tbCfToicoupon.setEnableFlag(0);
toicouponRepository.save(tbCfToicoupon);
TbCfCoupon coupon = couponOptional.get().getCoupon(); TbCfCoupon coupon = couponOptional.get().getCoupon();
order.setCoupon(coupon); order.setCoupon(coupon);
} }
...@@ -418,10 +422,10 @@ public class OrderController extends Controller { ...@@ -418,10 +422,10 @@ public class OrderController extends Controller {
//implementation of coupon use //implementation of coupon use
if (tbCfToicoupon != null) { // if (tbCfToicoupon != null) {
tbCfToicoupon.setEnableFlag(0); // tbCfToicoupon.setEnableFlag(0);
toicouponRepository.save(tbCfToicoupon); // toicouponRepository.save(tbCfToicoupon);
} // }
//order.getItemOrderList().forEach(itemOrderRepository::save); //order.getItemOrderList().forEach(itemOrderRepository::save);
......
package com.example.afrishop_v3.models;
import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
/**
* 实体
* 表名 attributes
*
* @author lipengjun
* @date 2020-12-21 15:41:01
*/
@Entity
public class Attributes implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 商品属性ID
*/
@Id
private String id;
/**
* 属性名
*/
private String attrName;
/**
* 状态 0:隐藏 1:正常
*/
private Integer status;
/**
* 排序
*/
private Integer sort;
/**
* 是否必须 0:否 1:是
*/
@Column(name = "is_need")
private boolean isNeed;
/**
* 创建时间
*/
private Date createTime;
/**
* 更新时间
*/
private Date updateTime;
@OneToMany(mappedBy = "attributes", cascade = CascadeType.ALL)
@Transient
private List<AttributesDesc> descList;
public List<AttributesDesc> getDescList() {
return descList;
}
public void setDescList(List<AttributesDesc> descList) {
this.descList = descList;
}
/**
* 设置:商品属性ID
*/
public void setId(String id) {
this.id = id;
}
/**
* 获取:商品属性ID
*/
public String getId() {
return id;
}
/**
* 设置:属性名
*/
public void setAttrName(String attrName) {
this.attrName = attrName;
}
/**
* 获取:属性名
*/
public String getAttrName() {
return attrName;
}
/**
* 设置:状态 0:隐藏 1:正常
*/
public void setStatus(Integer status) {
this.status = status;
}
/**
* 获取:状态 0:隐藏 1:正常
*/
public Integer getStatus() {
return status;
}
/**
* 设置:排序
*/
public void setSort(Integer sort) {
this.sort = sort;
}
/**
* 获取:排序
*/
public Integer getSort() {
return sort;
}
public boolean isNeed() {
return isNeed;
}
public void setNeed(boolean need) {
isNeed = need;
}
/**
* 设置:创建时间
*/
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
/**
* 获取:创建时间
*/
public Date getCreateTime() {
return createTime;
}
/**
* 设置:更新时间
*/
public void setUpdateTime(Date updateTime) {
this.updateTime = updateTime;
}
/**
* 获取:更新时间
*/
public Date getUpdateTime() {
return updateTime;
}
}
package com.example.afrishop_v3.models;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import java.io.Serializable;
import java.util.Date;
/**
* 实体
* 表名 attributes_desc
*
* @author lipengjun
* @date 2020-12-23 11:00:57
*/
@Entity
public class AttributesDesc implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 属性描述ID
*/
@Id
private String attrDescId;
/**
* 属性ID
*/
@ManyToOne
private Attributes attribute;
/**
* 属性值
*/
private String attrValue;
/**
* 属性描述(中文)
*/
private String attrDesc;
/**
* 状态
*/
private Integer status;
/**
* 创建时间
*/
private Date createTime;
/**
* 更新时间
*/
private Date updateTime;
/**
* 设置:属性描述ID
*/
public void setAttrDescId(String attrDescId) {
this.attrDescId = attrDescId;
}
/**
* 获取:属性描述ID
*/
public String getAttrDescId() {
return attrDescId;
}
public Attributes getAttribute() {
return attribute;
}
public void setAttribute(Attributes attribute) {
this.attribute = attribute;
}
/**
* 设置:属性值
*/
public void setAttrValue(String attrValue) {
this.attrValue = attrValue;
}
/**
* 获取:属性值
*/
public String getAttrValue() {
return attrValue;
}
/**
* 设置:属性描述(中文)
*/
public void setAttrDesc(String attrDesc) {
this.attrDesc = attrDesc;
}
/**
* 获取:属性描述(中文)
*/
public String getAttrDesc() {
return attrDesc;
}
/**
* 设置:状态
*/
public void setStatus(Integer status) {
this.status = status;
}
/**
* 获取:状态
*/
public Integer getStatus() {
return status;
}
/**
* 设置:创建时间
*/
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
/**
* 获取:创建时间
*/
public Date getCreateTime() {
return createTime;
}
/**
* 设置:更新时间
*/
public void setUpdateTime(Date updateTime) {
this.updateTime = updateTime;
}
/**
* 获取:更新时间
*/
public Date getUpdateTime() {
return updateTime;
}
}
package com.example.afrishop_v3.models;
import lombok.Data;
/**
* @Auther: wudepeng
* @Date: 2020/12/29
* @Description:属性模板
*/
@Data
public class AttributesVo {
private String attrName;
private String attrValue;
}
...@@ -23,18 +23,20 @@ public class TbCfItemParam { ...@@ -23,18 +23,20 @@ public class TbCfItemParam {
*/ */
@Id @Id
private String id; private String id;
/** /**
* 参数名 * 商品ID
*/ */
private String paramName; private String itemId;
/** /**
* 参数值 * 属性ID
*/ */
private String paramValue; private String attrId;
/** /**
* 商品ID * 属性描述ID
*/ */
private String itemId; private String attrDescId;
/** /**
* 创建时间 * 创建时间
*/ */
...@@ -44,6 +46,7 @@ public class TbCfItemParam { ...@@ -44,6 +46,7 @@ public class TbCfItemParam {
*/ */
private Date updateTime; private Date updateTime;
/** /**
* 设置:商品参数ID * 设置:商品参数ID
*/ */
...@@ -57,32 +60,7 @@ public class TbCfItemParam { ...@@ -57,32 +60,7 @@ public class TbCfItemParam {
public String getId() { public String getId() {
return id; return id;
} }
/**
* 设置:参数名
*/
public void setParamName(String paramName) {
this.paramName = paramName;
}
/**
* 获取:参数名
*/
public String getParamName() {
return paramName;
}
/**
* 设置:参数值
*/
public void setParamValue(String paramValue) {
this.paramValue = paramValue;
}
/**
* 获取:参数值
*/
public String getParamValue() {
return paramValue;
}
/** /**
* 设置:商品ID * 设置:商品ID
*/ */
...@@ -96,6 +74,7 @@ public class TbCfItemParam { ...@@ -96,6 +74,7 @@ public class TbCfItemParam {
public String getItemId() { public String getItemId() {
return itemId; return itemId;
} }
/** /**
* 设置:创建时间 * 设置:创建时间
*/ */
...@@ -109,6 +88,7 @@ public class TbCfItemParam { ...@@ -109,6 +88,7 @@ public class TbCfItemParam {
public Date getCreateTime() { public Date getCreateTime() {
return createTime; return createTime;
} }
/** /**
* 设置:更新时间 * 设置:更新时间
*/ */
......
package com.example.afrishop_v3.repository;
import com.example.afrishop_v3.models.AttributesDesc;
import org.springframework.data.jpa.repository.JpaRepository;
import java.util.List;
/**
* @Auther: wudepeng
* @Date: 2020/12/29
* @Description:
*/
public interface AttributesDescRepository extends JpaRepository<AttributesDesc, String> {
List<AttributesDesc> findByAttrDescIdIn(String[] attrDescId);
}
package com.example.afrishop_v3.repository;
import com.example.afrishop_v3.models.Attributes;
import org.springframework.data.jpa.repository.JpaRepository;
/**
* @Auther: wudepeng
* @Date: 2020/12/29
* @Description:
*/
public interface AttributesRepository extends JpaRepository<Attributes,String> {
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论