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

import cn.ezhizao.framework.web.controller.BaseController;
import cn.ezhizao.framework.web.domain.AjaxResult;
import cn.ezhizao.project.business.socialSecurity.domain.BizSocialSecurityConfirmDetail;
import cn.ezhizao.project.business.socialSecurity.service.IBizSocialSecurityConfirmDetailService;
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 = "FinancialSocialSecurityConfirmDetail数据接口")
@RequestMapping(value = "/business/financialSocialSecurityConfirmDetail")
public class SocialSecurityConfirmDetailController extends BaseController {

    @Resource
    IBizSocialSecurityConfirmDetailService financialSocialSecurityConfirmDetailService;

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

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

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

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

    @ApiOperation(value = "批量删除", notes = "批量删除")
    @PostMapping("/batchDelete")
    @ResponseBody
    public AjaxResult batchDelete(@RequestBody List<Long> list) {
        return financialSocialSecurityConfirmDetailService.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", financialSocialSecurityConfirmDetailService.getList(conditions));
        if (start != null) {
            //总页数
            map.put("total", financialSocialSecurityConfirmDetailService.getTotal(conditions));
        }
        return success(map);
    }


}
