package com.unis.base.server.domain;

import com.unis.base.common.vo.UserSealInfoVo;
import com.unis.base.common.vo.UserSealRoleVo;
import com.unis.base.server.dao.UserSealInfoDao;
import com.unis.base.server.dao.UserSealRoleDao;
import com.unis.base.server.entity.UserSealInfoDo;
import com.unis.base.server.entity.UserSealRoleDo;
import com.unis.common.utils.CurrentUtil;
import com.unis.common.utils.JsonUtils;
import com.unis.common.utils.LsBeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import tk.mybatis.mapper.entity.Example;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

/**
 * @author by PIG
 * 2022/6/22 17
 */
@Component
public class UserSealRoleDomain {

    @Autowired
    private UserSealRoleDao userSealRoleDao;
    @Autowired
    private UserSealInfoDao userSealInfoDao;

    public List<UserSealInfoVo> listSealInfoByAccountName(String accountName) {
        UserSealRoleDo queryEntity = new UserSealRoleDo();
        queryEntity.setAccountName(accountName);
        String seals = userSealRoleDao.getSealsByAccount(accountName);
        if (null == seals) {
            return new ArrayList<>();
        }
        String[] sealNumberArray = seals.split(",");
        List<String> list = Arrays.asList(sealNumberArray);

        Example infoExample = new Example(UserSealInfoDo.class);
        Example.Criteria criteria = infoExample.createCriteria();
        criteria.andIn("sealNumber", list).orIn("sealName", list);
        List<UserSealInfoDo> userSealRoleDos = userSealInfoDao.selectByExample(infoExample);

        return userSealRoleDos.stream().map(ele -> {
            UserSealInfoVo userSealInfoVo = new UserSealInfoVo();
            LsBeanUtils.copyAllProperties(ele, userSealInfoVo);
            return userSealInfoVo;
        }).collect(Collectors.toList());
    }

    public List<UserSealInfoVo> listAllSealInfo() {
        Example infoExample = new Example(UserSealInfoDo.class);
        Example.Criteria criteria = infoExample.createCriteria();
        criteria.andIsNull("remark");
        List<UserSealInfoDo> userSealRoleDos = userSealInfoDao.selectByExample(infoExample);

        return userSealRoleDos.stream().map(ele -> {
            UserSealInfoVo userSealInfoVo = new UserSealInfoVo();
            LsBeanUtils.copyAllProperties(ele, userSealInfoVo);
            return userSealInfoVo;
        }).collect(Collectors.toList());
    }
}
