package com.citygis.web.service.impl;

import cn.hutool.core.lang.Snowflake;
import cn.hutool.core.util.IdUtil;
import com.citygis.common.annotation.DataScope;
import com.citygis.common.core.domain.AjaxResult;
import com.citygis.web.domain.TabSystemOther;
import com.citygis.web.mapper.TabSystemOtherMapper;
import com.citygis.web.service.ITabSystemOtherService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.Collections;
import java.util.Date;
import java.util.List;

import static com.citygis.common.utils.SecurityUtils.*;

/**
 * <p>
 * 登录页系统连接 服务实现类
 * </p>
 *
 * @author citygis
 * @since 2024-12-25
 */
@Service
public class TabSystemOtherServiceImpl extends ServiceImpl<TabSystemOtherMapper, TabSystemOther> implements ITabSystemOtherService {

    @Resource
    TabSystemOtherMapper tabSystemOtherMapper;

    @Override
    @DataScope(userAlias = "tso", deptAlias = "tso")
    public List<TabSystemOther> getTabSystemOtherList(TabSystemOther tabSystemOther) {
        return tabSystemOtherMapper.getTabSystemOtherList(tabSystemOther);
    }

    @Override
    @Transactional
    public AjaxResult insertTabSystemOther(TabSystemOther tabSystemOther) {

        Snowflake snowflake = IdUtil.createSnowflake(1,1);
        long id = snowflake.nextId();

        tabSystemOther.setId(id);
        tabSystemOther.setUserId(getUserId());
        tabSystemOther.setDeptId(getDeptId());
        tabSystemOther.setCreateBy(getUsername());
        tabSystemOther.setCreateTime(new Date());

        boolean b = this.save(tabSystemOther);
        if (b) {
            return AjaxResult.success("添加成功");
        } else {
            return AjaxResult.error("添加失败");
        }
    }

    @Override
    @Transactional
    public AjaxResult updateTabSystemOtherById(TabSystemOther tabSystemOther) {
        tabSystemOther.setUpdateBy(getUsername());
        tabSystemOther.setUpdateTime(new Date());

        boolean b = this.updateById(tabSystemOther);
        if (b) {
            return AjaxResult.success("修改成功");
        } else {
            return AjaxResult.error("修改失败");
        }
    }

    @Override
    @Transactional
    public AjaxResult falseDeleteTabSystemOtherById(Long id) {

        TabSystemOther tabSystemOther = new TabSystemOther();
        tabSystemOther.setId(id);
        tabSystemOther.setIsDel(1);

        boolean b = this.updateById(tabSystemOther);
        if (b) {
            return AjaxResult.success("删除成功");
        } else {
            return AjaxResult.error("删除失败");
        }
    }
}
