package com.goafanti.standard.service.impl;

import com.goafanti.common.dao.StandardPlatformLinkMapper;
import com.goafanti.common.model.StandardPlatformLink;
import com.goafanti.core.mybatis.BaseMybatisDao;
import com.goafanti.core.mybatis.page.Pagination;
import com.goafanti.core.shiro.token.TokenManager;
import com.goafanti.standard.bo.InputStandardPlatformLink;
import com.goafanti.standard.service.StandardPlatformLinkService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * 标准平台连接(StandardPlatformLink)表服务实现类
 *
 * @author makejava
 * @since 2024-07-02 09:43:35
 */
@Service("standardPlatformLinkService")
public class StandardPlatformLinkServiceImpl extends BaseMybatisDao<StandardPlatformLinkMapper> implements StandardPlatformLinkService {
    @Resource
    private StandardPlatformLinkMapper standardPlatformLinkMapper;


    public Pagination<StandardPlatformLink> list(InputStandardPlatformLink in) {
        Map<String, Object> params = new HashMap<>();
        if (in.getName() != null)params.put("name", in.getName());
        if (in.getStatus() != null)params.put("status", in.getStatus());
        if (in.getStartTime()!= null)params.put("startTime", in.getStartTime());
        if (in.getEndTime()!= null)params.put("endTime", in.getEndTime()+" 23:59:59");
        return (Pagination<StandardPlatformLink>) findPage("queryAllByLimit",
                "queryAllByCount", params, in.getPageNo(), in.getPageSize());
    }

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public StandardPlatformLink queryById(Integer id) {
        return this.standardPlatformLinkMapper.queryById(id);
    }


    /**
     * 新增数据
     *
     * @param in 实例对象
     * @return 实例对象
     */
    @Override
    public StandardPlatformLink insert(StandardPlatformLink in) {
        in.setAid(TokenManager.getAdminId());
        Date now = new Date();
        in.setCreateTime(now);
        in.setUpdateTime(now);
        this.standardPlatformLinkMapper.insert(in);
        return in;
    }

    /**
     * 修改数据
     *
     * @param standardPlatformLink 实例对象
     * @return 实例对象
     */
    @Override
    public StandardPlatformLink update(StandardPlatformLink standardPlatformLink) {
        standardPlatformLink.setUpdateTime(new Date());
        this.standardPlatformLinkMapper.update(standardPlatformLink);
        return this.queryById(standardPlatformLink.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.standardPlatformLinkMapper.deleteById(id) > 0;
    }
}
