package org.jeecg.modules.itdmgongdanshuju.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.modules.itdmgongdanshuju.dto.ItdmGongdanDto;
import org.jeecg.modules.itdmgongdanshuju.dto.ItdmGongdanEditListDto;
import org.jeecg.modules.itdmgongdanshuju.dto.ItdmGongdanUploadDto;
import org.jeecg.modules.itdmgongdanshuju.entity.ItdmGongdanShuju;
import org.jeecg.modules.itdmgongdanshuju.service.ItdmGongdanShujuService;
import org.jeecg.modules.weituo.service.IItdmWeituoInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Arrays;
import java.util.List;

/**
 * @Description: 委托信息
 * @Author: jeecg-boot
 * @Date: 2023-05-17
 * @Version: V1.011
 */
@Api(tags = "工单数据11")
@RestController
@RequestMapping("/itdmgomgongdanshuju/ItdmGongdanshuju")
@Slf4j
public class ItdmGongdanshujuController {

    @Autowired
    private ItdmGongdanShujuService itdmGongdanShujuService;
    @Autowired
    private IItdmWeituoInfoService itdmWeituoInfoService;

    @ApiOperation(value = "获取委托数据", notes = "获取委托数据")
    @GetMapping("/getWeiTuoData")
    public Result getWeiTuoData() {

        return Result.OK(itdmWeituoInfoService.selectItdmWeituoYangpinCompany());

    }


    @ApiOperation(value = "工单数据-列表", notes = "工单数据-列表")
    @GetMapping("/list")
    public Result<List<ItdmGongdanShuju>> list(ItdmGongdanShuju itdmGongdanShuju, HttpServletRequest req) {
        QueryWrapper<ItdmGongdanShuju> queryWrapper = QueryGenerator.initQueryWrapper(itdmGongdanShuju, req.getParameterMap());
        queryWrapper.orderByAsc("shiyan_date_time","shiyan_time");
        List<ItdmGongdanShuju> list = itdmGongdanShujuService.list(queryWrapper);
        return Result.OK(list);
    }


    @ApiOperation(value = "工单数据-生成", notes = "工单数据-生成")
    @PostMapping("/create")
    public Result create(@RequestBody ItdmGongdanDto itdmGongdanDto, HttpServletRequest req) {

        Boolean b = itdmGongdanShujuService.generate(itdmGongdanDto);
        if (b) {
            return Result.OK();
        }
        return Result.error("数据生成失败");
    }


    @ApiOperation(value = "工单数据-修改", notes = "工单数据-修改")
    @GetMapping("/update")
    public ItdmGongdanShuju update(@RequestBody ItdmGongdanShuju itdmGongdanShuju, HttpServletRequest req) {
        itdmGongdanShujuService.updateById(itdmGongdanShuju);
        return itdmGongdanShuju;
    }

    @AutoLog(value = "工单数据-批量删除")
    @ApiOperation(value = "工单数据-批量删除", notes = "工单数据-批量删除")
    //@RequiresPermissions("org.jeecg.modules:itdm_gongdan_shuju:deleteBatch")
    @DeleteMapping(value = "/deleteBatch")
    public Result<String> deleteBatch(@RequestParam(name = "ids", required = true) String ids) {
        this.itdmGongdanShujuService.removeByIds(Arrays.asList(ids.split(",")));
        return Result.OK("批量删除成功!");
    }

    @AutoLog(value = "工单数据-编辑")
    @ApiOperation(value = "工单数据-编辑", notes = "工单数据-编辑")
    //@RequiresPermissions("org.jeecg.modules:itdm_gongdan_shuju:edit")
    @RequestMapping(value = "/edit", method = {RequestMethod.PUT, RequestMethod.POST})
    public Result<String> edit(@RequestBody ItdmGongdanShuju itdmGongdanShuju) {
        itdmGongdanShujuService.updateById(itdmGongdanShuju);
        return Result.OK("编辑成功!");
    }


    @AutoLog(value = "工单数据-上传")
    @ApiOperation(value = "工单数据-上传", notes = "工单数据-上传")
    //@RequiresPermissions("org.jeecg.modules:itdm_gongdan_shuju:edit")
    @RequestMapping(value = "/upload", method = {RequestMethod.PUT, RequestMethod.POST})
    public Result<String> upload(@RequestBody ItdmGongdanUploadDto itdmGongdanShuju) {
        itdmGongdanShujuService.upload(itdmGongdanShuju);
        return Result.OK("上传文件!");
    }


    @AutoLog(value = "工单数据-编辑")
    @ApiOperation(value = "工单数据-批量编辑", notes = "工单数据-批量编辑")
    //@RequiresPermissions("org.jeecg.modules:itdm_gongdan_shuju:edit")
    @RequestMapping(value = "/editList", method = {RequestMethod.PUT, RequestMethod.POST})
    public Result<String> editList(@RequestBody ItdmGongdanEditListDto dto) {
        itdmGongdanShujuService.editList(dto);
        return Result.OK("编辑成功!");
    }




    @ApiOperation(value = "工单数据-查询图片", notes = "工单数据-查询图片")
    //@RequiresPermissions("org.jeecg.modules:itdm_gongdan_shuju:edit")
    @RequestMapping(value = "/getUpdate", method = {RequestMethod.GET})
    public Result<String> getUpdate(String weituoId) {

        return Result.OK(itdmGongdanShujuService.getUpdate(weituoId));
    }


}
