package com.bonus.hn.bearing.capacity.backstage.companypro.service;

import com.bonus.hn.bearing.capacity.backstage.companypro.dao.OwmTeamQueryDao;
import com.bonus.hn.bearing.capacity.backstage.companypro.entity.OwmTeamQueryBean;
import com.bonus.hn.bearing.capacity.backstage.companypro.entity.TreeBean;
import com.bonus.hn.bearing.capacity.backstage.manager.utils.DateTimeHelper;
import com.bonus.hn.bearing.capacity.backstage.manager.utils.UserUtil;
import org.springframework.stereotype.Service;

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

/**
 * 包名称：com.bonus.hn.bearing.capacity.backstage.companypro.service
 * 类名称：ProjectManagerServiceImpl
 * 类描述：
 * 创建人：@author xxxxxx
 * 创建时间：2023年11月06日 16:27
 */
@Service("OwmTeamQueryService")
public class OwmTeamQueryServiceImpl implements OwmTeamQueryService{

    @Resource
    private OwmTeamQueryDao dao;

    @Override
    public List<OwmTeamQueryBean> getProjectManagementTeamsList(OwmTeamQueryBean o) {
        o.setLevel(UserUtil.getLoginUser().getLevel());
        o.setOrgIds(UserUtil.getLoginUser().getOrgId());
        return dao.getProjectManagementTeamsList(o);
    }

    @Override
    public List<OwmTeamQueryBean> getowmTeamQueryTeamsFormList(OwmTeamQueryBean o) {
        return dao.getowmTeamQueryTeamsFormList(o);
    }

    @Override
    public List<OwmTeamQueryBean> getTeamsList(OwmTeamQueryBean o) {
        o.setLevel(UserUtil.getLoginUser().getLevel());
        o.setOrgIds(UserUtil.getLoginUser().getOrgId());
        return dao.getTeamsList(o);
    }

    @Override
    public int bindOrUnBindProTeam(OwmTeamQueryBean bean) {
        bean.setUserId(UserUtil.getLoginUser().getId().toString());
        bean.setTime(DateTimeHelper.getNowDayHMS());
        int num = 0;
        if ("1".equals(bean.getType())){
            //绑定
            num = dao.bindProTeam(bean);
            if (num == 1){
                bean.setStatus("1");
                num = dao.updateStatus(bean);
            }
        }else {
            //解绑
            num = dao.unBindProTeam(bean);
            if (num == 1){
                bean.setStatus("0");
                bean.setProId("");
                num = dao.updateStatus(bean);
            }
        }
        return num;
    }

    @Override
    public List<TreeBean> getCompanyProTree(TreeBean o) {
        o.setLevel(UserUtil.getLoginUser().getLevel());
        o.setOrgIds(UserUtil.getLoginUser().getOrgId());
        return dao.getCompanyProTree(o);
    }
}
