/*
 * Author: wangjian
 * 生成ServiceImpl
 */
package com.tofly.gpsboot.service.paln.task.impl;

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

import com.tofly.api.UserClent;
import com.tofly.common.oauth.util.SecurityUtils;
import com.tofly.gpsboot.common.system.IsAuditEnum;
import com.tofly.gpsboot.common.system.IsReadEnum;
import com.tofly.gpsboot.common.system.IsSubmitEnum;
import com.tofly.pojo.plan.dto.PlancancleDto;
import com.tofly.pojo.plan.dto.ReportAuditDto;
import com.tofly.pojo.plan.vo.PlancancleVo;
import com.tofly.gpsboot.mapper.plan.PlancancleMapper;
import com.tofly.gpsboot.service.paln.task.PlanService;
import com.tofly.gpsboot.service.paln.task.PlancancleService;
import com.tofly.gpsboot.service.report.IReportPlanDisuseServer;
import com.tofly.pojo.User;
import com.tofly.pojo.plan.Plan;
import com.tofly.pojo.plan.Plancancle;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;


/**
 * 巡检计划作废信息表
 *
 * @author admin
 * @date Thu Mar 25 00:00:00 CST 2021
 */
@Service("plancancleService")
public class PlancancleServiceImpl extends ServiceImpl<PlancancleMapper, Plancancle> implements PlancancleService {

    @Autowired
    private PlanService planService;

    @Autowired
    private IReportPlanDisuseServer iReportPlanDisuseServer;

    @Override
    public Boolean saveInfo(PlancancleDto dto) {
        Plancancle plancancle = JSON.parseObject(JSON.toJSONString(dto), Plancancle.class);
        this.save(plancancle);
        // 自动上报
        ReportAuditDto reportAuditDto = new ReportAuditDto();
        reportAuditDto.setId(plancancle.getId());
        reportAuditDto.setReportId(SecurityUtils.getUserId());
        // 获取当前巡检计划派工人(创建人)
        List<Plan> list = planService.list(new QueryWrapper<Plan>().lambda().eq(Plan::getId, plancancle.getPlanId()));
        if (null != list && list.size() > 0) {
            Long createUser = list.get(0).getCreateUser();
            reportAuditDto.setAuditId(createUser);
        }
        iReportPlanDisuseServer.report(reportAuditDto);
        return true;
    }
}
