package com.pine.admin.modules.business.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.pine.common.dto.Page;
import com.pine.admin.modules.base.binder.BaseController;
import com.pine.common.dto.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestMethod;
import com.pine.admin.modules.business.entity.OfflinePayments;
import com.pine.admin.modules.business.service.OfflinePaymentsService;


/**
 * 线下支付详情
 *
 * @author Pine
 * @email 771190883@qq.com
 * @date 2019-07-25 18:38:56
 */
@Api(value = "线下支付详情接口", tags = {"线下支付详情接口" })
//@RestController
//@RequestMapping("business/OfflinePayments")
public class OfflinePaymentsController extends BaseController {

    @Autowired
    private OfflinePaymentsService offlinePaymentsService;


    /**
     * <p>获取全部记录。</p>
     */
    @ApiOperation(value = "获取所有线下支付详情数据", notes = "可以根据条件获取")
    @RequestMapping(value = "/all", method = RequestMethod.GET)
    public Result all(OfflinePayments record) {

        List<OfflinePayments> pp = offlinePaymentsService.getAllList(record);
        return Result.success(true, pp);
    }


    /**
     * <p>根据Id。</p>
     */
    @ApiOperation(value = "获取线下支付详情数据", notes = "根据id来获取线下支付详情详细信息")
    @RequestMapping(value = "/get/{id}", method = RequestMethod.GET)
    public Result getOfflinePaymentsEntity(@PathVariable("id") String id) {

            OfflinePayments data = offlinePaymentsService.getById(id);
        return Result.success(true, data);
    }

    /**
     * <p>根据条件获取。</p>
     */
    @ApiOperation(value = "获取线下支付详情数据", notes = "根据条件获取")
    @RequestMapping(value = "/getOne", method = RequestMethod.GET)
    public Result getOne(OfflinePayments record) {

            OfflinePayments data = offlinePaymentsService.getOne(record);
        return Result.success(true, data);
    }

    /**
     * <p>分页查询。</p>
     */
    @ApiOperation(value = "分页获取线下支付详情数据", notes = "根据条件获取")
    @RequestMapping(value = "/page", method = RequestMethod.GET)
    public Result page(Page page, OfflinePayments record) {

        Map<String, Object> result = new HashMap<>();

        List<OfflinePayments> pp = offlinePaymentsService.getByPage(page, record);

        result.put("page", page);
        result.put("pp", pp);
        return Result.success(true, result);
    }

    /**
     * <p>保存。</p>
     */
    @ApiOperation(value = "新增一条线下支付详情数据", notes = "新增一条线下支付详情数据")
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    public Result save(OfflinePayments record) {

        boolean num = offlinePaymentsService.create(record);
        if (num) {
            return Result.success(true, record.getId());
        }
        return Result.error("保存异常");
    }

    /**
     * <p>更新信息。</p>
     */
    @ApiOperation(value = "更新一条线下支付详情数据", notes = "更新一条线下支付详情数据")
    @RequestMapping(value = "/update", method = RequestMethod.PUT)
    public Result updateOfflinePayments(OfflinePayments record) {

        boolean num = offlinePaymentsService.update(record);
        if (num) {
            return Result.success(true, "保存成功");
        }
        return Result.error("保存异常");
    }

    /**
     * <p>删除。</p>
     */
    @RequestMapping(value = "/del/{id}", method = RequestMethod.DELETE)
    @ApiOperation(value = "删除一条线下支付详情数据", notes = "根据Id一条线下支付详情数据")
    public Result deleteOfflinePayments(@PathVariable("id") String id) {

        boolean num = offlinePaymentsService.delete(id);
        if (num) {
            return Result.success(true, "删除成功");
        }
        return Result.error("删除异常");
    }

    /**
     * <p>批量删除。</p>
     */
    @RequestMapping(value = "/deltetByIds", method = RequestMethod.DELETE)
    @ApiOperation(value = "删除多条线下支付详情数据", notes = "删除id的集合多个用英文逗号分隔")
    public Result delOfflinePaymentsAll(@RequestParam(required = true, value = "ids") String ids) {

        boolean num = offlinePaymentsService.deltetByIds(ids);
        if (num) {
            return Result.success(true, "删除成功");
        }
        return Result.error("删除异常");
    }

}
