package com.huimv.beeboxs.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.huimv.beeboxs.common.utils.Result;
import com.huimv.beeboxs.common.utils.ResultCode;
import com.huimv.beeboxs.entity.BaseHiveFarm;
import com.huimv.beeboxs.entity.SysAccountMultilevel;
import com.huimv.beeboxs.mapper.BaseHiveFarmMapper;
import com.huimv.beeboxs.mapper.SysAccountMultilevelMapper;
import com.huimv.beeboxs.service.IBaseHiveFarmService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author author
 * @since 2022-04-22
 */
@Service
public class BaseHiveFarmServiceImpl extends ServiceImpl<BaseHiveFarmMapper, BaseHiveFarm> implements IBaseHiveFarmService {

    @Autowired
    private SysAccountMultilevelMapper accountMultilevelMapper;
    @Override
    public Result getFarm(Integer userId) {
        SysAccountMultilevel sysAccountMultilevel = accountMultilevelMapper.selectById(userId);
        String farmIds = sysAccountMultilevel.getFarmIds();
        List list ;
        if (userId == 1){
            list = this.list();
        }else {
            List<String> list1 = Arrays.asList(farmIds.split(","));
            list = (List)this.listByIds(list1);
        }
        return new Result(ResultCode.SUCCESS,list);
    }

    @Override
    public Result add(BaseHiveFarm farm) {
        this.save(farm);

        return new Result(10000,"添加成功",true);
    }

}
