package io.renren.modules.business.controller;

import java.util.Arrays;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.modules.business.entity.BusinessLoanEntity;
import io.renren.modules.business.service.BusinessLoanService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 * 工人借款明细
 *
 * @author jiaqiao
 * @email jiaqiao@163.com
 * @date 2022-07-17 11:28:39
 */
@RestController
@RequestMapping("business/businessloan")
public class BusinessLoanController {
    @Autowired
    private BusinessLoanService businessLoanService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("business:businessloan:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = businessLoanService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{loanId}")
    @RequiresPermissions("business:businessloan:info")
    public R info(@PathVariable("loanId") Integer loanId){
		BusinessLoanEntity businessLoan = businessLoanService.getById(loanId);

        return R.ok().put("businessLoan", businessLoan);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("business:businessloan:save")
    public R save(@RequestBody BusinessLoanEntity businessLoan){
		businessLoanService.save(businessLoan);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("business:businessloan:update")
    public R update(@RequestBody BusinessLoanEntity businessLoan){
		businessLoanService.updateById(businessLoan);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("business:businessloan:delete")
    public R delete(@RequestBody Integer[] loanIds){
		businessLoanService.removeByIds(Arrays.asList(loanIds));

        return R.ok();
    }

}
