package com.template.services.impl;
import com.template.mapper.SystemMenuMapper;
import com.template.model.pojo.SystemMenu;
import com.template.model.result.CommonResult;
import com.template.model.vo.SystemMenuVo;
import com.template.services.SystemMenuService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.List;
/**
*
* 服务实现类
*
*
* @author ceshi
* @since 2023-03-30
*/
@Service
public class SystemMenuServiceImpl extends ServiceImpl implements SystemMenuService {
@Autowired
private SystemMenuMapper systemMenuMapper;
/*
查询获取所有菜单
* */
@Override
@Cacheable(value = {"getSystemMenus"})
public CommonResult> getSystemMenus() {
List result = systemMenuMapper.selectList(null);
return CommonResult.ok().setResult(result);
}
@Override
//根据参数清除名为roomThirdSetting的缓存
@CacheEvict(value = "getSystemMenus")
public CommonResult insertSystemMenus(SystemMenu systemMenu) {
int result = systemMenuMapper.insert(systemMenu);
return result > 0 ? CommonResult.ok() : CommonResult.fail();
}
@Override
public CommonResult deleteSystemMenu(Integer userID) {
int result = systemMenuMapper.deleteById(Long.valueOf(userID));
return result > 0 ? CommonResult.ok() : CommonResult.fail();
}
@Override
public CommonResult> getSystemMenusByParentId(Long parentId) {
HashMap map = new HashMap<>();
// 自定义要查询
map.put("menu_parent_id",parentId);
List result = systemMenuMapper.selectByMap(map);
return CommonResult.ok().setResult(result);
}
@Override
@CacheEvict(value = "insertPlaybackRecord", allEntries = true)//allEntries清除整个缓存区
public CommonResult insertPlaybackRecord(SystemMenu systemMenu) {
Integer result = systemMenuMapper.insert(systemMenu); // 帮我们自动生成id
return CommonResult.ok().setResult(result);// 发现,id会自动回填
}
@Override
@Cacheable("insertPlaybackRecord")
public CommonResult> getPlaybackRecords() {
List result = systemMenuMapper.selectList(null);
return CommonResult.ok().setResult(result);
}
@Override
public CommonResult> getPlaybackRecordBySql() {
List result = systemMenuMapper.querySystemMenuAll();
return CommonResult.ok().setResult(result);
}
}