package com.ssm.controller;

import com.ssm.manage.response.GenericResponse;
import com.ssm.manage.query.PromotionUnitRequest;
import com.ssm.manage.response.ResponseCode;
import com.ssm.manage.service.SsmPromotionUnitService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * (PromotionUnit)表控制层
 *
 * @author makejava
 * @since 2021-12-24 10:37:16
 */
@Api(value = "促销Controller",tags = {"促销适用门店"})
@RestController
@RequestMapping("/demay/ssm/promotionunit")
@Slf4j
public class SsmPromotionUnitController {

    @Autowired
    private SsmPromotionUnitService ssmPromotionUnitService;

    @ApiOperation(value = "促销活动添加关联使用门店", httpMethod = "POST", response = GenericResponse.class)
    @RequestMapping("/adds")
    public GenericResponse add(@RequestBody PromotionUnitRequest promotionUnitRequest){
        GenericResponse genericResponse = new GenericResponse();
        int add =0;
        try{
            add = ssmPromotionUnitService.add(promotionUnitRequest);
        }catch (Exception e){
            log.error("SsmPromotionUnitController.add:",e);
            genericResponse.setCodeAndMsg(ResponseCode.FAILED);
            return genericResponse;
        }
        if(add>0){
            genericResponse.setCodeAndMsg(ResponseCode.OK);
        }else{
            genericResponse.setCodeAndMsg(ResponseCode.FAILED);
        }
        return genericResponse;
    }

    @ApiOperation(value = "促销活动修改关联使用门店", httpMethod = "POST", response = GenericResponse.class)
    @RequestMapping("/update")
    public GenericResponse update(@RequestBody PromotionUnitRequest promotionUnitRequest){
        GenericResponse genericResponse = new GenericResponse();
        int add =0;
        try{
            add = ssmPromotionUnitService.update(promotionUnitRequest);
        }catch (Exception e){
            log.error("SsmPromotionUnitController.update:",e);
            genericResponse.setCodeAndMsg(ResponseCode.FAILED);
            return genericResponse;
        }
        if(add>0){
            genericResponse.setCodeAndMsg(ResponseCode.OK);
        }else{
            genericResponse.setCodeAndMsg(ResponseCode.FAILED);
        }
        return genericResponse;
    }

    @ApiOperation(value = "促销活动修改关联使用门店", httpMethod = "POST", response = GenericResponse.class)
    @RequestMapping("/addupdate")
    public GenericResponse addupdate(@RequestBody PromotionUnitRequest promotionUnitRequest){
        GenericResponse genericResponse = new GenericResponse();
        int add = ssmPromotionUnitService.insertupdat(promotionUnitRequest);
        if(add>0){
            genericResponse.setCodeAndMsg(ResponseCode.OK);
        }else{
            genericResponse.setCodeAndMsg(ResponseCode.FAILED);
        }
        return genericResponse;
    }

    @ApiOperation(value = "促销活动修改关联使用门店清空", httpMethod = "POST", response = GenericResponse.class)
    @RequestMapping("/empty")
    public GenericResponse empty(@RequestBody PromotionUnitRequest promotionUnitRequest){
        GenericResponse genericResponse = new GenericResponse();
        int add = ssmPromotionUnitService.empty(promotionUnitRequest);
        if(add>0){
            genericResponse.setCodeAndMsg(ResponseCode.OK);
        }else{
            genericResponse.setCodeAndMsg(ResponseCode.FAILED);
        }
        return genericResponse;
    }
}
