/*
 * Author: Zev
 * 生成ServiceImpl
 */
package com.tofly.gpsboot.service.process.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.tofly.api.UserClent;
import com.tofly.pojo.plan.vo.DevicemanagerVo;
import com.tofly.gpsboot.mapper.plan.DevicemanagerMapper;
import com.tofly.pojo.User;
import com.tofly.pojo.plan.Devicemanager;
import com.tofly.gpsboot.service.process.DevicemanagerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

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


/**
 * 车载设备使用情况管理表:TF_YWPN_DEVICEMANAGER_W
 *
 * @author admin
 * @date Thu Mar 18 00:00:00 CST 2021
 */
@Service("devicemanagerService")
public class DevicemanagerServiceImpl extends ServiceImpl<DevicemanagerMapper, Devicemanager> implements DevicemanagerService {
    @Autowired
    private UserClent userClent;
    @Override
    public List<DevicemanagerVo> viewConversion(List<Devicemanager> infoList) {
        List<DevicemanagerVo> infoVoList = new ArrayList<>();
        infoList.forEach(info ->{
            DevicemanagerVo baseInfo = JSONObject.parseObject(JSON.toJSONString(info),DevicemanagerVo.class);
            Long useUser = baseInfo.getUseUser();
            if (null != useUser && 0 != useUser) {
                User userAudit = userClent.getById(useUser).getResult();
                if(null!=userAudit){
                    baseInfo.setUseUserName(userAudit.getRealName());
                }

            }
            infoVoList.add(baseInfo);
        });
        return infoVoList;
    }
}
