package com.xueyi.system.staff.manager.impl;


import com.xueyi.common.core.context.SecurityContextHolder;
import com.xueyi.system.api.resource.domain.vo.DmResourcesVo;
import com.xueyi.system.api.staff.domain.dto.DmStaffDto;
import com.xueyi.system.api.staff.domain.po.DmStaffPo;
import com.xueyi.system.api.resource.domain.po.DmResourcesPo;
import com.xueyi.system.resource.mapper.DmResourcesMapper;
import com.xueyi.system.staff.domain.query.DmStaffQuery;
import com.xueyi.system.staff.domain.model.DmStaffConverter;
import com.xueyi.system.staff.mapper.DmStaffMapper;
import com.xueyi.common.web.entity.manager.impl.BaseManagerImpl;
import com.xueyi.system.staff.manager.IDmStaffManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.util.List;

/**
 * 人员管理 数据封装层处理
 *
 * @author xueyi
 */
@Component
public class DmStaffManager extends BaseManagerImpl<DmStaffQuery, DmStaffDto, DmStaffPo, DmStaffMapper, DmStaffConverter> implements IDmStaffManager {
    @Autowired
    DmResourcesMapper resourcesMapper;


    @Override
    public List<DmStaffDto> selectList(DmStaffQuery query) {
        List<DmStaffDto> dtos = super.selectList(query);
        dtos.forEach(item-> {
            DmResourcesPo po = resourcesMapper.selectById(item.getResourceId());
            if (po != null) {
                DmResourcesVo vo = new DmResourcesVo();
                vo.setId(po.getId());
                vo.setName(po.getName());
                vo.setTag(po.getTag());
                vo.setUrl(po.getUrl());
                vo.setType(po.getType());
                item.setResource(vo);
            }
        });
        return dtos;
    }

//    @Override
//    public int insert(DmStaffDto dto) {
//        dto.setUpdateTime(LocalDateTime.now());
//        dto.setUpdateBy(Long.parseLong(String.valueOf(SecurityContextHolder.getLocalMap().get("enterprise_id"))));
//        return super.insert(dto);
//    }
}