/*
 * 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.PlanpointDto;
import com.tofly.pojo.plan.vo.PlanpointVo;
import com.tofly.gpsboot.mapper.plan.PlanpointMapper;
import com.tofly.pojo.plan.Planpoint;
import com.tofly.gpsboot.service.daily.PlanpointService;
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_PLANPOINT_W
 *
 * @author admin
 * @date Thu Mar 18 00:00:00 CST 2021
 */
@Service("planpointService")
public class PlanpointServiceImpl extends ServiceImpl<PlanpointMapper, Planpoint> implements PlanpointService {

    @Autowired
    private UserClent userClent;

    @Override
    public List<PlanpointVo> viewConversion(List<Planpoint> infoList) {
        List<PlanpointVo> infoVoList = new ArrayList<>();
        infoList.forEach(info -> {
            PlanpointVo baseInfoVo = JSON.parseObject(JSON.toJSONString(info), PlanpointVo.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<PlanpointVo> getPlanPointPage(Page page, PlanpointDto parDto) {
        Planpoint planpoint = JSON.parseObject(JSON.toJSONString(parDto),Planpoint.class);
        QueryWrapper<Planpoint> wrapper = new QueryWrapper();
        String name = parDto.getName();
        /*if(!StringUtils.isEmpty(name)){
            wrapper.like("NAME",name);
        }*/
        wrapper.setEntity(planpoint);
        wrapper.orderByDesc("CREATE_TIME");
        Page infoPageList = this.page(page, wrapper);
        infoPageList.setRecords(this.viewConversion(infoPageList.getRecords()));
        return infoPageList;
    }
}
