新增规格逻辑修改,新增激活码到期时间,激活码时间校验
This commit is contained in:
@@ -170,4 +170,23 @@ public class DateUtil {
|
|||||||
public static LocalDateTime parseLocalDateTimeFormatyMdHms(String localDateTime) {
|
public static LocalDateTime parseLocalDateTimeFormatyMdHms(String localDateTime) {
|
||||||
return LocalDateTime.from(DFY_MD_HMS.parse(localDateTime));
|
return LocalDateTime.from(DFY_MD_HMS.parse(localDateTime));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 激活码到期时间
|
||||||
|
* @param monthsToAdd
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static long addMonthsAndGetTimestamp(int monthsToAdd) {
|
||||||
|
// 获取当前日期时间
|
||||||
|
ZonedDateTime now = ZonedDateTime.now();
|
||||||
|
|
||||||
|
// 增加月份
|
||||||
|
LocalDate dateAfterMonths = now.toLocalDate().plusMonths(monthsToAdd);
|
||||||
|
|
||||||
|
// 将日期设置为下一个月的最后一天
|
||||||
|
ZonedDateTime newDateTime = dateAfterMonths.atStartOfDay(now.getZone());
|
||||||
|
|
||||||
|
// 转换为时间戳
|
||||||
|
return newDateTime.toInstant().toEpochMilli();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -65,6 +65,9 @@ public class ListUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static List<String> stringChangeStringList(String listString){
|
public static List<String> stringChangeStringList(String listString){
|
||||||
|
if (StringUtils.isEmpty(listString)){
|
||||||
|
return new ArrayList<>();
|
||||||
|
}
|
||||||
// 使用Fastjson将JSON字符串转换为JSONArray对象
|
// 使用Fastjson将JSON字符串转换为JSONArray对象
|
||||||
listString = listString.replaceAll("\"", "").replaceAll("\\[", "").replaceAll("\\]", "");
|
listString = listString.replaceAll("\"", "").replaceAll("\\[", "").replaceAll("\\]", "");
|
||||||
List<String> stringList = Stream.of(listString.split(","))
|
List<String> stringList = Stream.of(listString.split(","))
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ public class TbProductQueryCriteria{
|
|||||||
|
|
||||||
/** 精确 */
|
/** 精确 */
|
||||||
@Query
|
@Query
|
||||||
private Integer status;
|
private Integer status =1;
|
||||||
|
|
||||||
/** 精确 */
|
/** 精确 */
|
||||||
@Query
|
@Query
|
||||||
|
|||||||
@@ -32,4 +32,7 @@ public interface TbProductRepository extends JpaRepository<TbProduct, Integer>,
|
|||||||
|
|
||||||
@Query("SELECT product from TbProduct product where product.id in :productIds")
|
@Query("SELECT product from TbProduct product where product.id in :productIds")
|
||||||
List<TbProduct> findByIds(List<Integer> productIds);
|
List<TbProduct> findByIds(List<Integer> productIds);
|
||||||
|
|
||||||
|
@Query(value = "update tb_product set status = -1 where id in :productIds",nativeQuery = true)
|
||||||
|
Integer updateByStatus(List<Integer> productIds);
|
||||||
}
|
}
|
||||||
@@ -311,16 +311,12 @@ public class TbProductServiceImpl implements TbProductService {
|
|||||||
tbProductSkuRepository.saveAll(skuList);
|
tbProductSkuRepository.saveAll(skuList);
|
||||||
|
|
||||||
}
|
}
|
||||||
// ValidationUtil.isNull( tbProduct.getId(),"TbProduct","id",resources.getId());
|
|
||||||
// tbProduct.copy(resources);
|
|
||||||
// tbProductRepository.save(tbProduct);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void deleteAll(Integer[] ids) {
|
public void deleteAll(Integer[] ids) {
|
||||||
for (Integer id : ids) {
|
List<Integer> list = Arrays.asList(ids);
|
||||||
tbProductRepository.deleteById(id);
|
tbProductRepository.updateByStatus(list);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -110,9 +110,8 @@ public class TbShopCategoryServiceImpl implements TbShopCategoryService {
|
|||||||
public TbShopCategory create(TbShopCategory resources) {
|
public TbShopCategory create(TbShopCategory resources) {
|
||||||
resources.setCreatedAt(Instant.now().toEpochMilli());
|
resources.setCreatedAt(Instant.now().toEpochMilli());
|
||||||
resources.setUpdatedAt(Instant.now().toEpochMilli());
|
resources.setUpdatedAt(Instant.now().toEpochMilli());
|
||||||
|
TbShopCategory byName = tbShopCategoryRepository.findByName(resources.getName(), resources.getShopId());
|
||||||
TbShopCategoryDto dto = tbShopCategoryMapper.toDto(tbShopCategoryRepository.save(resources));
|
if (byName.getName() != null){
|
||||||
if (resources.getName() != null){
|
|
||||||
throw new BadRequestException("分类名称重复");
|
throw new BadRequestException("分类名称重复");
|
||||||
}
|
}
|
||||||
if (resources.getPid() == null || "".equals(resources.getPid())){
|
if (resources.getPid() == null || "".equals(resources.getPid())){
|
||||||
@@ -121,8 +120,7 @@ public class TbShopCategoryServiceImpl implements TbShopCategoryService {
|
|||||||
resources.setTree(Integer.valueOf(resources.getPid().trim()));
|
resources.setTree(Integer.valueOf(resources.getPid().trim()));
|
||||||
}
|
}
|
||||||
|
|
||||||
ValidationUtil.isNull(dto.getId(),"TbShopCategory","id",resources.getId());
|
ValidationUtil.isNull(resources.getId(),"TbShopCategory","id",resources.getId());
|
||||||
tbShopCategoryRepository.save(resources);
|
|
||||||
return tbShopCategoryRepository.save(resources);
|
return tbShopCategoryRepository.save(resources);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -88,6 +88,9 @@ public class TbMerchantRegisterServiceImpl implements TbMerchantRegisterService
|
|||||||
if (resources.getNumber()>10){
|
if (resources.getNumber()>10){
|
||||||
throw new BadRequestException("每次最多生成10条激活码");
|
throw new BadRequestException("每次最多生成10条激活码");
|
||||||
}
|
}
|
||||||
|
if (resources.getPeriodYear() <= 0){
|
||||||
|
throw new BadRequestException("激活码时长有误");
|
||||||
|
}
|
||||||
for (int i = 0; i < resources.getNumber(); i++) {
|
for (int i = 0; i < resources.getNumber(); i++) {
|
||||||
TbMerchantRegister tbMerchantRegister = new TbMerchantRegister();
|
TbMerchantRegister tbMerchantRegister = new TbMerchantRegister();
|
||||||
tbMerchantRegister.setRegisterCode(UUID.randomUUID().toString().replaceAll("-", ""));
|
tbMerchantRegister.setRegisterCode(UUID.randomUUID().toString().replaceAll("-", ""));
|
||||||
|
|||||||
@@ -75,6 +75,8 @@ public class TbShopInfoServiceImpl implements TbShopInfoService {
|
|||||||
|
|
||||||
private final TbPlussShopStaffRepository shopStaffRepository;
|
private final TbPlussShopStaffRepository shopStaffRepository;
|
||||||
|
|
||||||
|
private final RedisUtils redisUtils;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<String,Object> queryAll(TbShopInfoQueryCriteria criteria){
|
public Map<String,Object> queryAll(TbShopInfoQueryCriteria criteria){
|
||||||
Sort sort = Sort.by(Sort.Direction.DESC, "id");
|
Sort sort = Sort.by(Sort.Direction.DESC, "id");
|
||||||
@@ -130,8 +132,31 @@ public class TbShopInfoServiceImpl implements TbShopInfoService {
|
|||||||
BeanUtils.copyProperties(resources,tbShopInfo);
|
BeanUtils.copyProperties(resources,tbShopInfo);
|
||||||
tbShopInfo.setCreatedAt(Instant.now().toEpochMilli());
|
tbShopInfo.setCreatedAt(Instant.now().toEpochMilli());
|
||||||
tbShopInfo.setUpdatedAt(Instant.now().toEpochMilli());
|
tbShopInfo.setUpdatedAt(Instant.now().toEpochMilli());
|
||||||
|
//激活码
|
||||||
|
TbMerchantRegister tbMerchantRegister = new TbMerchantRegister();
|
||||||
|
if (resources.getRegisterCode() != null){
|
||||||
|
tbMerchantRegister = merchantRegisterRepository.findByRegisterCode(resources.getRegisterCode());
|
||||||
|
if(tbMerchantRegister == null){
|
||||||
|
throw new BadRequestException("激活码有误");
|
||||||
|
}
|
||||||
|
if (tbMerchantRegister.getStatus() == 1){
|
||||||
|
throw new BadRequestException("激活码已激活,不能重复绑定");
|
||||||
|
}
|
||||||
|
tbShopInfo.setExpireAt(DateUtil.addMonthsAndGetTimestamp(tbMerchantRegister.getPeriodYear()));
|
||||||
|
//向redis中存入key
|
||||||
|
redisUtils.set(CacheKey.ACT_CODE,resources.getAccount(),tbShopInfo.getExpireAt()-Instant.now().toEpochMilli());
|
||||||
|
}
|
||||||
//增加商户详情
|
//增加商户详情
|
||||||
TbShopInfo save = tbShopInfoRepository.save(tbShopInfo);
|
TbShopInfo save = tbShopInfoRepository.save(tbShopInfo);
|
||||||
|
if (resources.getRegisterCode() != null) {
|
||||||
|
//激活码绑定
|
||||||
|
tbMerchantRegister.setStatus(1);
|
||||||
|
tbMerchantRegister.setShopId(String.valueOf(save.getId()));
|
||||||
|
tbMerchantRegister.setName(save.getShopName());
|
||||||
|
merchantRegisterRepository.save(tbMerchantRegister);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
//增加商户登录账号
|
//增加商户登录账号
|
||||||
TbMerchantAccount tbMerchantAccount = new TbMerchantAccount();
|
TbMerchantAccount tbMerchantAccount = new TbMerchantAccount();
|
||||||
tbMerchantAccount.setAccount(resources.getAccount());
|
tbMerchantAccount.setAccount(resources.getAccount());
|
||||||
@@ -183,22 +208,7 @@ public class TbShopInfoServiceImpl implements TbShopInfoService {
|
|||||||
tbPlussShopStaff.setCode(save.getPhone());
|
tbPlussShopStaff.setCode(save.getPhone());
|
||||||
shopStaffRepository.save(tbPlussShopStaff);
|
shopStaffRepository.save(tbPlussShopStaff);
|
||||||
|
|
||||||
if (resources.getRegisterCode() != null){
|
|
||||||
//激活码绑定
|
|
||||||
TbMerchantRegister tbMerchantRegister = merchantRegisterRepository.findByRegisterCode(resources.getRegisterCode());
|
|
||||||
if(tbMerchantRegister == null){
|
|
||||||
throw new BadRequestException("激活码有误");
|
|
||||||
}
|
|
||||||
if (tbMerchantRegister.getStatus() == 1){
|
|
||||||
throw new BadRequestException("激活码已激活,不能重复绑定");
|
|
||||||
}
|
|
||||||
tbMerchantRegister.setStatus(1);
|
|
||||||
tbMerchantAccount.setShopId(String.valueOf(save.getId()));
|
|
||||||
tbMerchantAccount.setName(save.getShopName());
|
|
||||||
merchantRegisterRepository.save(tbMerchantRegister);
|
|
||||||
//向redis中存入key
|
|
||||||
// redisUtils.set
|
|
||||||
}
|
|
||||||
|
|
||||||
return tbShopInfoMapper.toDto(new TbShopInfo());
|
return tbShopInfoMapper.toDto(new TbShopInfo());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ spring:
|
|||||||
properties:
|
properties:
|
||||||
hibernate:
|
hibernate:
|
||||||
dialect: org.hibernate.dialect.MySQL5InnoDBDialect
|
dialect: org.hibernate.dialect.MySQL5InnoDBDialect
|
||||||
show_sql: true
|
show_sql: false
|
||||||
|
|
||||||
redis:
|
redis:
|
||||||
#数据库索引
|
#数据库索引
|
||||||
|
|||||||
Reference in New Issue
Block a user