/*
 *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions are met:
 *
 *  Redistributions of source code must retain the above copyright notice,
 *  this list of conditions and the following disclaimer.
 *  Redistributions in binary form must reproduce the above copyright
 *  notice, this list of conditions and the following disclaimer in the
 *  documentation and/or other materials provided with the distribution.
 *  Neither the name of the dreamlu.net developer nor the names of its
 *  contributors may be used to endorse or promote products derived from
 *  this software without specific prior written permission.
 *  Author: Chill 庄骞 (smallchill@163.com)
 */
package org.springblade.manager.service.impl;

import org.apache.ibatis.annotations.Param;
import org.springblade.core.tool.node.ForestNodeMerger;
import org.springblade.manager.dto.FindAllUserByConditionDTO;
import org.springblade.manager.entity.ContractInfo;
import org.springblade.manager.vo.CRolePostVO;
import org.springblade.manager.vo.ContractInfoVO;
import org.springblade.manager.mapper.ContractInfoMapper;
import org.springblade.manager.service.IContractInfoService;
import org.springblade.core.mp.base.BaseServiceImpl;
import org.springblade.manager.vo.WbsTreeContractTreeVO;
import org.springblade.manager.vo.WbsTreeVO;
import org.springblade.system.user.entity.User;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.metadata.IPage;

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

/**
 * 合同段信息表 服务实现类
 *
 * @author liuyc
 * @since 2022-04-14
 */
@Service
public class ContractInfoServiceImpl
        extends BaseServiceImpl<ContractInfoMapper, ContractInfo>
        implements IContractInfoService {

    @Resource
    private ContractInfoMapper contractInfoMapper;

    @Override
    public IPage<ContractInfoVO> selectContractInfoPage(IPage<ContractInfoVO> page, ContractInfoVO contractInfo) {
        List<ContractInfoVO> dat = baseMapper.selectContractInfoPage(page, contractInfo);
        return page.setRecords(dat);
    }

    @Override
    public List<ContractInfo> selectContractInfoPageByPid(String pid) {
        return baseMapper.selectContractInfoPageByPid(pid);
    }

    @Override
    public List<CRolePostVO> findJobByRoleId(String id) {
        return contractInfoMapper.findJobByRoleId(id);
    }

    @Override
    public List<User> findAllUserByCondition(FindAllUserByConditionDTO values) {
        return contractInfoMapper.findAllUserByCondition(values);
    }

    @Override
    public List<User> findUserListByCondition(FindAllUserByConditionDTO values) {
        return contractInfoMapper.findUserListByCondition(values);
    }

    @Override
    public List<User> findUserInfoByCondition(String rId, String pId, String userName) {
        if (userName == null || ("").equals(userName)) {
            userName = "";
        }
        return contractInfoMapper.findUserInfoByCondition(rId, pId, userName);
    }


    @Override
    public List<User> findUserByName(String name) {
        List<User> userByName = contractInfoMapper.findUserByName(name);
        return userByName;
    }

    @Override
    public Boolean updatePasswordByUserId(String userId, String password) {
        Integer row = contractInfoMapper.updatePasswordByUserId(userId, password);
        if (row > 0) {
            return true;
        }
        return false;
    }

    @Override
    public String selectStartFileId(String startFileUrl) {
//        return contractInfoMapper.selectStartFileId(startFileUrl);
        return null;
    }

    @Override
    public Boolean deleteFile(String url) {
        return contractInfoMapper.deleteFile(url);
    }

    @Override
    public List<WbsTreeContractTreeVO> tree(String wbsId, String projectId, String contractId) {
        return ForestNodeMerger.merge(baseMapper.tree(wbsId, projectId, contractId));
    }
}
