package com.starry.admin.modules.weichat.controller;

import com.starry.admin.common.aspect.ClerkUserLogin;
import com.starry.admin.modules.shop.module.entity.PlayShopArticleInfoEntity;
import com.starry.admin.modules.shop.module.entity.PlayShopCarouselInfoEntity;
import com.starry.admin.modules.shop.service.IPlayShopArticleInfoService;
import com.starry.admin.modules.shop.service.IPlayShopCarouselInfoService;
import com.starry.admin.modules.weichat.entity.PlayShopReadArticleVo;
import com.starry.admin.modules.weichat.entity.shop.ShopHomeCarouseInfoReturnVo;
import com.starry.common.result.R;
import com.starry.common.utils.ConvertUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * 店铺接口
 *
 * @author admin
 * @since 2024/5/20 下午11:19
 **/
@Slf4j
@RestController
@RequestMapping("/wx/shop")
public class WxShopController {


    @Resource
    private IPlayShopCarouselInfoService playShopCarouselInfoService;

    @Resource
    IPlayShopArticleInfoService playShopArticleInfoService;

    /**
     * 获取首页轮播图
     */
    @GetMapping(value = "custom/getShopHomeCarouseInfo")
    public R getShopHomeCarouseInfo() {
        List<PlayShopCarouselInfoEntity> entities = playShopCarouselInfoService.selectHomeCarouselInfo();
        return R.ok(ConvertUtil.entityToVoList(entities, ShopHomeCarouseInfoReturnVo.class));
    }


    /**
     * 获取店铺文章列表
     */
    @ClerkUserLogin
    @GetMapping(value = "clerk/getArticleList")
    public R getArticleList() {
        return R.ok(playShopArticleInfoService.selectByList());
    }


    /**
     * 阅读店铺文章
     */
    @ClerkUserLogin
    @GetMapping(value = "clerk/readShopArticleInfo")
    public R readShopArticleInfo(@RequestBody PlayShopReadArticleVo vo) {
        PlayShopArticleInfoEntity entity = playShopArticleInfoService.selectById(vo.getId());
        entity.setVisitsNumber(entity.getVisitsNumber() + 1);
        playShopArticleInfoService.update(entity);
        return R.ok("成功");
    }


}
