package cn.ezhizao.project.business.housingFund.controller;

import cn.ezhizao.framework.web.controller.BaseController;
import cn.ezhizao.framework.web.domain.AjaxResult;
import cn.ezhizao.project.business.housingFund.domain.BizHousingFundConfirmDetail;
import cn.ezhizao.project.business.housingFund.service.IBizHousingFundConfirmDetailService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * @author 周晓
 */
@RestController
@Api(tags = "FinancialHousingFundConfirmDetail数据接口")
@RequestMapping(value = "/business/financialHousingFundConfirmDetail")
public class BizHousingFundConfirmDetailController extends BaseController {

    @Resource
    IBizHousingFundConfirmDetailService financialHousingFundConfirmDetailService;

    @ApiOperation(value = "根据id查询", notes = "根据id查询")
    @GetMapping("/getById/{id}")
    @ResponseBody
    public AjaxResult getById(@PathVariable Long id) {
        return success(financialHousingFundConfirmDetailService.getById(id));
    }

    @PostMapping("/save")
    @ApiOperation(value = "保存", notes = "保存")
    @ResponseBody
    public AjaxResult save(@RequestBody BizHousingFundConfirmDetail financialHousingFundConfirmDetail) {
        return (financialHousingFundConfirmDetail.getId() == null ? financialHousingFundConfirmDetailService.save(financialHousingFundConfirmDetail) : financialHousingFundConfirmDetailService.updateById(financialHousingFundConfirmDetail)) ? success() : error();
    }

    @PostMapping("/saveBatch")
    @ApiOperation(value = "批量保存", notes = "批量保存")
    @ResponseBody
    public AjaxResult saveBatch(@RequestBody List<BizHousingFundConfirmDetail> list) {
        return financialHousingFundConfirmDetailService.saveOrUpdateBatch(list) ? success() : error();
    }

    @ApiOperation(value = "删除", notes = "删除")
    @GetMapping("/deleteById/{id}")
    @ResponseBody
    public AjaxResult deleteById(@PathVariable Long id) {
        return financialHousingFundConfirmDetailService.removeById(id) ? success() : error();
    }

    @ApiOperation(value = "批量删除", notes = "批量删除")
    @PostMapping("/batchDelete")
    @ResponseBody
    public AjaxResult batchDelete(@RequestBody List<Long> list) {
        return financialHousingFundConfirmDetailService.removeBatchByIds(list) ? success() : error();
    }

    @ApiOperation(value = "带条件List 分页查询", notes = "带条件List 分页查询")
    @GetMapping("/list")
    @ResponseBody
    public AjaxResult getList(@RequestBody Map<String, Object> conditions) {
        Map<String, Object> map = new HashMap<>(16);
        Integer pn = conditions.get("pn") == null ? null : Integer.parseInt(conditions.get("pn").toString());
        Integer size = conditions.get("size") == null ? null : Integer.parseInt(conditions.get("size").toString());
        Integer start = (pn == null || size == null) ? null : (pn - 1) * size;
        conditions.put("start", start);
        //分页数据
        map.put("list", financialHousingFundConfirmDetailService.getList(conditions));
        if (start != null) {
            //总页数
            map.put("total", financialHousingFundConfirmDetailService.getTotal(conditions));
        }
        return success(map);
    }

}
