package com.djhk.uav.warLawLibrary.service.impl;

import com.djhk.common.core.redis.RedisCache;
import com.djhk.common.utils.DateUtils;
import com.djhk.common.utils.StringUtils;
import com.djhk.uav.warLawLibrary.domain.WarLawLibrary;
import com.djhk.uav.warLawLibrary.mapper.WarLawLibraryMapper;
import com.djhk.uav.warLawLibrary.service.IWarLawLibraryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.concurrent.TimeUnit;

/**
 * 【请填写功能名称】Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-11-15
 */
@Service
public class WarLawLibraryServiceImpl implements IWarLawLibraryService
{
    @Autowired
    private WarLawLibraryMapper warLawLibraryMapper;

    @Autowired
    private RedisCache redisService;

    /**
     * 查询【请填写功能名称】
     * 
     * @param id 【请填写功能名称】主键
     * @return 【请填写功能名称】
     */
    @Override
    public WarLawLibrary selectWarLawLibraryById(Long id)
    {
        return warLawLibraryMapper.selectWarLawLibraryById(id);
    }

    /**
     * 查询【请填写功能名称】列表
     * 
     * @param warLawLibrary 【请填写功能名称】
     * @return 【请填写功能名称】
     */
    @Override
    public List<WarLawLibrary> selectWarLawLibraryList(WarLawLibrary warLawLibrary)
    {
        return warLawLibraryMapper.selectWarLawLibraryList(warLawLibrary);
    }

    /**
     * 新增【请填写功能名称】
     * 
     * @param warLawLibrary 【请填写功能名称】
     * @return 结果
     */
    @Override
    public int insertWarLawLibrary(WarLawLibrary warLawLibrary)
    {
        warLawLibrary.setCreateTime(DateUtils.getNowDate());
        int i = warLawLibraryMapper.insertWarLawLibrary(warLawLibrary);
        warLawLibrary.setId((long) i);
        redisService.setCacheObject("war_law_library" + warLawLibrary.getWarName(),warLawLibrary,30000L, TimeUnit.DAYS);
        return i;
    }

    /**
     * 修改【请填写功能名称】
     * 
     * @param warLawLibrary 【请填写功能名称】
     * @return 结果
     */
    @Override
    public int updateWarLawLibrary(WarLawLibrary warLawLibrary)
    {
        warLawLibrary.setUpdateTime(DateUtils.getNowDate());
        WarLawLibrary w = redisService.getCacheObject("war_law_library" + warLawLibrary.getWarName());
        if (!StringUtils.isEmpty(w.toString()))
        {
            redisService.deleteObject("war_law_library" + warLawLibrary.getWarName());
            redisService.setCacheObject("war_law_library" + warLawLibrary.getWarName(),warLawLibrary,30000L, TimeUnit.DAYS);
        }
        return warLawLibraryMapper.updateWarLawLibrary(warLawLibrary);
    }

    /**
     * 批量删除【请填写功能名称】
     * 
     * @return 结果
     */
    @Override
    public int deleteWarLawLibraryByIds(Long id)
    {
            WarLawLibrary lawLibrary = warLawLibraryMapper.selectWarLawLibraryById(id);
            WarLawLibrary w = redisService.getCacheObject("war_law_library" + lawLibrary.getWarName());
            if (!StringUtils.isEmpty(w.toString()))
            {
                redisService.deleteObject("war_law_library" + lawLibrary.getWarName());
            }
        return warLawLibraryMapper.deleteWarLawLibraryByIds(id);
    }

    /**
     * 删除【请填写功能名称】信息
     * 
     * @param id 【请填写功能名称】主键
     * @return 结果
     */
    @Override
    public int deleteWarLawLibraryById(Long id)
    {
        return warLawLibraryMapper.deleteWarLawLibraryById(id);
    }
    @Override
    public int removeByWarName(String warName)
    {
        return warLawLibraryMapper.removeByWarName(warName);
    }
}
