package com.lightinit.hsdataportal.impl;

import com.lightinit.hsdataportal.mapper.RequirementFollowMapper;
import com.lightinit.hsdataportal.mapper.RequirementMapper;
import com.lightinit.hsdataportal.model.*;
import com.lightinit.hsdataportal.service.IMyFollowRequirementService;
import com.lightinit.hsdataportal.service.IMyMicroappRequirementService;
import com.lightinit.hsdataportal.spring.DynamicDataContextHolder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MyFollowRequirementServiceImpl implements IMyFollowRequirementService {
    @Autowired
    private RequirementFollowMapper requirementFollowMapper;
    @Override
    public List<MyFollowRequirementListModel> selectOpenList(Long id) {
        DynamicDataContextHolder.setCustomerType(DynamicDataContextHolder.DEFAULT);
        return requirementFollowMapper.selectList(id);
    }


    @Override
    public List<MyFollowRequirementListModel> selectShareList(Long id) {
        DynamicDataContextHolder.setCustomerType(DynamicDataContextHolder.DEFAULT);
        return requirementFollowMapper.selectShareList(id);
    }


    @Override
    public ResultState delfollow(long id) {
        DynamicDataContextHolder.setCustomerType(DynamicDataContextHolder.DEFAULT);
        ResultState<Long> resultState = new ResultState<Long>();
        int sqlResult =requirementFollowMapper.deleteByPrimaryKey(id);
        if (!(sqlResult > 0)){
            resultState.setStateCode(ResultStateCode.INVALID_DATA);
            resultState.setMsg("取消关注失败");
        }
        resultState.setData(id);
        return resultState;
    }
}
