package com.jwipc.spe.controller;

import com.jwipc.security.LoginUtil;
import com.jwipc.security.dto.CurrentUserDTO;
import com.jwipc.spe.dto.QmNoticeOrderDTO;
import com.jwipc.spe.dto.QmRectifiedMeasuresDTO;
import com.jwipc.spe.logic.QmNoticeOrderLogic;
import com.jwipc.spe.logic.QmRectifiedMeasuresLogic;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

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

/**
 * @author Al
 * @create 2024-02-28 15:36
 * 考核指标
 */
@Controller
@RequestMapping(MODULE_ROOT + "/supQualityManage/qualityHandle")
@RequiredArgsConstructor
public class SupQmNoticeOrderPageController {
    private final QmNoticeOrderLogic qmNoticeOrderLogic;
    private final QmRectifiedMeasuresLogic qmRectifiedMeasuresLogic;
    //private final OrgLogic orgLogic;
    //主页面
    @GetMapping("/index")
    public String index() {
        return MODULE_ROOT + "/supQualityManage/qualityHandle/list";
    }
    @GetMapping("/indexEnd")
    public String indexEnd() {
        return MODULE_ROOT + "/supQualityManage/qualityHandle/handle";
    }
    //新增详情页
    @GetMapping("/detail")
    public String detail(Model model, Long id) {
        CurrentUserDTO user = LoginUtil.getCurrentUser();
        model.addAttribute("loginName",user.getLoginName());
        if (null!=user.getDeptCode()){
        model.addAttribute("orgName",user.getDeptName());
        }
        QmNoticeOrderDTO qmNoticeOrder;
        qmNoticeOrder = qmNoticeOrderLogic.getById(id);
        model.addAttribute("qmNoticeOrder", qmNoticeOrder);
        return MODULE_ROOT + "/supQualityManage/qualityHandle/detail";
    }
    /**
     * 质量整改审批视图
     */
    @RequestMapping("lookNew")
    public String lookNew(Model model, Long id) {
        QmNoticeOrderDTO qmNoticeOrder = new QmNoticeOrderDTO();
        qmNoticeOrder.setId(id);
        QmNoticeOrderDTO supplierQmNoticeOrder = qmNoticeOrderLogic.getById(id);
        model.addAttribute("qmNoticeOrder", supplierQmNoticeOrder);
        QmRectifiedMeasuresDTO qmRectifiedMeasuresDTO = qmRectifiedMeasuresLogic.getByNoticeOrderId(id);
        model.addAttribute("qmRectifiedMeasuresDTO", qmRectifiedMeasuresDTO);
        CurrentUserDTO user = LoginUtil.getCurrentUser();
        //supplierQmNoticeOrder.setDataType("data_type", 1);
        supplierQmNoticeOrder.setId(id);
        return MODULE_ROOT + "/supQualityManage/qualityHandle/look";
    }
    /**
     * 质量整改确认视图
     */
    @RequestMapping("confirm")
    public String confirmUI(Model model, Long id) {
        QmNoticeOrderDTO qmNoticeOrder = new QmNoticeOrderDTO();
        qmNoticeOrder.setId(id);
        QmNoticeOrderDTO supplierQmNoticeOrder = qmNoticeOrderLogic.getById(id);
        model.addAttribute("qmNoticeOrder", supplierQmNoticeOrder);
        QmRectifiedMeasuresDTO qmRectifiedMeasuresDTO = qmRectifiedMeasuresLogic.getByNoticeOrderId(id);
        model.addAttribute("qmRectifiedMeasuresDTO", qmRectifiedMeasuresDTO);
        CurrentUserDTO user = LoginUtil.getCurrentUser();
        //supplierQmNoticeOrder.setDataType("data_type", 1);
        supplierQmNoticeOrder.setId(id);
        return MODULE_ROOT + "/supQualityManage/qualityHandle/confirm";
    }

    /**
     * 质量整改改善视图
     */
    @RequestMapping("improve")
    public String improveUI(Model model, Long id) {
        final CurrentUserDTO user = LoginUtil.getCurrentUser();
        //Supplier supplier = supplierDataService.findBySupplierCode(user.getLoginName());
        //是否外包

        //model.addAttribute("isexternal", supplier.getIsexternal());
        QmNoticeOrderDTO qmNoticeOrder = new QmNoticeOrderDTO();
        qmNoticeOrder.setId(id);
        QmNoticeOrderDTO qmNoticeOrderDTO = qmNoticeOrderLogic.getById(id);
        model.addAttribute("qmNoticeOrderDTO", qmNoticeOrderDTO);
        //qmNoticeOrderDTO.put("data_type", 1);
        qmNoticeOrderDTO.setId(id);
        return MODULE_ROOT + "/supQualityManage/qualityHandle/improve";
    }

    @GetMapping("/look")
    public String look(Model model, Long id) {
        CurrentUserDTO user = LoginUtil.getCurrentUser();
        model.addAttribute("loginName",user.getLoginName());
        if (null!=user.getDeptCode()){
            model.addAttribute("orgName",user.getDeptName());
        }
        QmNoticeOrderDTO qmNoticeOrder;
        qmNoticeOrder = qmNoticeOrderLogic.getById(id);
        model.addAttribute("qmNoticeOrder", qmNoticeOrder);
//        Supplier supplier = supplierService.getById(id);
//        model.addAttribute("isexternal", supplier.getIsExternal());
        return MODULE_ROOT + "/qualityManage/launchedQualityManage/look";
    }
}
