/*
 * Author: Zev
 * 生成ServiceImpl
 */
package com.tofly.gpsboot.service.paln.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.GpscalculateVo;
import com.tofly.gpsboot.mapper.plan.GpscalculateMapper;
import com.tofly.pojo.User;
import com.tofly.pojo.plan.Gpscalculate;
import com.tofly.gpsboot.service.paln.GpscalculateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

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

/**
 * 巡查统计计算表：TF_YWPN_GPSCALCULATE_W
 *
 * @author admin
 * @date Thu Mar 18 00:00:00 CST 2021
 */
@Service("gpscalculateService")
public class GpscalculateServiceImpl extends ServiceImpl<GpscalculateMapper, Gpscalculate> implements GpscalculateService {

    @Autowired
    private UserClent userClent;

    @Override
    public List<GpscalculateVo> viewConversion(List<Gpscalculate> infoList) {
        List<GpscalculateVo> voList = new ArrayList<>();
        infoList.forEach(info ->{
            GpscalculateVo vo = JSONObject.parseObject(JSON.toJSONString(info),GpscalculateVo.class);
            // 填充巡查用户名称
            Long userId = info.getUserId();
            if (null!= userId && 0!=userId) {
                User userAudit = userClent.getById(userId).getResult();
                if(null!=userAudit){
                    vo.setUserIdName(userAudit.getRealName());
                }

            }
            voList.add(vo);
        });
        return voList;
    }
}
