ShyActivityController.java 2.61 KB
package com.cnlive.shenhe.controller;


import com.cnlive.shenhe.bean.ErrorEnum;
import com.cnlive.shenhe.bean.ResponseBean;
import com.cnlive.shenhe.dto.ShyActivityDTO;
import com.cnlive.shenhe.entity.ShyActivity;
import com.cnlive.shenhe.serviceImpl.ShyActivityImpl;
import com.cnlive.shenhe.utils.CommonConst;
import com.cnlive.shenhe.utils.CommonUtils;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;


/**
 * @author Administrator
 * @author yanzhaowang
 * @create 2022-03-08 12:37
 */
@Controller
@RequestMapping("/activity")
public class ShyActivityController {
    @Autowired
    private ShyActivityImpl shyActivityImpl;

    @PostMapping("/add")
    @ResponseBody
    public ResponseBean insterShyActivity(ShyActivity shyActivity) {
        int i = shyActivityImpl.insertShyActivity(shyActivity);
        if (i > 0) {
            return new ResponseBean(ErrorEnum.SUCCESS.getErrorCode(), "当前活动添加成功");
        }
        return new ResponseBean(ErrorEnum.ERROR.getErrorCode(), "添加失败,请重试");
    }

    @PostMapping("/delete")
    @ResponseBody
    public ResponseBean deleteShyActivity(Integer id) {
        int i = shyActivityImpl.deleteShyActivity(id);
        if (i > 0) {
            return new ResponseBean(ErrorEnum.SUCCESS.getErrorCode(), "删除当前活动成功");
        }
        return new ResponseBean(ErrorEnum.ERROR.getErrorCode(), "删除失败,请重试");

    }

    @PostMapping("/update")
    @ResponseBody
    public ResponseBean updateShyActivity(ShyActivity shyActivity) {

        int i = shyActivityImpl.updateShyActivity(shyActivity);
        if (i > 0) {
            return new ResponseBean(ErrorEnum.SUCCESS.getErrorCode(), "修改当前活动成功");
        }
        return new ResponseBean(ErrorEnum.ERROR.getErrorCode(), "修改失败,请重试");

    }

    @GetMapping("/page")
    public String getShyActivity(@RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "10") Integer pageSize, Model model, String activity, Integer exempt_from_trial) {
        PageInfo<ShyActivity> shyActivityPageInfo = shyActivityImpl.selectByExample(pageNum, pageSize, activity, exempt_from_trial);
        List<ShyActivity> list = shyActivityPageInfo.getList();
        model.addAttribute("exempt_from_trial",exempt_from_trial);
        model.addAttribute("ShyActivitylist", shyActivityPageInfo);
        return "page/activity.html";
    }


}