package com.org.hktshop.controller.product;

import com.org.hktshop.Interface.product.IHktGoodsSeoDescService;
import com.org.hktshop.base.BaseResult;
import com.org.hktshop.controller.BaseController;
import com.org.hktshop.entity.Page;
import com.org.hktshop.entity.admin.HktAdmin;
import com.org.hktshop.entity.product.HktGoodsSeoDesc;
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("/search")
public class HktGoodsDescSeoController extends BaseController {

    @Autowired
    private IHktGoodsSeoDescService hktGoodsSeoDescService;

    @ApiOperation(value = "新增商品搜索标签", notes = "新增商品搜索标签", httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "languageId", value = "语言类型", required = true),
            @ApiImplicitParam(name = "name", value = "内容", required = true),
            @ApiImplicitParam(name = "sort", value = "排序", required = true)
    })
    @RequestMapping(value = "/updateDesc", method = RequestMethod.POST)
    public Object addSearchTitle(@RequestBody HktGoodsSeoDesc hktGoodsSeoDesc) {
        try {
            hktGoodsSeoDesc.setUseType(6);
            hktGoodsSeoDescService.updateDesc(new HktAdmin(),hktGoodsSeoDesc);
            return BaseResult.success();

        } catch (Exception e) {
            logger.error("新增商品搜索标签报错： error = {}", e.toString());
            return BaseResult.fail(HttpCode.INTERNAL_SERVER_ERROR.getCode());
        }
    }

    @ApiOperation(value = "删除商品搜索标签", notes = "删除商品搜索标签", httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "主键", required = true)
    })
    @RequestMapping(value = "/delSerace", method = RequestMethod.POST)
    public Object delSearchTitle(@RequestBody HktGoodsSeoDesc hktGoodsSeoDesc) {
        try {

            return hktGoodsSeoDescService.deleteDesc(new HktAdmin(),hktGoodsSeoDesc);
        } catch (Exception e) {
            logger.error("删除商品搜索标签报错： error = {}", e.toString());
            return BaseResult.fail(HttpCode.INTERNAL_SERVER_ERROR.getCode());
        }
    }


    @ApiOperation(value = "分页查询", notes = "分页查询", httpMethod = "POST")
    @RequestMapping(value = "/queryList", method = RequestMethod.POST)
    public Object queryByPage(@RequestBody HktGoodsSeoDesc hktGoodsSeoDesc) {
        try {
            hktGoodsSeoDesc.setUseType(6);
            Page<HktGoodsSeoDesc> page = hktGoodsSeoDescService.queryByPage(hktGoodsSeoDesc);
            return BaseResult.successWithData(page);
        } catch (Exception e) {
            logger.error("删除商品搜索标签报错： error = {}", e.toString());
            return BaseResult.fail(HttpCode.INTERNAL_SERVER_ERROR.getCode());
        }
    }

    @ApiOperation(value = "详情", notes = "详情", httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "主键", required = true)
    })
    @RequestMapping(value = "/findTitleById", method = RequestMethod.POST)
    public Object findTitleById(@RequestBody HktGoodsSeoDesc hktGoodsSeoDesc) {
        try {

            HktGoodsSeoDesc hgs = hktGoodsSeoDescService.findTitleById(hktGoodsSeoDesc);
            return BaseResult.successWithData(hgs);
        } catch (Exception e) {
            logger.error("删除商品搜索标签报错： error = {}", e.toString());
            return BaseResult.fail(HttpCode.INTERNAL_SERVER_ERROR.getCode());
        }
    }
}
