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

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

import com.tofly.common.oauth.util.SecurityUtils;
import com.tofly.pojo.plan.vo.InspectgroupVo;
import com.tofly.gpsboot.mapper.plan.InspectgroupMapper;
import com.tofly.gpsboot.service.paln.GroupuserService;
import com.tofly.pojo.plan.Groupuser;
import com.tofly.pojo.plan.Inspectgroup;
import com.tofly.gpsboot.service.config.InspectgroupService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


/**
 * 巡查分组信息表：TF_YWPN_INSPECTGROUP_W
 *
 * @author admin
 * @date Thu Mar 18 00:00:00 CST 2021
 */
@Service("inspectgroupService")
public class InspectgroupServiceImpl extends ServiceImpl<InspectgroupMapper, Inspectgroup> implements InspectgroupService {

    @Autowired
    private GroupuserService groupuserService;

    @Override
    public List<InspectgroupVo> viewConversion(List<Inspectgroup> infoList) {
        // 无转换类型
        return JSONArray.parseArray(JSON.toJSONString(infoList), InspectgroupVo.class);
    }

    @Override
    public List<Inspectgroup> getInspectGroupInfo() {
        List<Groupuser> list = groupuserService.list(new QueryWrapper<Groupuser>().lambda().eq(Groupuser::getUserId, SecurityUtils.getUserId()));
        if(null != list && list.size()>0){
            String groupId = list.get(0).getGroupId();
            return this.list(new QueryWrapper<Inspectgroup>().lambda().eq(Inspectgroup::getId,groupId));
        }else {
            return this.list();
        }

    }
}
