package com.org.hktshop.controller.product;

import com.org.hktshop.Interface.product.IHktSearchReplacementService;
import com.org.hktshop.base.BaseResult;
import com.org.hktshop.controller.BaseController;
import com.org.hktshop.entity.product.HktSearchReplacement;
import com.org.hktshop.utils.HttpCode;
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.RestController;

/**
 * @author hotking03
 */
@RequestMapping("/async/replace")
@RestController
public class HktSearchReplacementController extends BaseController {

    @Autowired
    private IHktSearchReplacementService hktSearchReplacementService;

    @RequestMapping("/updateReplace")
    public Object updateReplace(@RequestBody HktSearchReplacement hktSearchReplacement){
        try {
            return hktSearchReplacementService.updateReplace(hktSearchReplacement);
        }catch (Exception e){
            logger.info(e.toString());
            return BaseResult.fail(HttpCode.INTERNAL_SERVER_ERROR.getCode(),HttpCode.INTERNAL_SERVER_ERROR.getMsg());
        }
    }

    @RequestMapping("/delReplace")
    public Object delReplace(@RequestBody HktSearchReplacement hktSearchReplacement){
        try {
            hktSearchReplacementService.delReplace(hktSearchReplacement);
            return BaseResult.success();
        }catch (Exception e){
            logger.info(e.toString());
            return BaseResult.fail(HttpCode.INTERNAL_SERVER_ERROR.getCode(),HttpCode.INTERNAL_SERVER_ERROR.getMsg());
        }
    }

    @RequestMapping("/queryList")
    public Object queryList(@RequestBody HktSearchReplacement hktSearchReplacement){
        try {
            return BaseResult.successWithData(hktSearchReplacementService.queryListByPage(hktSearchReplacement));
        }catch (Exception e){
            logger.info(e.toString());
            return BaseResult.fail(HttpCode.INTERNAL_SERVER_ERROR.getCode(),HttpCode.INTERNAL_SERVER_ERROR.getMsg());
        }
    }


    @RequestMapping("/findReplace")
    public Object findReplace(@RequestBody HktSearchReplacement hktSearchReplacement){
        try {
            return BaseResult.successWithData(hktSearchReplacementService.findReplace(hktSearchReplacement));
        }catch (Exception e){
            logger.info(e.toString());
            return BaseResult.fail(HttpCode.INTERNAL_SERVER_ERROR.getCode(),HttpCode.INTERNAL_SERVER_ERROR.getMsg());
        }
    }
}
