/*
 * Copyright (c) 京北方信息技术股份有限公司 Corporation 2021 . All rights reserved.
 *
 */
package net.northking.cctp.project.api.team.service;

import com.hzbank.testteam.autotest.dependencies.monsterDependency.dto.UserDTO;
import net.northking.cctp.common.db.annotation.DatabaseReadOnly;
import net.northking.cctp.common.http.QueryByPage;
import net.northking.cctp.project.bus.feign.HzBankFeign;
import net.northking.cctp.project.dto.team.MtProjectTeamDetailDto;
import net.northking.cctp.project.dto.team.MtProjectTeamQueryDto;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 系统人员表服务实现类
 *
 * @author maven-cctp-plugin
 * @since 1.0
 */

@Service
@ConditionalOnMissingBean(name = "MtProjectTeamApiServiceImpl")
public class MtProjectTeamApiServiceImpl implements MtProjectTeamApiService {


    @Autowired
    private HzBankFeign hzBankFeign;


    @Override
    @DatabaseReadOnly
    public List<MtProjectTeamDetailDto> pagingQuery(QueryByPage<MtProjectTeamQueryDto> queryByPage) {
        List<MtProjectTeamDetailDto> list = new ArrayList<>();
        MtProjectTeamQueryDto query = queryByPage.getQuery();
        // 根据用户姓名和登录名查询用户的id
        Map<String, Object> params = new HashMap<>();
        if (!StringUtils.isEmpty(query.getUserChnName())) {
            params.put("employeeName", query.getUserChnName());
        }
        if (!StringUtils.isEmpty(query.getLoginNo())) {
            params.put("userName", query.getLoginNo());
        }
        params.put("limitCount", queryByPage.getPageSize());
        List<UserDTO> userDTOS = hzBankFeign.selectByMap(params);
        if (!CollectionUtils.isEmpty(userDTOS)) {
            for (UserDTO userDTO : userDTOS) {
                MtProjectTeamDetailDto mtProjectTeamDetailDto = new MtProjectTeamDetailDto();
                mtProjectTeamDetailDto.setUserId(userDTO.getId().toString());
                mtProjectTeamDetailDto.setUserChnName(userDTO.getEmployeeName());
                mtProjectTeamDetailDto.setIsDeleted(userDTO.getDeleted());
                list.add(mtProjectTeamDetailDto);
            }
        }
        return list;
    }





}
