package com.jwipc.sys.controller.pc;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.jwipc.sys.dto.AttachmentTypeConfigDTO;
import com.jwipc.sys.entity.AttachmentTypeConfig;
import com.jwipc.sys.logic.AttachmentTypeConfigLogic;
import com.jwipc.sys.service.IAttachmentTypeConfigService;
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 org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

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

/**
 * <p>
 *
 * </p>
 *
 * @author Chen Tianshi
 * @since 2025/9/12 12:06
 */
@Controller
@RequestMapping(MODULE_ROOT + "/businessAttachment/")
@RequiredArgsConstructor
public class BusinessAttachmentPageController {
    private final AttachmentTypeConfigLogic attachmentTypeConfigLogic;

    /**
     * 通用附件上传界面
     * @return 视图
     */
    @GetMapping("fileUploadWithType")
    public String fileUploadWithType(Model model,String businessTypeCode,String businessCode,String businessId) {
        model.addAttribute("businessTypeCode", businessTypeCode);
        model.addAttribute("businessCode", businessCode);
        model.addAttribute("businessId", businessId);
        List<AttachmentTypeConfigDTO> attachmentTypeConfigs = attachmentTypeConfigLogic.listByBusinessTypeCode(businessTypeCode);
        model.addAttribute("attachmentTypeConfigList", attachmentTypeConfigs);
        if (businessTypeCode != null && businessTypeCode.indexOf("contract_payment_") != -1) {
            businessTypeCode = "contract_payment_apply";
            model.addAttribute("businessTypeCode", businessTypeCode);
        }
        return MODULE_ROOT + "/businessAttachment/file_upload_with_type";
    }

    @GetMapping("businessAttachmentDetail")
    public String businessAttachment(@RequestParam String businessId, @RequestParam String businessCode, @RequestParam String businessTypeCode, Model model) {
        model.addAttribute("businessId", businessId);
        model.addAttribute("businessCode", businessCode);
        model.addAttribute("businessTypeCode", businessTypeCode);
        return MODULE_ROOT + "/businessAttachment/business_attachment_detail";
    }

}
