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

地址优化

上级 3fdfed2f
......@@ -46,8 +46,8 @@ public class AddressController extends Controller {
// return new Result(e.getCode(), "Delivery name is required");
// if (address.getPhone() == null || address.getPhone().trim().isEmpty())
// return new Result(e.getCode(), "Phone is required");
// if (repository.existsByAddressDetailAndUserId(address.getAddress1().trim(), userId))
// return new Result(e.getCode(), "Address already existed");
if (repository.existsByAddressDetailAndUserId(address.getAddressDetail().trim(), userId))
return new Result(e.getCode(), "Address already existed");
//客户新增第一条地址,设置为默认
......@@ -95,13 +95,14 @@ public class AddressController extends Controller {
// if (address.getPhone() == null || address.getPhone().trim().isEmpty())
// return new Result(e.getCode(), "Phone is required");
// if (repository.existsByAddressDetailAndUserIdAndAddressIdIsNot(address.getAddressDetail().trim(), userId, addressId))
// return new Result(e.getCode(), "Address already existed");
if (repository.existsByAddressDetailAndUserIdAndAddressIdIsNot(address.getAddressDetail().trim(), userId, addressId))
return new Result(e.getCode(), "Address already existed");
address.setAddressDetail(address.getAddressDetail().trim());
address.setAddressId(addressId);
address.setUpdateTime(new Date());
address.setDefaultFlag(address.getDefaultFlag());
address.setUserId(userId);
TbCfAddress save = repository.save(address);
// configDefaultAddress(save.getAddressId());
......@@ -136,16 +137,18 @@ public class AddressController extends Controller {
TbCfUserInfo user = this.user.user();
System.out.println("address:" + address);
repository.resetToDefault(user.getUserId());
System.out.println("address1:" + address);
repository.resetToDefaultAndAddressIdIsNot(user.getUserId(),addressId);
address.setDefaultFlag(StateConstant.VALID);
repository.save(address);
TbCfAddress save = repository.save(address);
user.setAddress(address);
userRepository.save(user);
System.out.println("address2:" + save);
return new Result<>(ResultCodeEnum.SUCCESS.getDesc());
return new Result(save);
}
......
......@@ -320,21 +320,18 @@ public class AuthController extends Controller {
return "Password is Empty";
}
if (!isPasswordValid(password)) {
String string = "Password is not strong";
if (!isPasswordValidDigit(password)) {
string += ", a digit must occur at least once";
}
// if (!isPasswordValidDigit(password)) {
// string += ", a digit must occur at least once";
// }
//
// if (!isPasswordValidUpperCase(password)) {
// string += ", an upper case letter must occur at least once";
// }
if (!isPasswordValidUpperCase(password)) {
string += ", an upper case letter must occur at least once";
}
if (!isPasswordValidLength(password)) {
String string = "Password is not strong, at least eight characters though";
if (!isPasswordValidLength(password)) {
string += ", at least eight characters though";
}
return string;
}
......
......@@ -81,7 +81,7 @@ public class FlutterWaveController extends Controller {
public ResponseEntity<String> payForOrderByCard(@RequestParam("orderId") String orderId, @RequestBody FlutterWaveCard flutterWaveCard) {
RaveConstant.PUBLIC_KEY = PUBLIC_KEY;
RaveConstant.SECRET_KEY = SECRET_KEY;
RaveConstant.ENVIRONMENT = Environment.STAGING; //or live
RaveConstant.ENVIRONMENT = Environment.LIVE; //or live
// Result result = new Result();
Optional<TbCfOrder> byId = repository.findById(orderId);
......
......@@ -4,6 +4,7 @@ import com.example.afrishop_v3.base.Result;
import com.example.afrishop_v3.enums.ResultCodeEnum;
import com.example.afrishop_v3.models.*;
import com.example.afrishop_v3.repository.*;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.domain.Page;
......@@ -29,9 +30,10 @@ public class ItemController {
private final TbCfItemCollectionRepository collectionRepository;
private final TbCfItemParamRepository itemParamRepository;
private final TbCfRecommendRepository recommendRepository;
private final TbCfItemCommentRepository commentRepository;
private static Logger logger = LoggerFactory.getLogger(ItemController.class);
public ItemController(TbCfStationItemRepository repository, TbCfGoodstwotypeRepository goodstwotypeRepository, TbCfGoodstypeRepository goodstypeRepository, TbCfDescripitonRepository descriptionRepository, TbCfCategoryRepository categoryRepository, TbCfItemSkuRepository skuRepository, TbCfItemDescRepository descRepository, TbCfItemCollectionRepository collectionRepository, TbCfItemParamRepository itemParamRepository, TbCfRecommendRepository recommendRepository) {
public ItemController(TbCfStationItemRepository repository, TbCfGoodstwotypeRepository goodstwotypeRepository, TbCfGoodstypeRepository goodstypeRepository, TbCfDescripitonRepository descriptionRepository, TbCfCategoryRepository categoryRepository, TbCfItemSkuRepository skuRepository, TbCfItemDescRepository descRepository, TbCfItemCollectionRepository collectionRepository, TbCfItemParamRepository itemParamRepository, TbCfRecommendRepository recommendRepository, TbCfItemCommentRepository commentRepository) {
this.repository = repository;
this.goodstwotypeRepository = goodstwotypeRepository;
this.goodstypeRepository = goodstypeRepository;
......@@ -42,6 +44,7 @@ public class ItemController {
this.collectionRepository = collectionRepository;
this.itemParamRepository = itemParamRepository;
this.recommendRepository = recommendRepository;
this.commentRepository = commentRepository;
}
@GetMapping("/queryAll")
......@@ -129,7 +132,7 @@ public class ItemController {
Page<TbCfStationItem> recommendItems = repository.getRecommendItems(itemId, stationItem.getItemDescritionId(), stationItem.getItemCategorytwo(), stationItem.getItemCategory(), PageRequest.of(pageNum, pageSize));
return new Result<>(recommendItems);
}else logger.warn("Recommended item not found");
} else logger.warn("Recommended item not found");
return new Result<>(new ArrayList<>(), ResultCodeEnum.ILLEGAL_ARGUMENT.getCode(), "Item id is invalid or not found");
}
......@@ -216,4 +219,31 @@ public class ItemController {
return new Result<>(map);
}
@GetMapping("/queryItemComments")
public Result queryItemLastComment(
@RequestParam("itemId") String itemId,
@RequestParam(value = "pageNum", defaultValue = "0") Integer pageNum,
@RequestParam(value = "pageSize", defaultValue = "6") Integer pageSize,
@RequestParam(value = "limit", required = false) Integer limit) {
Result result = new Result();
if (StringUtils.isBlank(itemId)) {
result.setCode(ResultCodeEnum.VALIDATE_ERROR.getCode());
result.setMessage("The itemId parameter cannot be empty");
return result;
}
// try {
Page<TbCfItemComment> allByItemId = commentRepository.findAllByItemId(itemId, PageRequest.of(pageNum, pageSize,Sort.by(Sort.Order.desc("createTime"))));
List<TbCfItemComment> comments = allByItemId.toList();
if (limit != null)
comments.stream().limit(limit);
result.setData(comments);
// } catch (Exception e) {
// result.setCode(ResultCodeEnum.SERVICE_ERROR.getCode());
// result.setMessage(ResultCodeEnum.SERVICE_ERROR.getDesc());
// }
return result;
}
}
package com.example.afrishop_v3.models;
import lombok.Data;
import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;
import javax.persistence.Entity;
import javax.persistence.Id;
......@@ -35,13 +37,14 @@ public class TbCfItemCollection {
@ManyToOne
@JoinColumn(columnDefinition = "item_id",name = "item_id")
@NotFound(action= NotFoundAction.IGNORE)
private TbCfStationItem item;
/**
* 删除
*/
private Integer delFlag;
/**
* 创建时间
* 创建时间
*/
private Date createTime;
/**
......@@ -106,14 +109,14 @@ public class TbCfItemCollection {
return delFlag;
}
/**
* 设置:创建时间
* 设置:创建时间
*/
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
/**
* 获取:创建时间
* 获取:创建时间
*/
public Date getCreateTime() {
return createTime;
......
......@@ -2,8 +2,12 @@ package com.example.afrishop_v3.models;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;
import org.hibernate.annotations.Formula;
import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;
import javax.annotation.Nullable;
import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;
......@@ -30,6 +34,7 @@ public class TbCfItemComment{
@ManyToOne
@JsonIgnore
@JoinColumn(columnDefinition = "user_id",name = "user_id")
@NotFound(action= NotFoundAction.IGNORE)
private TbCfUserInfo user;
/**
* 订单ID
......@@ -79,6 +84,9 @@ public class TbCfItemComment{
* 创建时间
*/
private Date createTime;
// @Transient
private Integer real;
/**
* 更新时间
*/
......@@ -347,4 +355,6 @@ public class TbCfItemComment{
public Date getUpdateTime() {
return updateTime;
}
}
......@@ -15,8 +15,8 @@ public interface TbCfAddressRepository extends PagingAndSortingRepository<TbCfAd
@Transactional
@Modifying
@Query(value = "update tb_cf_address set default_flag=0 where user_id=:user_id", nativeQuery = true)
void resetToDefault(@Param("user_id") String userId);
@Query(value = "update tb_cf_address set default_flag=0 where user_id=:user_id and address_id!=:address_id", nativeQuery = true)
void resetToDefaultAndAddressIdIsNot(@Param("user_id") String userId, @Param("address_id") String address_id);
boolean existsByAddressDetailAndUserId(String addressDetail, String userId);
......
......@@ -9,9 +9,15 @@ import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.Param;
public interface TbCfItemCommentRepository extends PagingAndSortingRepository<TbCfItemComment,String> {
import java.util.List;
public interface TbCfItemCommentRepository extends PagingAndSortingRepository<TbCfItemComment, String> {
boolean existsByUserUserIdAndItemId(String userId, String itemId);
Page<TbCfItemComment> findAllByItemId(String itemId, Pageable pageable);
@Query("select a as itemComment, count(x) as commented from #{#entityName} a left join TbCfItemLike x on a=x.comment and x.user=:user where a.itemId=:itemId group by a")
Page<CommentCount> findAllByItemIdAndUser(@Param("itemId") String itemId, @Param("user") TbCfUserInfo user, Pageable pageable);
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论