package com.org.hktshop.controller.encapsulation;

import com.org.hktshop.base.BaseResult;
import com.org.hktshop.entity.Page;
import com.org.hktshop.entity.encapsulation.FcPackage;
import com.org.hktshop.service.encapsulation.FcPackageService;
import com.org.hktshop.utils.HttpCode;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/encapsulation")
@Api(tags = "封装接口")
public class FcPackageController {

    @Autowired
    private FcPackageService fcPackageService;

    @PostMapping("/save")
    @ApiOperation(value = "新增封装", notes = "新增封装")
    public BaseResult insert(@RequestBody FcPackage fcPackage) {
        try {
            fcPackageService.saveEncapsulation(fcPackage);
            return BaseResult.success();
        } catch (Exception ex) {
            return BaseResult.fail(HttpCode.INTERNAL_SERVER_ERROR.getCode(),HttpCode.INTERNAL_SERVER_ERROR.getMsg());
        }
    }

    @GetMapping("/deleteById")
    @ApiOperation(value = "删除封装", notes = "删除封装")
    public BaseResult deleteById(@RequestParam String id) {
        try {
            fcPackageService.deleteEncapsulation(id);
            return BaseResult.success();
        } catch (Exception ex) {
            return BaseResult.fail(HttpCode.INTERNAL_SERVER_ERROR.getCode(),HttpCode.INTERNAL_SERVER_ERROR.getMsg());
        }
    }

    @PostMapping("/update")
    @ApiOperation(value = "修改封装", notes = "修改封装")
    public BaseResult update(@RequestBody FcPackage fcPackage) {
        try {
            fcPackageService.updateEncapsulation(fcPackage);
            return BaseResult.success();
        } catch (Exception ex) {
            return BaseResult.fail(HttpCode.INTERNAL_SERVER_ERROR.getCode(),HttpCode.INTERNAL_SERVER_ERROR.getMsg());
        }
    }

    @GetMapping("/getById")
    @ApiOperation(value = "封装 id查", notes = "封装 id查")
    public BaseResult<FcPackage> getById(@RequestParam String id) {
        try {
            return BaseResult.successWithData(fcPackageService.getEncapsulation(id));
        } catch (Exception ex) {
            return BaseResult.fail(HttpCode.INTERNAL_SERVER_ERROR.getCode(),HttpCode.INTERNAL_SERVER_ERROR.getMsg());
        }
    }

    @PostMapping("/getEncapsulation")
    @ApiOperation(value = "封装 条件查", notes = "封装 条件查")
    public BaseResult<FcPackage> getEncapsulation(@RequestBody FcPackage fcPackage) {
        try {
            return BaseResult.successWithData(fcPackageService.getEncapsulation(fcPackage));
        } catch (Exception ex) {
            return BaseResult.fail(HttpCode.INTERNAL_SERVER_ERROR.getCode(),HttpCode.INTERNAL_SERVER_ERROR.getMsg());
        }
    }

    @PostMapping("/findPage")
    @ApiOperation(value = "封装 分页查", notes = "封装 分页查")
    public BaseResult<Page<FcPackage>> findPage(@RequestBody FcPackage fcPackage) {
        try {
            return BaseResult.successWithData(fcPackageService.getHktEncapsulationPage(fcPackage));
        } catch (Exception ex) {
            return BaseResult.fail(HttpCode.INTERNAL_SERVER_ERROR.getCode(),HttpCode.INTERNAL_SERVER_ERROR.getMsg());
        }
    }
}
