package com.bonus.material.scrap.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import cn.hutool.core.convert.Convert;
import com.bonus.common.biz.config.ListPagingUtil;
import com.bonus.common.core.utils.ServletUtils;
import com.bonus.common.log.enums.OperaType;
import com.bonus.material.common.annotation.PreventRepeatSubmit;
import com.bonus.material.scrap.domain.vo.ScrapDetailsListVo;
import com.bonus.material.scrap.domain.vo.ScrapTaskListVo;
import com.bonus.material.scrap.domain.vo.ScrapTotalListVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.bonus.common.log.annotation.SysLog;
import com.bonus.common.security.annotation.RequiresPermissions;
import com.bonus.material.scrap.domain.ScrapApplyDetails;
import com.bonus.material.scrap.service.IScrapApplyDetailsService;
import com.bonus.common.core.web.controller.BaseController;
import com.bonus.common.core.web.domain.AjaxResult;
import com.bonus.common.core.utils.poi.ExcelUtil;

/**
 * 报废任务详细Controller
 * 
 * @author xsheng
 * @date 2024-10-16
 */
@Api(tags = "报废任务详细接口")
@RestController
@RequestMapping("/scrap_apply_details")
public class ScrapApplyDetailsController extends BaseController {

    @Autowired
    private IScrapApplyDetailsService scrapApplyDetailsService;

    /**
     * 查询报废任务详细列表
     */
    @ApiOperation(value = "查询报废任务列表")
//    @RequiresPermissions("scrap:details:list")
    @GetMapping("/list")
    public AjaxResult list(ScrapApplyDetails scrapApplyDetails) {
        Integer pageIndex = Convert.toInt(ServletUtils.getParameter("pageNum"), 1);
        Integer pageSize = Convert.toInt(ServletUtils.getParameter("pageSize"), 10);
        List<ScrapTaskListVo> list = scrapApplyDetailsService.selectScrapApplyDetailsList(scrapApplyDetails);
        return AjaxResult.success(ListPagingUtil.paging(pageIndex, pageSize, list));
    }



    /**
     * 查询盘点报废任务列表
     * @param scrapApplyDetails
     * @return
     */
    @ApiOperation(value = "查询盘点报废任务列表")
//    @RequiresPermissions("scrap:details:list")
    @GetMapping("/inventoryList")
    public AjaxResult inventoryList(ScrapApplyDetails scrapApplyDetails) {
        Integer pageIndex = Convert.toInt(ServletUtils.getParameter("pageNum"), 1);
        Integer pageSize = Convert.toInt(ServletUtils.getParameter("pageSize"), 10);
        List<ScrapTaskListVo> list = scrapApplyDetailsService.selectInventoryList(scrapApplyDetails);
        return AjaxResult.success(ListPagingUtil.paging(pageIndex, pageSize, list));
    }

    /**
     * 查询盘点报废任务详情
     * @param scrapApplyDetails
     * @return
     */
    @ApiOperation(value = "查询盘点报废任务详情")
//    @RequiresPermissions("scrap:details:list")
    @GetMapping("/getDetailsList")
    public AjaxResult getDetailsList(ScrapApplyDetails scrapApplyDetails) {
        ScrapApplyDetails details = scrapApplyDetailsService.getDetailsList(scrapApplyDetails);
        return AjaxResult.success(details);
    }

    @ApiOperation(value = "导出盘点报废任务详情")
    @PreventRepeatSubmit
    //@RequiresPermissions("lease:info:export")
    @SysLog(title = "盘点报废", businessType = OperaType.EXPORT, logType = 1,module = "仓储管理->导出盘点报废任务详情")
    @PostMapping("/exportDetails")
    public void exportDetails(HttpServletResponse response, ScrapApplyDetails scrapApplyDetails) {
        ScrapApplyDetails details = scrapApplyDetailsService.getDetailsList(scrapApplyDetails);
        List<ScrapApplyDetails> scrapApplyDetailsList = details.getScrapApplyDetailsList();
        ExcelUtil<ScrapApplyDetails> util = new ExcelUtil<ScrapApplyDetails>(ScrapApplyDetails.class);
        util.exportExcel(response, scrapApplyDetailsList, "盘点报废任务详情");
    }


    /**
     * 新增盘点报废
     * @param scrapApplyDetails
     * @return
     */
    @ApiOperation(value = "新增盘点报废")
    @PostMapping("/addList")
    public AjaxResult savePutInfo(@RequestBody ScrapApplyDetails scrapApplyDetails) {
        return scrapApplyDetailsService.savePutInfo(scrapApplyDetails);
    }

    /**
     * 修改盘点报废
     * @param scrapApplyDetails
     * @return
     */
    @ApiOperation(value = "修改盘点报废")
    @PostMapping("/updateList")
    public AjaxResult updateList(@RequestBody ScrapApplyDetails scrapApplyDetails) {
        return scrapApplyDetailsService.updateList(scrapApplyDetails);
    }

    /**
     * 删除盘点报废
     * @param scrapApplyDetails
     * @return
     */
    @ApiOperation(value = "删除盘点报废")
    @PostMapping("/delete")
    public AjaxResult delete(@RequestBody ScrapApplyDetails scrapApplyDetails) {
        return scrapApplyDetailsService.delete(scrapApplyDetails);
    }

    /**
     * 查询报废台账任务列表
     * @param scrapApplyDetails
     * @return
     */
    @ApiOperation(value = "查询报废台账任务列表")
//    @RequiresPermissions("scrap:details:list")
    @GetMapping("/getTotalList")
    public AjaxResult getTotalList(ScrapApplyDetails scrapApplyDetails) {
        Integer pageIndex = Convert.toInt(ServletUtils.getParameter("pageNum"), 1);
        Integer pageSize = Convert.toInt(ServletUtils.getParameter("pageSize"), 10);
        List<ScrapTotalListVo> list = scrapApplyDetailsService.selectTotalScrapApplyDetailsList(scrapApplyDetails);
        return AjaxResult.success(ListPagingUtil.paging(pageIndex, pageSize, list));
    }

    /**
     * 查询报废台账列表
     * @param scrapApplyDetails
     * @return
     */
    @ApiOperation(value = "查询报废台账列表")
//    @RequiresPermissions("scrap:details:list")
    @GetMapping("/getScrapList")
    public AjaxResult getScrapList(ScrapApplyDetails scrapApplyDetails) {
        Integer pageIndex = Convert.toInt(ServletUtils.getParameter("pageNum"), 1);
        Integer pageSize = Convert.toInt(ServletUtils.getParameter("pageSize"), 10);
        List<ScrapTotalListVo> list = scrapApplyDetailsService.getScrapList(scrapApplyDetails);
        return AjaxResult.success(ListPagingUtil.paging(pageIndex, pageSize, list));
    }

    /**
     * 导出报废台账列表
     * @param response
     * @param scrapApplyDetails
     */
    @ApiOperation(value = "导出报废台账列表")
    //@RequiresPermissions("scrap:details:export")
    @PostMapping("/exportScrapList")
    public void exportScrapList(HttpServletResponse response, ScrapApplyDetails scrapApplyDetails) {
        List<ScrapTotalListVo> list = scrapApplyDetailsService.getScrapList(scrapApplyDetails);
        ExcelUtil<ScrapTotalListVo> util = new ExcelUtil<>(ScrapTotalListVo.class);
        util.exportExcel(response, list, "报废台账任务数据");
    }

    /**
     * 查询报废台账明细列表
     * @param scrapApplyDetails
     * @return
     */
    @ApiOperation(value = "查询报废台账明细列表")
//    @RequiresPermissions("scrap:details:list")
    @GetMapping("/getScrapDetailsList")
    public AjaxResult getScrapDetailsList(ScrapApplyDetails scrapApplyDetails) {
        Integer pageIndex = Convert.toInt(ServletUtils.getParameter("pageNum"), 1);
        Integer pageSize = Convert.toInt(ServletUtils.getParameter("pageSize"), 10);
        List<ScrapDetailsListVo> list = scrapApplyDetailsService.getScrapDetailsList(scrapApplyDetails);
        return AjaxResult.success(ListPagingUtil.paging(pageIndex, pageSize, list));
    }

    /**
     * 导出报废台账列表
     * @param response
     * @param scrapApplyDetails
     */
    @ApiOperation(value = "导出报废台账明细列表")
    //@RequiresPermissions("scrap:details:export")
    @PostMapping("/exportScrapDetailsList")
    public void exportScrapDetailsList(HttpServletResponse response, ScrapApplyDetails scrapApplyDetails) {
        List<ScrapDetailsListVo> list = scrapApplyDetailsService.getScrapDetailsList(scrapApplyDetails);
        ExcelUtil<ScrapDetailsListVo> util = new ExcelUtil<>(ScrapDetailsListVo.class);
        util.exportExcel(response, list, "报废台账明细数据");
    }

    /**
     * 查询报废台账审核总费用
     * @param scrapApplyDetails
     * @return
     */
    @ApiOperation(value = "查询报废台账审核总费用")
//    @RequiresPermissions("scrap:details:list")
    @GetMapping("/getTotalPrice")
    public AjaxResult getTotalPrice(ScrapApplyDetails scrapApplyDetails) {
        ScrapTotalListVo list = scrapApplyDetailsService.getTotalPrice(scrapApplyDetails);
        return AjaxResult.success(list);
    }

    /**
     * 查询报废任务详细列表--根据任务ID
     */
    @ApiOperation(value = "查询报废任务详情--TaskId")
    @GetMapping("/selectRepairQuestListByTaskId")
    public AjaxResult selectRepairQuestListByTaskId(ScrapApplyDetails scrapApplyDetails) {
        List<ScrapApplyDetails> list = scrapApplyDetailsService.selectRepairQuestListByTaskId(scrapApplyDetails);
        return success(list);
    }

    /**
     * 导出报废任务详细列表
     */
    @ApiOperation(value = "导出报废任务详细列表")
    @PreventRepeatSubmit
    //@RequiresPermissions("scrap:details:export")
    @SysLog(title = "报废任务详细", businessType = OperaType.EXPORT, logType = 1,module = "仓储管理->导出报废任务详细")
    @PostMapping("/export")
    public void export(HttpServletResponse response, ScrapApplyDetails scrapApplyDetails) {
        List<ScrapTaskListVo> list = scrapApplyDetailsService.selectScrapApplyDetailsList(scrapApplyDetails);
        ExcelUtil<ScrapTaskListVo> util = new ExcelUtil<>(ScrapTaskListVo.class);
        util.exportExcel(response, list, "报废任务详细数据");
    }

    /**
     * 报废审核通过
     * @param scrapApplyDetails
     * @return
     */
    @ApiOperation(value = "报废审核通过")
    @PostMapping("/approve")
    public AjaxResult approve(@RequestBody ScrapApplyDetails scrapApplyDetails) {
        return scrapApplyDetailsService.approve(scrapApplyDetails);
    }

    /**
     * 盘点报废审核
     * @param scrapApplyDetails
     * @return
     */
    @ApiOperation(value = "盘点报废审核")
    @PostMapping("/inventoryApprove")
    public AjaxResult inventoryApprove(@RequestBody ScrapApplyDetails scrapApplyDetails) {
        return scrapApplyDetailsService.inventoryApprove(scrapApplyDetails);
    }

    /**
     * 报废台账审核通过
     * @param scrapApplyDetails
     * @return
     */
    @ApiOperation(value = "报废台账审核通过")
    @PostMapping("/ledgerApprove")
    public AjaxResult ledgerApprove(@RequestBody ScrapApplyDetails scrapApplyDetails) {
        return scrapApplyDetailsService.ledgerApprove(scrapApplyDetails);
    }

    /**
     * 报废审核驳回
     * @param scrapApplyDetails
     * @return
     */
    @ApiOperation(value = "报废审核驳回")
    @PostMapping("/reject")
    public AjaxResult reject(@RequestBody ScrapApplyDetails scrapApplyDetails) {
        return scrapApplyDetailsService.reject(scrapApplyDetails);
    }

    /**
     * 报废台账审核驳回
     * @param scrapApplyDetails
     * @return
     */
    @ApiOperation(value = "报废台账审核驳回")
    @PostMapping("/ledgerReject")
    public AjaxResult ledgerReject(@RequestBody ScrapApplyDetails scrapApplyDetails) {
        return scrapApplyDetailsService.ledgerReject(scrapApplyDetails);
    }

    /**
     * 获取报废任务详细详细信息
     */
    @ApiOperation(value = "获取报废任务详细详细信息")
    @RequiresPermissions("scrap:details:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(scrapApplyDetailsService.selectScrapApplyDetailsById(id));
    }

    /**
     * 新增报废任务详细
     */
    @ApiOperation(value = "新增报废任务详细")
    @PreventRepeatSubmit
    @RequiresPermissions("scrap:details:add")
    @SysLog(title = "报废任务详细", businessType = OperaType.INSERT, logType = 1,module = "仓储管理->新增报废任务详细")
    @PostMapping
    public AjaxResult add(@RequestBody ScrapApplyDetails scrapApplyDetails) {
        try {
            return toAjax(scrapApplyDetailsService.insertScrapApplyDetails(scrapApplyDetails));
        } catch (Exception e) {
            return error("系统错误, " + e.getMessage());
        }
    }

    /**
     * 修改报废任务详细
     */
    @ApiOperation(value = "修改报废任务详细")
    @PreventRepeatSubmit
    @RequiresPermissions("scrap:details:edit")
    @SysLog(title = "报废任务详细", businessType = OperaType.UPDATE, logType = 1,module = "仓储管理->修改报废任务详细")
    @PutMapping
    public AjaxResult edit(@RequestBody ScrapApplyDetails scrapApplyDetails) {
        try {
            return toAjax(scrapApplyDetailsService.updateScrapApplyDetails(scrapApplyDetails));
        } catch (Exception e) {
            return error("系统错误, " + e.getMessage());
        }
    }

    /**
     * 删除报废任务详细
     */
    @ApiOperation(value = "删除报废任务详细")
    @PreventRepeatSubmit
    @RequiresPermissions("scrap:details:remove")
    @SysLog(title = "报废任务详细", businessType = OperaType.DELETE, logType = 1,module = "仓储管理->删除报废任务详细")
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(scrapApplyDetailsService.deleteScrapApplyDetailsByIds(ids));
    }
}
