package com.tuoheng.miniprogram.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.tuoheng.common.core.utils.DateUtils;
import com.tuoheng.common.core.utils.JsonResult;
import com.tuoheng.common.core.utils.StringUtils;
import com.tuoheng.miniprogram.dao.InspectionFileHandleMapper;
import com.tuoheng.miniprogram.dao.InspectionFileMapper;
import com.tuoheng.miniprogram.entity.InspectionFileHandle;
import com.tuoheng.miniprogram.entity.dto.UploadResultDto;
import com.tuoheng.miniprogram.service.IInspectionFileHandleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Author ChengWang
 * @Date 2022/11/25
 */
@Service
@Slf4j
public class InspectionFileHandleServiceImpl implements IInspectionFileHandleService {

    @Autowired
    private InspectionFileMapper inspectionFileMapper;

    @Autowired
    private InspectionFileHandleMapper inspectionFileHandleMapper;

    /**
     * 上传结果
     * @param dto
     * @return
     */
    @Override
    public JsonResult uploadResult(UploadResultDto dto) {
        if(StringUtils.isEmpty(dto.getId())) {
            return JsonResult.error("问题id为空");
        }
        if(StringUtils.isEmpty(dto.getTenantId())){
            return JsonResult.error("租户id不存在");
        }
        InspectionFileHandle inspectionFileHandle = new InspectionFileHandle();
        inspectionFileHandle.setInspectionFileId(dto.getId());
        inspectionFileHandle.setTenantId(dto.getTenantId());
        inspectionFileHandle.setHandlerImage(dto.getHandlerImage());
        inspectionFileHandle.setHandlerResult(dto.getHandlerResult());
        inspectionFileHandle.setHandlerUser("cw");
        inspectionFileHandle.setCreateUser("cw");
        inspectionFileHandle.setCreateTime(DateUtils.now());
        inspectionFileHandle.setMark(1);
        int count = inspectionFileHandleMapper.insert(inspectionFileHandle);
        if(count<=0){
            return JsonResult.error();
        }

        return JsonResult.success();
    }

}
