package com.jwipc.finance.controller;


import com.jwipc.finance.dto.DeductionDTO;
import com.jwipc.finance.logic.DeductionLogic;
import com.jwipc.log.annotation.AuditLogInter;
import com.jwipc.security.LoginUtil;
import com.jwipc.sys.client.UserPurchaseGroupClient;
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.finance.constant.ModuleConst.MODULE_ROOT;

/**
 * @author Al
 * @create 2024-02-20 15:26
 * 对账-扣款管理页面
 */
@Controller
@RequestMapping(MODULE_ROOT + "/deduction")
@RequiredArgsConstructor
public class DeductionPageController {
    private final DeductionLogic deductionLogic;
    private final UserPurchaseGroupClient userPurchaseGroupClient;
    @GetMapping("/index")
    public String index() {
        return MODULE_ROOT + "/deduction/list";
    }
    @GetMapping("/detail")
    public String detail(Model model, Long id, Long flag) {
        DeductionDTO deduction;
        deduction = deductionLogic.getById(id);
        if(flag == 0 || flag == 3){
            deduction.setCompanyCode("1000");
            deduction.setFactory("1400");
            deduction.setPurchaseOrg("8000");
            //默认采购组
            deduction.setPurchaseGroup(userPurchaseGroupClient.getMarkPurchaseGroupCodeByUserId(LoginUtil.getUserId()));
        }
        if(flag == 3){
            deduction.setDeductionExecutionProcurement(LoginUtil.getUserId());
            deduction.setDeductionExecutionProcurementName(LoginUtil.getName());
        }
        model.addAttribute("deduction", deduction);
        model.addAttribute("flag", flag);
        return MODULE_ROOT + "/deduction/detail";
    }
    @GetMapping("/deductionConfirm/index")
    public String confirmIndex() {
        return MODULE_ROOT + "/deduction/deductionConfirm/list";
    }

    @AuditLogInter(value = "详情页", module = "扣款单确认")
    @GetMapping("/deductionConfirm/detail")
    public String confirmDetail(Model model, Long id,Long flag) {
        DeductionDTO deduction;
        deduction = deductionLogic.getById(id);
        model.addAttribute("deduction", deduction);
        model.addAttribute("flag", flag);
        return MODULE_ROOT + "/deduction/deductionConfirm/detail";
    }

    @GetMapping("/supplierDeductionConfirm/index")
    public String supConfirmIndex() {
        return MODULE_ROOT + "/deduction/supplierDeductionConfirm/list";
    }
    @GetMapping("/supplierDeductionConfirm/detail")
    public String supConfirmDetail(Model model, Long id,Long flag) {
        DeductionDTO deduction;
        deduction = deductionLogic.getById(id);
        model.addAttribute("deduction", deduction);
        model.addAttribute("flag", flag);
        return MODULE_ROOT + "/deduction/supplierDeductionConfirm/detail";
    }
}
