package com.org.hktshop.controller.product;

import com.org.hktshop.Interface.product.IHktPriceRegulationService;
import com.org.hktshop.base.BaseResult;
import com.org.hktshop.controller.BaseController;
import com.org.hktshop.entity.product.HktPriceRegulation;
import com.org.hktshop.utils.HttpCode;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;


/**
 * 价格规则
 * @author owen
 */
@RestController
@RequestMapping("/async/regulation")
public class HktPriceRegulationController extends BaseController {

    @Autowired
    private IHktPriceRegulationService hktPriceRegulationService;
    /****
     * 新增/修改 价格规则
     * @param priceRegulation
     * @return
     */
    @RequestMapping(value = "/updatePriceRegulation",method = RequestMethod.POST)
    @ApiOperation(value = "新增/修改 价格规则")
    public Object updatePriceTemplate(@RequestBody HktPriceRegulation priceRegulation) {
        try {
            hktPriceRegulationService.updatePriceTemplate(priceRegulation);
            return BaseResult.success();
        } catch (Exception ex) {
            logger.info("新增/修改价格规则错误  error = {}",ex.toString());
            return BaseResult.fail(HttpCode.INTERNAL_SERVER_ERROR.getCode(), HttpCode.INTERNAL_SERVER_ERROR.getMsg());
        }
    }

    /****
     * 删除价格规则
     * @param priceRegulation
     * @return
     */
    @RequestMapping(value = "/delPriceRegulation",method = RequestMethod.POST)
    @ApiOperation(value = "删除价格规则")
    public Object delPriceTemplate(@RequestBody HktPriceRegulation priceRegulation) {
        try {
            hktPriceRegulationService.delPriceTemplate(priceRegulation);
            return BaseResult.success();
        } catch (Exception ex) {
            logger.info("删除价格规则错误  error = {}",ex.toString());
            return BaseResult.fail(HttpCode.INTERNAL_SERVER_ERROR.getCode(), HttpCode.INTERNAL_SERVER_ERROR.getMsg());
        }
    }

    @ApiOperation(value = "分页查询价格规则", notes = "分页查询价格规则", httpMethod = "POST")
    @RequestMapping(value = "/queryList",method = RequestMethod.POST)
    public Object queryPriceRegulationByPage(@RequestBody HktPriceRegulation priceRegulation) {
        try {
            Object page = hktPriceRegulationService.queryPriceRegulationByPage(priceRegulation);
            return BaseResult.successWithData(page);
        } catch (Exception e) {
            logger.info("分页查询价格规则列表错误  error = {}",e.toString());
            e.printStackTrace();
            return BaseResult.fail(HttpCode.INTERNAL_SERVER_ERROR.getCode());
        }
    }

    @ApiOperation(value = "价格规则详情", notes = "价格规则详情", httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "价格规则主键")
    })
    @RequestMapping("/findPriceRegulation")
    public Object findPriceRegulation(@RequestBody HktPriceRegulation priceRegulation) {
        try {
            HktPriceRegulation hktThe = hktPriceRegulationService.findPriceRegulation(priceRegulation);
            return BaseResult.successWithData(hktThe);
        } catch (Exception e) {
            logger.info("价格规则查询错误  error = {}",e.toString());
            return BaseResult.fail(HttpCode.INTERNAL_SERVER_ERROR.getCode());
        }
    }
}
