package io.renren.modules.business.controller;

import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;
import io.renren.modules.business.entity.BusinessSsjdexcelEntity;
import io.renren.modules.business.service.BusinessSsjdexcelService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

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



/**
 * 送审进度
 *
 * @author jiaqiao
 * @email jiaqiao@163.com
 * @date 2022-08-25 15:29:51
 */
@RestController
@RequestMapping("business/businessssjdexcel")
public class BusinessSsjdexcelController {
    @Autowired
    private BusinessSsjdexcelService businessSsjdexcelService;

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

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


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("business:businessssjdexcel:info")
    public R info(@PathVariable("id") Integer id){
		BusinessSsjdexcelEntity businessSsjdexcel = businessSsjdexcelService.getById(id);
        return R.ok().put("businessSsjdexcel", businessSsjdexcel);
    }

    /**
     * 根据绑定的合同ID查询信息
     */
    @RequestMapping("/contractInfo/{id}")
    @RequiresPermissions("business:businessssjdexcel:info")
    public R contractInfo(@PathVariable("id") Integer id){
		BusinessSsjdexcelEntity businessSsjdexcel = businessSsjdexcelService.contractInfo(id);
        return R.ok().put("businessSsjdexcel", businessSsjdexcel);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("business:businessssjdexcel:save")
    public R save(@RequestBody BusinessSsjdexcelEntity businessSsjdexcel){
        businessSsjdexcel.setExcelContractMoneyNew(businessSsjdexcel.getExcelContractMoney());
		businessSsjdexcelService.save(businessSsjdexcel);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("business:businessssjdexcel:update")
    public R update(@RequestBody BusinessSsjdexcelEntity businessSsjdexcel){
        if(businessSsjdexcel.getExcelContractMoney() != null) {
            businessSsjdexcel.setExcelContractMoney(null);
        }
		businessSsjdexcelService.updateById(businessSsjdexcel);

        return R.ok();
    }

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

        return R.ok();
    }

}
