package com.hw.dms.controller;

import com.hw.common.core.domain.R;
import com.hw.common.core.web.controller.BaseController;
import com.hw.common.core.web.domain.AjaxResult;
import com.hw.common.log.annotation.Log;
import com.hw.common.log.enums.BusinessType;
import com.hw.dms.domain.DmsBillsFaultInstance;
import com.hw.dms.service.IDmsBillsFaultInstanceService;
import com.hw.system.api.RemoteFileService;
import com.hw.system.api.domain.SysFile;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @Description:手持PDA接口
 * @ProjectName:HwMes
 * @Author:xins
 * @Date:2024-03-13 17:08
 * @Version:1.0
 */
@RestController
@RequestMapping("/mobile")
public class DmsMobileController extends BaseController {
    @Autowired
    private IDmsBillsFaultInstanceService dmsBillsFaultInstanceService;

    @Resource
    private RemoteFileService remoteFileService;


    /**
     * PDA-报修
     *
     * 需传入
     * 设备id          deviceId
     * 故障类别         faultType
     * 故障描述         faultDescription
     * 涉及操作         designOperations
     * 维修类型         repairType
     * 外协id          outsrcId(可不传入)
     * 图片            files
     * */
//    @RequiresPermissions("qms:checkresultdetail:add")
    @Log(title = "故障报修工单", businessType = BusinessType.INSERT)
    @PostMapping("/insertFaultInstsanceActivity")
    public AjaxResult insertFaultInstsanceActivity(DmsBillsFaultInstance dmsBillsFaultInstance,
                                            @RequestParam(value = "files") List<MultipartFile> files) {
        List<String> fileUrls = new ArrayList<>();
        for (MultipartFile file : files) {
            R<SysFile> sysFileR = remoteFileService.upload(file);
            SysFile sysFile = sysFileR.getData();
            fileUrls.add(sysFile.getUrl());
        }
        dmsBillsFaultInstance.setFileUrls(fileUrls);
        return success(dmsBillsFaultInstanceService.insertDmsBillsFaultInstance(dmsBillsFaultInstance));
    }

}
