package com.bonus.system.service.impl;

import com.bonus.common.core.utils.StringUtils;
import com.bonus.common.core.utils.encryption.Sm4Utils;
import com.bonus.common.core.web.domain.AjaxResult;
import com.bonus.system.domain.SysParamsDto;
import com.bonus.system.domain.vo.SysSelectVo;
import com.bonus.system.mapper.SelectMapper;
import com.bonus.system.service.ISelectService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

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

/**
 * @className:SelectServiceImpl
 * @author:cwchen
 * @date:2024-07-15-10:25
 * @version:1.0
 * @description:公共下拉选-serviceImpl
 */
@Service(value = "ISelectService")
@Slf4j
public class SelectServiceImpl implements ISelectService {
    @Resource(name = "SelectMapper")
    private SelectMapper mapper;

    @Override
    public AjaxResult getTeamList(SysParamsDto dto) {
        try {
            List<SysSelectVo> list = mapper.getTeamList(dto);
            return AjaxResult.success(list);
        } catch (Exception e) {
            log.error("获取班组下拉选",e);
            return AjaxResult.error();
        }
    }

    @Override
    public AjaxResult getProList(SysParamsDto dto) {
        try {
            List<SysSelectVo> list = mapper.getProList(dto);
            return AjaxResult.success(list);
        } catch (Exception e) {
            log.error(e.toString(),e);
            return AjaxResult.error();
        }
    }

    @Override
    public AjaxResult getTeamLists(SysParamsDto dto) {
        List<Map<String,Object>> list = new ArrayList<>();
        try {
            list = mapper.getTeamLists(dto);
        } catch (Exception e) {
            log.error(e.toString(),e);
        }
        return AjaxResult.success(list);
    }

    @Override
    public AjaxResult getPowerLists(SysParamsDto dto) {
        try {
            List<SysSelectVo> list = mapper.getPowerLists(dto);
            return AjaxResult.success(list);
        } catch (Exception e) {
            log.error(e.toString(),e);
            return AjaxResult.error();
        }
    }

    @Override
    public AjaxResult getTeamPeople(SysParamsDto dto) {
        try {
            List<SysSelectVo> list = mapper.getTeamPeople(dto);
            for (SysSelectVo vo : list) {
                String[] valArr = vo.getName().split("-");
                if(StringUtils.isNotEmpty(valArr[1])){
                    vo.setName(valArr[0] + "-" + Sm4Utils.decode(valArr[1]));
                }
            }
            return AjaxResult.success(list);
        } catch (Exception e) {
            log.error(e.toString(),e);
            return AjaxResult.error();
        }
    }
}
