package com.hssx.pcbms.controller;


import com.hssx.pcbms.entity.TaskFile;
import com.hssx.pcbms.service.TaskFileService;
import com.hssx.pcbms.util.HttpRespMsg;
import com.hssx.pcbms.util.PageUtil;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 吴涛涛
 * @since 2019-11-11
 */
@Controller
@RequestMapping("/taskfile")
public class TaskFileController {

    @Value("${upload.path}")
    private String path;
    @Autowired
    private TaskFileService taskFileService;

    /**
     * 图片上传通用接口
     * 参数：
     * file：产品图片文件
     * taskId:任务id,uploaderId:操作人的id
     *
     * @return
     */
    @ApiOperation(value = "任务资料上传通用接口", notes = "任务资料上传通用接口方法")
    @RequestMapping("/uploadFile")
    @ResponseBody
    public HttpRespMsg uploadFile(MultipartFile file, TaskFile taskFile) {
        HttpRespMsg msg = new HttpRespMsg();
        msg = taskFileService.updateFile(file,taskFile);
        return msg;
    }


    /**
     * 任务资料删除
     * 参数：
     * id：任务资料文件id,uploaderId:操作人的id
     *
     * @return
     */
    @ApiOperation(value = "任务资料删除接口", notes = "任务资料删除方法")
    @RequestMapping("/delFile")
    @ResponseBody
    public HttpRespMsg delFile(TaskFile taskFile) {
        HttpRespMsg msg = new HttpRespMsg();
        msg = taskFileService.delById(taskFile);
        return msg;
    }

    /**
     * 资产列表
     * 参数：
     * taskId:任务id,pageNum:当前页，pageSize：每页多少条
     * @return
     */
    @ApiOperation(value = "资产列表", notes = "资产列表方法")
    @RequestMapping("/list")
    @ResponseBody
    public HttpRespMsg list(PageUtil page, String taskId) {
        HttpRespMsg msg = taskFileService.getList(page,taskId);
        return msg;
    }

}

