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

地址优化

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