package com.jwipc.spe.controller;

import com.jwipc.page.PageView;
import com.jwipc.spe.dto.AppraiseRectifiedNoticeExamineSaveDTO;
import com.jwipc.spe.dto.AppraiseRectifiedNoticeSaveDTO;
import com.jwipc.spe.dto.AppraiseRectifiedNoticeUpdateDTO;
import com.jwipc.spe.logic.RectifiedNoticeLogic;
import com.jwipc.spe.logic.SupAppraisePlanLogic;
import com.jwipc.spe.model.query.AppraiseRectifiedNoticeQuery;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import static com.jwipc.spe.constant.ModuleConst.MODULE_ROOT;

/**
 * <p> </p>
 *
 * @author ZhangJie
 * @version 1.0
 * @since JDK 1.8
 */
@RestController
@RequestMapping(MODULE_ROOT + "/rectifiedNotice/rest")
@RequiredArgsConstructor
public class RectifiedNoticeRestController {
    private final RectifiedNoticeLogic rectifiedNoticeLogic;
    private final SupAppraisePlanLogic supAppraisePlanLogic;

    /**
     * 考核管理中保存整改通知单整改信息
     *
     * @return 结果
     */
    @PostMapping("saveNotice")
    public ResponseEntity saveNotice(@RequestBody AppraiseRectifiedNoticeSaveDTO saveDTO)
    {
        rectifiedNoticeLogic.submitRectification(saveDTO);
        return ResponseEntity.ok().build();
    }

    /**
     * 考核管理中保存整改通知单整改信息
     *
     * @return 结果
     */
    @PostMapping("updateNotice")
    public ResponseEntity updateNotice(@RequestBody AppraiseRectifiedNoticeSaveDTO saveDTO)
    {
        rectifiedNoticeLogic.updateNotice(saveDTO);
        return ResponseEntity.ok().build();
    }

    /**
     * 批量提交整改
     *
     * @param ids 考核计划供应商明细id
     * @return
     */
    @PostMapping("saveBatchNotice")
    public ResponseEntity saveBatchNotice(String ids, Long id) {
        rectifiedNoticeLogic.saveBatchNotice(ids, id);
        return ResponseEntity.ok().build();
    }

    /**
     * 通知单列表数据(供应商查看)
     *
     * @param query 查询条件
     * @return 结果
     */
    @GetMapping("list")
    public PageView list(AppraiseRectifiedNoticeQuery query) {
        return rectifiedNoticeLogic.getList(query);
    }

    /**
     * 通知单待确认数据列表
     *
     * @param query 查询条件
     * @return 结果
     */
    @GetMapping("confirmList")
    public PageView confirmList(AppraiseRectifiedNoticeQuery query) {
        return rectifiedNoticeLogic.getConfirmList(query);
    }

    /**
     * 通知单待确认数据列表
     *
     * @param query 查询条件
     * @return 结果
     */
    @GetMapping("closeList")
    public PageView closeList(AppraiseRectifiedNoticeQuery query) {
        return rectifiedNoticeLogic.getConfirmList(query);
    }

    @GetMapping("allList")
    public PageView allList(AppraiseRectifiedNoticeQuery query) {
        return rectifiedNoticeLogic.getAllList(query);
    }


    /**
     * 通知单整改项数据
     *
     * @param noticeId 整改通知单id
     * @return 结果
     */
    @GetMapping("/measuresList")
    public PageView measuresList(Long noticeId) {
        return rectifiedNoticeLogic.getMeasuresList(noticeId);
    }

    /**
     * 通知单审核日志数据
     *
     * @param noticeId 整改通知单id
     * @return 结果
     */
    @GetMapping("/examineLogList")
    public PageView examineLogList(Long noticeId) {
        return rectifiedNoticeLogic.getExamineLogList(noticeId);
    }

    /**
     * 考核管理中保存整改通知单整改信息
     *
     * @return 结果
     */
    @PostMapping("updateRectification")
    public ResponseEntity updateRectification(@RequestBody AppraiseRectifiedNoticeUpdateDTO saveDTO)
    {
        rectifiedNoticeLogic.updateRectification(saveDTO);
        return ResponseEntity.ok().build();
    }

    @PostMapping("updateRectification1")
    public ResponseEntity updateRectification1(@RequestBody AppraiseRectifiedNoticeUpdateDTO saveDTO)
    {
        rectifiedNoticeLogic.updateRectification1(saveDTO);
        return ResponseEntity.ok().build();
    }

    /**
     * 整改提交
     *
     * @param noticeId 整改通知单id
     * @return
     */
    @PostMapping("submitRectified")
    public ResponseEntity submitRectified(Long noticeId) {
        rectifiedNoticeLogic.submitRectified(noticeId);
        return ResponseEntity.ok().build();
    }

    /**
     * 整改提交
     *
     * @param noticeId 整改通知单id
     * @return
     */
    @PostMapping("submitConfirm")
    public ResponseEntity submitConfirm(Long noticeId, String examineView, Integer passFlag) {
        rectifiedNoticeLogic.submitConfirm(noticeId, examineView, passFlag);
        return ResponseEntity.ok().build();
    }

    /**
     * 整改审批和跟踪提交
     *
     * @param saveDTO 提交的数据
     * @return
     */
    @PostMapping("submitExamine")
    public ResponseEntity submitExamine(@RequestBody AppraiseRectifiedNoticeExamineSaveDTO saveDTO) {
        rectifiedNoticeLogic.submitExamine(saveDTO);
        return ResponseEntity.ok().build();
    }

    @GetMapping("rectifiedSupplierList")
    public PageView rectifiedSupplierList(Long planId) {
        return supAppraisePlanLogic.rectifiedSupplierList(planId);
    }
}
