package com.xueyi.system.digitalmans.service.impl;

import com.xueyi.common.web.entity.service.impl.BaseServiceImpl;
import com.xueyi.system.api.digitalmans.domain.dto.DmInitSkillDto;
import com.xueyi.system.api.digitalmans.domain.dto.DmSkillDto;
import com.xueyi.system.api.digitalmans.domain.po.DmSkillPo;
import com.xueyi.system.digitalmans.domain.dto.DmCustomMadeDto;
import com.xueyi.system.digitalmans.domain.dto.DmDigitalmanDto;
import com.xueyi.system.digitalmans.domain.query.DmInitSkillQuery;
import com.xueyi.system.digitalmans.domain.query.DmSkillQuery;
import com.xueyi.system.digitalmans.domain.vo.DmSyncDigitalmanVo;
import com.xueyi.system.digitalmans.manager.IDmSkillManager;
import com.xueyi.system.digitalmans.manager.impl.DmInitSkillManager;
import com.xueyi.system.digitalmans.manager.impl.DmSkillManager;
import com.xueyi.system.digitalmans.mapper.DmSkillMapper;
import com.xueyi.system.digitalmans.service.IDmSkillService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * 访客管理 服务层处理
 *
 * @author xueyi
 */
@Service
public class DmSkillServiceImpl extends BaseServiceImpl<DmSkillQuery, DmSkillDto, IDmSkillManager> implements IDmSkillService {

    @Autowired
    DmSkillMapper skillMapper;

    @Autowired
    DmInitSkillManager initSkillManager;

    @Autowired
    DmSkillManager skillManager;

    /**
     * 查询技能对象列表 | 数据权限
     *
     * @param dmSkill 技能对象
     * @return 访客对象集合
     */
    @Override
    //@DataScope(userAlias = "createBy", mapperScope = {"DmVisitorsMapper"})
    public List<DmSkillDto> selectListScope(DmSkillQuery dmSkill) {
        return baseManager.selectList(dmSkill);
    }

    @Override
    public List<DmSkillDto> selectSkillListByTimestamp(Long manId, String timestamp) {
        DmSyncDigitalmanVo vo =  new DmSyncDigitalmanVo();
        vo.setTimestamp(timestamp);
        vo.setManId(manId);
        List<DmSkillDto> list = skillMapper.selectSkillListByH5(vo);
        return list;
    }

    @Override
    public DmSkillPo selectSkillByCode(String skillCode) {
        return skillMapper.selectSkillByCode(skillCode);
    }

    @Override
    public int customInsert(DmCustomMadeDto dto) {

        return super.baseManager.customInsert(dto);
    }

    @Override
    public int batchInitInsert(DmDigitalmanDto digitalmanDto) {
        // 获取初始化列表
        List<DmInitSkillDto> initList = initSkillManager.selectList(new DmInitSkillQuery());
        List<DmSkillDto> list = new ArrayList<>();
        initList.forEach(item->{
            DmSkillDto dto = new DmSkillDto();
            dto.setInfo(item.getInfo());
            dto.setManId(digitalmanDto.getId());
            dto.setName(item.getName());
            dto.setResp(item.getResp());
            dto.setSkillCode(item.getSkillCode());
            dto.setMotionId(item.getMotionId());
            dto.setMotionName(item.getMotionName());
            dto.setStatus("1");
            list.add(dto);
        });
        return skillManager.insertBatch(list);
    }
}