diff --git a/eladmin-common/src/main/java/cn/ysk/cashier/utils/DateUtil.java b/eladmin-common/src/main/java/cn/ysk/cashier/utils/DateUtil.java index 6254b573..f391aff4 100644 --- a/eladmin-common/src/main/java/cn/ysk/cashier/utils/DateUtil.java +++ b/eladmin-common/src/main/java/cn/ysk/cashier/utils/DateUtil.java @@ -170,4 +170,23 @@ public class DateUtil { public static LocalDateTime parseLocalDateTimeFormatyMdHms(String 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(); + } } diff --git a/eladmin-common/src/main/java/cn/ysk/cashier/utils/ListUtil.java b/eladmin-common/src/main/java/cn/ysk/cashier/utils/ListUtil.java index 7a18bb3c..d1bc273f 100644 --- a/eladmin-common/src/main/java/cn/ysk/cashier/utils/ListUtil.java +++ b/eladmin-common/src/main/java/cn/ysk/cashier/utils/ListUtil.java @@ -65,6 +65,9 @@ public class ListUtil { } public static List stringChangeStringList(String listString){ + if (StringUtils.isEmpty(listString)){ + return new ArrayList<>(); + } // 使用Fastjson将JSON字符串转换为JSONArray对象 listString = listString.replaceAll("\"", "").replaceAll("\\[", "").replaceAll("\\]", ""); List stringList = Stream.of(listString.split(",")) diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/dto/product/TbProductQueryCriteria.java b/eladmin-system/src/main/java/cn/ysk/cashier/dto/product/TbProductQueryCriteria.java index e4b106e2..b643055e 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/dto/product/TbProductQueryCriteria.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/dto/product/TbProductQueryCriteria.java @@ -77,7 +77,7 @@ public class TbProductQueryCriteria{ /** 精确 */ @Query - private Integer status; + private Integer status =1; /** 精确 */ @Query diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/repository/product/TbProductRepository.java b/eladmin-system/src/main/java/cn/ysk/cashier/repository/product/TbProductRepository.java index bf9875b4..7fb464c7 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/repository/product/TbProductRepository.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/repository/product/TbProductRepository.java @@ -32,4 +32,7 @@ public interface TbProductRepository extends JpaRepository, @Query("SELECT product from TbProduct product where product.id in :productIds") List findByIds(List productIds); + + @Query(value = "update tb_product set status = -1 where id in :productIds",nativeQuery = true) + Integer updateByStatus(List productIds); } \ No newline at end of file diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/productimpl/TbProductServiceImpl.java b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/productimpl/TbProductServiceImpl.java index 41145263..7cb480a6 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/productimpl/TbProductServiceImpl.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/productimpl/TbProductServiceImpl.java @@ -311,16 +311,12 @@ public class TbProductServiceImpl implements TbProductService { tbProductSkuRepository.saveAll(skuList); } -// ValidationUtil.isNull( tbProduct.getId(),"TbProduct","id",resources.getId()); -// tbProduct.copy(resources); -// tbProductRepository.save(tbProduct); } @Override public void deleteAll(Integer[] ids) { - for (Integer id : ids) { - tbProductRepository.deleteById(id); - } + List list = Arrays.asList(ids); + tbProductRepository.updateByStatus(list); } @Override diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/productimpl/TbShopCategoryServiceImpl.java b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/productimpl/TbShopCategoryServiceImpl.java index 43e85196..5a0971c1 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/productimpl/TbShopCategoryServiceImpl.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/productimpl/TbShopCategoryServiceImpl.java @@ -110,9 +110,8 @@ public class TbShopCategoryServiceImpl implements TbShopCategoryService { public TbShopCategory create(TbShopCategory resources) { resources.setCreatedAt(Instant.now().toEpochMilli()); resources.setUpdatedAt(Instant.now().toEpochMilli()); - - TbShopCategoryDto dto = tbShopCategoryMapper.toDto(tbShopCategoryRepository.save(resources)); - if (resources.getName() != null){ + TbShopCategory byName = tbShopCategoryRepository.findByName(resources.getName(), resources.getShopId()); + if (byName.getName() != null){ throw new BadRequestException("分类名称重复"); } if (resources.getPid() == null || "".equals(resources.getPid())){ @@ -121,8 +120,7 @@ public class TbShopCategoryServiceImpl implements TbShopCategoryService { resources.setTree(Integer.valueOf(resources.getPid().trim())); } - ValidationUtil.isNull(dto.getId(),"TbShopCategory","id",resources.getId()); - tbShopCategoryRepository.save(resources); + ValidationUtil.isNull(resources.getId(),"TbShopCategory","id",resources.getId()); return tbShopCategoryRepository.save(resources); } diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbMerchantRegisterServiceImpl.java b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbMerchantRegisterServiceImpl.java index feb605c3..6bc5a17a 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbMerchantRegisterServiceImpl.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbMerchantRegisterServiceImpl.java @@ -88,6 +88,9 @@ public class TbMerchantRegisterServiceImpl implements TbMerchantRegisterService if (resources.getNumber()>10){ throw new BadRequestException("每次最多生成10条激活码"); } + if (resources.getPeriodYear() <= 0){ + throw new BadRequestException("激活码时长有误"); + } for (int i = 0; i < resources.getNumber(); i++) { TbMerchantRegister tbMerchantRegister = new TbMerchantRegister(); tbMerchantRegister.setRegisterCode(UUID.randomUUID().toString().replaceAll("-", "")); diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopInfoServiceImpl.java b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopInfoServiceImpl.java index 941057e3..1577d50c 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopInfoServiceImpl.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopInfoServiceImpl.java @@ -75,6 +75,8 @@ public class TbShopInfoServiceImpl implements TbShopInfoService { private final TbPlussShopStaffRepository shopStaffRepository; + private final RedisUtils redisUtils; + @Override public Map queryAll(TbShopInfoQueryCriteria criteria){ Sort sort = Sort.by(Sort.Direction.DESC, "id"); @@ -130,8 +132,31 @@ public class TbShopInfoServiceImpl implements TbShopInfoService { BeanUtils.copyProperties(resources,tbShopInfo); tbShopInfo.setCreatedAt(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); + 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.setAccount(resources.getAccount()); @@ -183,22 +208,7 @@ public class TbShopInfoServiceImpl implements TbShopInfoService { tbPlussShopStaff.setCode(save.getPhone()); 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()); } diff --git a/eladmin-system/src/main/resources/config/application.yml b/eladmin-system/src/main/resources/config/application.yml index f5e14942..ad9c02a0 100644 --- a/eladmin-system/src/main/resources/config/application.yml +++ b/eladmin-system/src/main/resources/config/application.yml @@ -26,7 +26,7 @@ spring: properties: hibernate: dialect: org.hibernate.dialect.MySQL5InnoDBDialect - show_sql: true + show_sql: false redis: #数据库索引