package com.yc.ship.module.miniapplet.service.menu;

import com.yc.ship.module.miniapplet.controller.admin.menu.vo.AppletMenuPageReqVO;
import com.yc.ship.module.miniapplet.controller.admin.menu.vo.AppletMenuSaveReqVO;
import com.yc.ship.module.miniapplet.dal.dataobject.menu.AppletMenuDO;
import com.yc.ship.module.miniapplet.dal.mysql.menu.AppletMenuMapper;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;

import com.yc.ship.framework.common.pojo.PageResult;
import com.yc.ship.framework.common.util.object.BeanUtils;

import java.util.List;


/**
 * 小程序菜单 Service 实现类
 *
 * @author 管理员
 */
@Service
@Validated
public class AppletMenuServiceImpl implements AppletMenuService {

    @Resource
    private AppletMenuMapper appletMenuMapper;

    @Override
    public Long createMenu(AppletMenuSaveReqVO createReqVO) {
        // 插入
        AppletMenuDO menu = BeanUtils.toBean(createReqVO, AppletMenuDO.class);
        appletMenuMapper.insert(menu);
        // 返回
        return menu.getId();
    }

    @Override
    public void updateMenu(AppletMenuSaveReqVO updateReqVO) {
        // 更新
        AppletMenuDO updateObj = BeanUtils.toBean(updateReqVO, AppletMenuDO.class);
        appletMenuMapper.updateById(updateObj);
    }

    @Override
    public void deleteMenu(Long id) {
        // 删除
        appletMenuMapper.deleteById(id);
    }


    @Override
    public AppletMenuDO getMenu(Long id) {
        return appletMenuMapper.selectById(id);
    }

    @Override
    public PageResult<AppletMenuDO> getMenuPage(AppletMenuPageReqVO pageReqVO) {
        return appletMenuMapper.selectPage(pageReqVO);
    }

    @Override
    public List<AppletMenuDO> getAppMenuList() {
        return appletMenuMapper.selectAppList();
    }

}