package com.yida.data.school.transaction.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yida.data.common.core.annotation.ControllerLog;
import com.yida.data.common.core.common.ModuleName;
import com.yida.data.common.core.common.ResultBean;
import com.yida.data.common.core.entity.apply.EduProductModel;
import com.yida.data.common.core.entity.system.enums.OperationLogTypeEnum;
import com.yida.data.log.annotation.OperationLog;
import com.yida.data.school.transaction.service.EduProductModelService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 后台须知管理
 */

@Api(tags = "交易-商品须知")
@RestController
@RequestMapping("/transaction/productModel")
public class EduProductModelController {
    @Resource
    private EduProductModelService eduProductModelService;

    @ApiOperation("须知查询")
    @GetMapping("/selectProductModel")
    public ResultBean listModel(@ApiParam("须知名字") @RequestParam String modelName,
                                @RequestParam Integer pageNum,
                                @RequestParam Integer pageSize) {
        Page<EduProductModel> page = new Page<>();
        page.setCurrent(pageNum);
        page.setSize(pageSize);
        return ResultBean.buildSuccess(eduProductModelService.selectEduProductModelService(page, modelName));
    }

    @ApiOperation("新增须知")
    @PostMapping("/insertProductModel")
    @OperationLog(module = ModuleName.PRODUCT, methods = "新增商品须知", type = OperationLogTypeEnum.INSERT)
    public ResultBean insertModel(@RequestBody EduProductModel eduProductModel) {
        eduProductModelService.insertEduProductModelService(eduProductModel);
        return ResultBean.buildSuccess();
    }


    @ApiOperation("修改须知")
    @PostMapping("/updateProductModel")
    @OperationLog(module = ModuleName.PRODUCT, methods = "修改商品须知", type = OperationLogTypeEnum.UPDATE)
    public ResultBean upDataModel(@RequestBody EduProductModel eduProductModel) {
        eduProductModelService.updateEduProductModelService(eduProductModel);
        return ResultBean.buildSuccess();
    }


    @ApiOperation("删除须知")
    @GetMapping("/removeEduProductModel")
    @OperationLog(module = ModuleName.PRODUCT, methods = "删除商品须知", type = OperationLogTypeEnum.DELETE)
    public ResultBean removeModel(@ApiParam("应用id") @RequestParam Integer modelId) {
        eduProductModelService.removeEduProductModelService(modelId);
        return ResultBean.buildSuccess();
    }
}