package com.sunxung.factoring.web.cashflowmanage;

import com.sunxung.factoring.component.annotation.OperationLog;
import com.sunxung.factoring.component.enums.OperationTypeEnum;
import com.sunxung.factoring.dict.impl.CompanyOwnershipDict;
import com.sunxung.factoring.entity.GridPage;
import com.sunxung.factoring.entity.ResponseJson;
import com.sunxung.factoring.entity.cashflowmanage.BankCardInfo;
import com.sunxung.factoring.entity.cashflowmanage.vo.SearchBankCardInfoSetVo;
import com.sunxung.factoring.service.cashflowmanage.BankCardInfoSetService;
import com.sunxung.factoring.service.sys.DictionaryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * @Description : 银行卡信息设置控制层
 * @Author : JiaYf
 * @Date: 2021-10-30 14:16
 */
@Controller
@RequestMapping("/bankCardInfoSet")
public class BankCardInfoController {

    private final String prefix = "bankCardInfoSet";

    @Autowired
    private BankCardInfoSetService bankCardInfoSetService;

    @Autowired
    private DictionaryService dictService;

    /**
     * 跳转列表页面
     *
     * @return
     */
    @RequestMapping("/list")
    public String list(Model model) {
        model.addAttribute("companyOwnershipList", dictService.findByParentCode(CompanyOwnershipDict.CODE));
        return prefix + "/list";
    }

    /**
     * 分页查询 银行卡信息设置
     *
     * @param searchBankCardInfoSetVo
     * @return
     */
    @GetMapping("/select")
    @ResponseBody
    public GridPage<BankCardInfo> queryPage(SearchBankCardInfoSetVo searchBankCardInfoSetVo) {
        return bankCardInfoSetService.queryPage(searchBankCardInfoSetVo);
    }

    /**
     * 跳转新增页面
     *
     * @return
     */
    @RequestMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 保存银行卡信息设置表
     *
     * @param bankCardInfo
     * @return
     */
    @PostMapping("/doAdd")
    @ResponseBody
    @OperationLog(operationModule = "银行卡信息",operationType = OperationTypeEnum.INSERT,description = "保存银行卡信息")
    public Object doAdd(BankCardInfo bankCardInfo, HttpServletRequest request) {
        bankCardInfoSetService.add(bankCardInfo, request);
        return new ResponseJson("新增银行卡信息设置完成！");
    }

    /**
     * 跳转查看页面
     *
     * @param id 银行卡信息设置id
     * @return
     */
    @RequestMapping("/view")
    public String view(Model model, Long id) {
        model.addAttribute("bankCardInfo", bankCardInfoSetService.get(id));
        return prefix + "/view";
    }

    /**
     * 跳转修改页面
     *
     * @param id 银行卡信息设置id
     * @return
     */
    @RequestMapping("/update")
    public String update(Model model, Long id) {
        BankCardInfo bankCardInfo = bankCardInfoSetService.get(id);
        model.addAttribute("bankCardInfoSet", bankCardInfo);
        return prefix + "/update";
    }

    /**
     * 修改 银行卡信息设置表
     *
     * @param bankCardInfo
     * @return
     */
    @PostMapping("/doUpdate")
    @ResponseBody
    @OperationLog(operationModule = "银行卡信息",operationType = OperationTypeEnum.UPDATE,description = "修改 银行卡信息")
    public Object doUpdate(BankCardInfo bankCardInfo) {
        bankCardInfoSetService.updateById(bankCardInfo);
        return new ResponseJson("银行卡信息设置更新完成!");
    }

    /**
     * 删除 银行卡信息设置表
     *
     * @param id
     * @return
     */
    @PostMapping("/detete")
    @ResponseBody
    @OperationLog(operationModule = "银行卡信息",operationType = OperationTypeEnum.DELETE,description = "删除 银行卡信息")
    public Object detete(Long id) {
        bankCardInfoSetService.deleteById(id);
        return new ResponseJson("银行卡信息设置删除完成!");
    }

    /**
     * 启用 禁用  状态切换
     *
     * @param id
     * @param flag 1:启用；0：禁用
     * @return
     */
    @PostMapping("/enable")
    @ResponseBody
    @OperationLog(operationModule = "银行卡信息",operationType = OperationTypeEnum.OTHER,description = "启用 禁用 银行卡信息")
    public Object enable(Long id, Integer flag) {
        bankCardInfoSetService.enable(id, flag);
        if (flag.equals(1)) {
            return new ResponseJson("启用完成!");
        } else {
            return new ResponseJson("禁用完成!");
        }
    }

}
