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

import com.alibaba.fastjson.JSON;
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.service.ShyActivityService;
import com.github.pagehelper.PageInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author Administrator
 * @author yanzhaowang
 * @create 2022-03-08 12:37
 */
@Controller
@RequestMapping("/activity")
public class ShyActivityController extends BaseController {

    private static Logger logger = LoggerFactory.getLogger(ShyActivityController.class);

    @Autowired
    private ShyActivityService shyActivityService;

    /**
     * 添加活动
     *
     * @param shyActivity
     * @return
     */
    @PostMapping("/add")
    @ResponseBody
    public ResponseBean insterShyActivity(ShyActivity shyActivity) {
        try {
            Boolean result = shyActivityService.insertShyActivity(shyActivity);
            if (result) {
                return new ResponseBean(ErrorEnum.SUCCESS.getErrorCode(), "当前活动添加成功");
            }
            return new ResponseBean(ErrorEnum.ERROR.getErrorCode(), "添加失败,请重试");
        } catch (Exception e) {
            e.printStackTrace();
            return new ResponseBean(ErrorEnum.ERROR.getErrorCode(), "添加失败,请重试");
        }
    }

    /**
     * 根据主键id删除活动
     *
     * @param id
     * @return
     */
    @PostMapping("/delete")
    @ResponseBody
    public ResponseBean deleteShyActivity(Integer id) {
        Boolean result = shyActivityService.deleteShyActivity(id);
        if (result) {
            return new ResponseBean(ErrorEnum.SUCCESS.getErrorCode(), "删除当前活动成功");
        }
        return new ResponseBean(ErrorEnum.ERROR.getErrorCode(), "删除失败,请重试");

    }

    /**
     * 修改对象
     *
     * @param shyActivity
     * @return
     */
    @PostMapping("/update")
    @ResponseBody
    public ResponseBean updateShyActivity(ShyActivity shyActivity) {
        try {
            Boolean result = shyActivityService.updateShyActivity(shyActivity);
            if (result) {
                return new ResponseBean(ErrorEnum.SUCCESS.getErrorCode(), "修改当前活动成功");
            }
            return new ResponseBean(ErrorEnum.ERROR.getErrorCode(), "修改失败,请重试");
        } catch (Exception e) {
            e.printStackTrace();
            return new ResponseBean(ErrorEnum.ERROR.getErrorCode(), "修改失败,请重试");
        }

    }

    /**
     * 获取分页 条件查询的列表
     *
     * @param shyActivityDTO
     * @param model
     * @return
     */
    @GetMapping("/page")
    public String getShyActivity(ShyActivityDTO shyActivityDTO, Model model) {
        logger.info("列表请求参数:{}", JSON.toJSONString(shyActivityDTO));
        PageInfo<ShyActivity> shyActivityPageInfo = shyActivityService.selectByExample(shyActivityDTO);
        model.addAttribute("exempt_from_trial", shyActivityDTO.getExempt_from_trial());
        model.addAttribute("ShyActivitylist", shyActivityPageInfo);
        return "page/activity.html";
    }
}