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

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.tofly.api.UserClent;
import com.tofly.gpsboot.common.system.IsUseEnum;
import com.tofly.pojo.User;
import com.tofly.pojo.plan.dto.PlanpathDto;
import com.tofly.pojo.plan.vo.PlanpathVo;
import com.tofly.gpsboot.mapper.plan.PlanpathMapper;
import com.tofly.gpsboot.service.daily.PlanpathService;
import com.tofly.pojo.plan.Planpath;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

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


/**
 * 巡检线信息表：TF_YWPN_PLANPATH_W
 *
 * @author admin
 * @date Thu Mar 18 00:00:00 CST 2021
 */
@Service("planpathService")
public class PlanpathServiceImpl extends ServiceImpl<PlanpathMapper, Planpath> implements PlanpathService {

    @Autowired
    private UserClent userClent;

    @Override
    public List<PlanpathVo> viewConversion(List<Planpath> infoList) {
        List<PlanpathVo> infoVoList = new ArrayList<>();
        infoList.forEach(info -> {
            PlanpathVo baseInfoVo = JSON.parseObject(JSON.toJSONString(info), PlanpathVo.class);
            // 巡查类型名称/是否被占用名称
//            baseInfoVo.setInspectType(inspecttypeService.getById(info.getInspectType()).getName());
            baseInfoVo.setIsUse(IsUseEnum.getCodeForValue(info.getIsUse()));
            User result = userClent.getById(info.getCreateUser()).getResult();
            if(null!=result){
                baseInfoVo.setCreateUserName(result.getRealName());
            }
            infoVoList.add(baseInfoVo);
        });
        return infoVoList;

    }

    @Override
    public Page<PlanpathVo> getPlanPathPage(Page page, PlanpathDto parDto) {
//        Planpath planpath = JSON.parseObject(JSON.toJSONString(parDto),Planpath.class);
        QueryWrapper<Planpath> wrapper = new QueryWrapper();
        String name = parDto.getName();
        if(!StringUtils.isEmpty(name)){
            wrapper.like("NAME",name);
        }
//        wrapper.setEntity(planpath);
        Page infoPageList = this.page(page, wrapper);
        infoPageList.setRecords(this.viewConversion(infoPageList.getRecords()));
        return infoPageList;
    }
}
