//package com.czg.service.account.service.impl;
//
//import cn.hutool.core.bean.BeanUtil;
//import cn.hutool.core.util.StrUtil;
//import com.alibaba.fastjson2.JSONArray;
//import com.alibaba.fastjson2.JSONObject;
//import com.czg.account.dto.ShopShareCouponDTO;
//import com.czg.account.dto.ShopShareDTO;
//import com.czg.account.entity.ShopCoupon;
//import com.czg.account.service.ShopCouponService;
//import com.czg.account.vo.ShopShareRecordVO;
//import com.czg.account.vo.ShopShareVO;
//import com.czg.exception.ApiNotPrintException;
//import com.czg.service.account.mapper.ShopShareRecordMapper;
//import com.czg.utils.PageUtil;
//import com.github.pagehelper.PageHelper;
//import com.github.pagehelper.PageInfo;
//import com.mybatisflex.core.paginate.Page;
//import com.mybatisflex.core.query.QueryWrapper;
//import com.mybatisflex.spring.service.impl.ServiceImpl;
//import com.czg.account.entity.ShopShare;
//import com.czg.account.service.ShopShareService;
//import com.czg.service.account.mapper.ShopShareMapper;
//import jakarta.annotation.Resource;
//import org.springframework.stereotype.Service;
//
///**
// * 店铺分享 服务层实现。
// *
// * @author zs
// * @since 2025-03-05
// */
//@Service
//public class ShopShareServiceImpl extends ServiceImpl<ShopShareMapper, ShopShare> implements ShopShareService{
//    @Resource
//    private ShopCouponService shopCouponService;
//    @Resource
//    private ShopShareRecordMapper shopShareRecordMapper;
//
//    @Override
//    public ShopShareVO get(Long shopId) {
//        ShopShare shopShare = getOne(new QueryWrapper().eq(ShopShare::getShopId, shopId));
//        ShopShareVO shopShareVO = new ShopShareVO();
//        if (shopShare != null) {
//            BeanUtil.copyProperties(shopShare, shopShareVO);
//            if (StrUtil.isNotBlank(shopShare.getRewardCoupon())) {
////                shopShareVO.setRewardCouponList(shopCouponService.list(new QueryWrapper().eq(ShopCoupon::getShopId, shopId).in(ShopCoupon::getId, JSONArray.parseArray(shopShare.getRewardCoupon()))));
//                shopShareVO.setRewardCouponList(JSONArray.parseArray(shopShare.getRewardCoupon(), ShopShareCouponDTO.class));
//            }
//
//            if (StrUtil.isNotBlank(shopShare.getNewCoupon())) {
////                shopShareVO.setNewCouponList(shopCouponService.list(new QueryWrapper().eq(ShopCoupon::getShopId, shopId).in(ShopCoupon::getId, JSONArray.parseArray(shopShare.getNewCoupon()))));
//                shopShareVO.setNewCouponList(JSONArray.parseArray(shopShare.getNewCoupon(), ShopShareCouponDTO.class));
//            }
//        }
//        return shopShareVO;
//    }
//
//    @Override
//    public Boolean add(Long shopId, ShopShareDTO shopShareDTO) {
//        ShopShare shopShare = getOne(new QueryWrapper().eq(ShopShare::getShopId, shopId));
//        if (shopShare == null) {
//            shopShare = new ShopShareVO();
//            shopShare.setShopId(shopId);
//        }
//
//        if (shopShareDTO.getNewCouponList() != null && !shopShareDTO.getNewCouponList().isEmpty()) {
//            long count = shopCouponService.count(new QueryWrapper().in(ShopCoupon::getId, shopShareDTO.getNewCouponList().stream().map(ShopShareCouponDTO::getId).toList()).eq(ShopCoupon::getShopId, shopId));
//            if (count != shopShareDTO.getNewCouponList().size()) {
//                throw new ApiNotPrintException("优惠券不存在");
//            }
//            shopShare.setNewCoupon(JSONArray.toJSONString(shopShareDTO.getNewCouponList()));
//        }
//
//        if (shopShareDTO.getRewardCouponList() != null && !shopShareDTO.getRewardCouponList().isEmpty()) {
//            long count = shopCouponService.count(new QueryWrapper().in(ShopCoupon::getId, shopShareDTO.getRewardCouponList().stream().map(ShopShareCouponDTO::getId).toList()).eq(ShopCoupon::getShopId, shopId));
//            if (count != shopShareDTO.getRewardCouponList().size()) {
//                throw new ApiNotPrintException("优惠券不存在");
//            }
//            shopShare.setRewardCoupon(JSONArray.toJSONString(shopShareDTO.getRewardCouponList()));
//        }
//        BeanUtil.copyProperties(shopShareDTO, shopShare);
//        return saveOrUpdate(shopShare);
//    }
//
//    @Override
//    public Page<ShopShareRecordVO> recordPage(Long shopId, String key, Integer status) {
//        Page<Object> page = PageUtil.buildPage();
//        PageHelper.startPage(Math.toIntExact(page.getPageNumber()), Math.toIntExact(page.getPageSize()));
//        return PageUtil.convert(new PageInfo<>(shopShareRecordMapper.getRecord(shopId, key, status)));
//    }
//}
