package com.jwipc.shopping.controller.pc;

import com.jwipc.log.annotation.AuditLogInter;
import com.jwipc.security.LoginUtil;
import com.jwipc.shopping.constant.ModuleConst;
import com.jwipc.shopping.dto.ShoppingPayDTO;
import com.jwipc.shopping.logic.ShoppingPayLogic;
import com.jwipc.sys.client.SequenceClient;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * @Author: swq
 * @Date: 2024/4/10 10:30
 */
@Controller
@RequestMapping(ModuleConst.MODULE_ROOT + "/shoppingPay/page")
@RequiredArgsConstructor
@Slf4j
public class ShoppingPayPageController {
    @Autowired
    SequenceClient sequenceClient;
    @Autowired
    ShoppingPayLogic shoppingPayLogic;
    /**
     * 商城付款列表页面
     *
     * @return 页面
     */
    @RequestMapping("/index")
    public String index(Model model){
        return ModuleConst.MODULE_ROOT + "/shoppingPay/index";
    }
    /**
     * 商城付款新增修改页面
     *
     * @return 页面
     */
    @AuditLogInter(value = "新增/编辑页面", module = "商城付款")
    @RequestMapping("/formDeatil")
    public String formDeatil( Model model, String id,Integer check) {
        ShoppingPayDTO bean = shoppingPayLogic.formShoppingPay(id) ;
        if(StringUtils.isEmpty(bean)){
            bean = new ShoppingPayDTO();
        }
        if(StringUtils.isEmpty(id)){
            String code = sequenceClient.createSequenceNo("mall_apply_pay_code");
            bean.setPayCode(code);
        }
//        bean.setCreateUserName(LoginUtil.getName());
        model.addAttribute("bean", bean);
        model.addAttribute("userName", LoginUtil.getCurrentUser().getName());
        model.addAttribute("userAccount", LoginUtil.getAccount());
        model.addAttribute("check", check);
        model.addAttribute("belongDeptNameH", "申请部门");
        return ModuleConst.MODULE_ROOT + "/shoppingPay/form";
    }
    @GetMapping("/select")
    public String select(Model model,String contractCompanyCode) {
        model.addAttribute("contractCompanyCode", contractCompanyCode);
        return ModuleConst.MODULE_ROOT + "/shoppingPay/selectCostCenter";
    }


}
