package cn.iocoder.yudao.module.jx.service.impl;


import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils;
import cn.iocoder.yudao.module.jx.domain.SopeNess;
import cn.iocoder.yudao.module.jx.mapper.SopeNessMapper;
import cn.iocoder.yudao.module.jx.service.ISopeNessService;
import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;


/**
 * 经营范围Service业务层处理
 *
 * @author ruoyi
 * @date 2024-05-23
 */
@Service
public class SopeNessServiceImpl implements ISopeNessService
{
    @Autowired
    private SopeNessMapper sopeNessMapper;

    @Resource
    private AdminUserApi userApi;

    /**
     * 查询经营范围
     *
     * @param id 经营范围主键
     * @return 经营范围
     */
    @Override
    public SopeNess selectSopeNessById(Long id)
    {
        return sopeNessMapper.selectSopeNessById(id);
    }

    /**
     * 查询经营范围列表
     *
     * @param sopeNess 经营范围
     * @return 经营范围
     */
    @Override
    public IPage<SopeNess> selectSopeNessList(SopeNess sopeNess, Page<SopeNess> page)
    {
        Long userId = SecurityFrameworkUtils.getLoginUserId();
        AdminUserRespDTO user = userApi.getUser(userId);
        Long deptId = user.getDeptId();
        sopeNess.setDeptId(deptId);
        return sopeNessMapper.selectSopeNessList(sopeNess,page);
    }

    /**
     * 新增经营范围
     *
     * @param sopeNess 经营范围
     * @return 结果
     */
    @Override
    public int insertSopeNess(SopeNess sopeNess)
    {
        Long userId = SecurityFrameworkUtils.getLoginUserId();
        AdminUserRespDTO user = userApi.getUser(userId);
        Long deptId = user.getDeptId();
        sopeNess.setDeptId(deptId);
        //sopeNess.setCreateTime(DateUtils.getNowDate());
        return sopeNessMapper.insertSopeNess(sopeNess);
    }

    /**
     * 修改经营范围
     *
     * @param sopeNess 经营范围
     * @return 结果
     */
    @Override
    public int updateSopeNess(SopeNess sopeNess)
    {
        Long userId = SecurityFrameworkUtils.getLoginUserId();
        AdminUserRespDTO user = userApi.getUser(userId);
        Long deptId = user.getDeptId();
        sopeNess.setDeptId(deptId);
        //sopeNess.setUpdateTime(DateUtils.getNowDate());
        return sopeNessMapper.updateSopeNess(sopeNess);
    }

    /**
     * 批量删除经营范围
     *
     * @param ids 需要删除的经营范围主键
     * @return 结果
     */
    @Override
    public int deleteSopeNessByIds(Long[] ids)
    {
        return sopeNessMapper.deleteSopeNessByIds(ids);
    }

    /**
     * 删除经营范围信息
     *
     * @param id 经营范围主键
     * @return 结果
     */
    @Override
    public int deleteSopeNessById(Long id)
    {
        return sopeNessMapper.deleteSopeNessById(id);
    }
}
