package com.yonge.cooleshow.auth.service.impl;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yonge.cooleshow.auth.api.entity.WxTemplateMessage;
import com.yonge.cooleshow.auth.dal.dao.WxTemplateMessageMapper;
import com.yonge.cooleshow.auth.dal.wrapper.WxTemplateMessageWrapper;
import com.yonge.cooleshow.auth.service.WxTemplateMessageService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * 微信模板消息内容
 * 2023-02-01 14:21:57
 */
@Slf4j
@Service
public class WxTemplateMessageServiceImpl extends ServiceImpl<WxTemplateMessageMapper, WxTemplateMessage> implements WxTemplateMessageService {

	/**
     * 查询详情
     * @param id 详情ID
     * @return WxTemplateMessage
     */
	@Override
    public WxTemplateMessage detail(Long id) {

        return baseMapper.selectById(id);
    }

    /**
     * 分页查询
     * @param page IPage<WxTemplateMessage>
     * @param query WxTemplateMessageWrapper.WxTemplateMessageQuery
     * @return IPage<WxTemplateMessage>
     */
    @Override
    public IPage<WxTemplateMessage> selectPage(IPage<WxTemplateMessage> page, WxTemplateMessageWrapper.WxTemplateMessageQuery query) {

        return page.setRecords(baseMapper.selectPage(page, query));
    }

    /**
     * 添加
     * @param wxTemplateMessage WxTemplateMessageWrapper.WxTemplateMessage
     * @return Boolean
     */
    @Override
    public Boolean add(WxTemplateMessageWrapper.WxTemplateMessage wxTemplateMessage) {

        return this.save(JSON.parseObject(wxTemplateMessage.jsonString(), WxTemplateMessage.class));
    }

    /**
     * 更新
     * @param wxTemplateMessage WxTemplateMessageWrapper.WxTemplateMessage
     * @return Boolean
     */
    @Override
    public Boolean update(WxTemplateMessageWrapper.WxTemplateMessage wxTemplateMessage){

        return this.updateById(JSON.parseObject(wxTemplateMessage.jsonString(), WxTemplateMessage.class));
    }
}
