java 基于jeecg-boot的公告管理——上移、下移、置顶

一、后端

实体类:

package org.jeecg.modules.bidding.entity;

import java.io.Serializable;
import java.io.UnsupportedEncodingException;
import java.util.Date;
import java.math.BigDecimal;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import com.fasterxml.jackson.annotation.JsonFormat;
import org.springframework.format.annotation.DateTimeFormat;
import org.jeecgframework.poi.excel.annotation.Excel;
import org.jeecg.common.aspect.annotation.Dict;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;

/**
 * @Description: 公告管理
 * @Author: jeecg-boot
 * @Date:   2022-05-06
 * @Version: V1.0
 */
@Data
@TableName("bid_notice")
@Accessors(chain = true)
@EqualsAndHashCode(callSuper = false)
@ApiModel(value="bid_notice对象", description="公告管理")
public class BidNotice implements Serializable {
    private static final long serialVersionUID = 1L;

   /**主键*/
   @TableId(type = IdType.ASSIGN_ID)
    @ApiModelProperty(value = "主键")
    private java.lang.String id;
   /**创建人*/
    @ApiModelProperty(value = "创建人")
    private java.lang.String createBy;
   /**创建日期*/
   @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
    @ApiModelProperty(value = "创建日期")
    private java.util.Date createTime;
   /**更新人*/
    @ApiModelProperty(value = "更新人")
    private java.lang.String updateBy;
   /**更新日期*/
   @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
    @ApiModelProperty(value = "更新日期")
    private java.util.Date updateTime;
   /**所属部门*/
    @ApiModelProperty(value = "所属部门")
    private java.lang.String sysOrgCode;
   /**标题*/
   @Excel(name = "标题", width = 15)
    @ApiModelProperty(value = "标题")
    private java.lang.String title;
   /**内容*/
   @Excel(name = "内容", width = 15)
    @ApiModelProperty(value = "内容")
    private java.lang.String content;
   /**是否置顶*/
   @Excel(name = "是否置顶", width = 15, dicCode = "notice_top")
   @Dict(dicCode = "notice_top")
    @ApiModelProperty(value = "是否置顶")
    private java.lang.String isTop;
   /**排序*/
   @Excel(name = "排序", width = 15)
    @ApiModelProperty(value = "排序")
    private java.lang.Integer sort;
   /**状态*/
   @Excel(name = "状态", width = 15, dicCode = "notice_status")
   @Dict(dicCode = "notice_status")
    @ApiModelProperty(value = "状态")
    private java.lang.String status;
   /**发布时间*/
   @Excel(name = "发布时间", width = 20, format = "yyyy-MM-dd HH:mm:ss")
   @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
    @ApiModelProperty(value = "发布时间")
    private java.util.Date releaseDate;
   /**附件*/
   @Excel(name = "附件", width = 15)
    @ApiModelProperty(value = "附件")
    private java.lang.String annex;
    /**访问量*/
    @Excel(name = "访问量", width = 15)
    @ApiModelProperty(value = "访问量")
    private java.lang.Integer visit;
}

控制层:

package org.jeecg.modules.bidding.controller;

import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.common.util.oConvertUtils;
import org.jeecg.modules.bidding.entity.BidNotice;
import org.jeecg.modules.bidding.service.IBidNoticeService;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;

import org.jeecgframework.poi.excel.ExcelImportUtil;
import org.jeecgframework.poi.excel.def.NormalExcelConstants;
import org.jeecgframework.poi.excel.entity.ExportParams;
import org.jeecgframework.poi.excel.entity.ImportParams;
import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
import org.jeecg.common.system.base.controller.JeecgController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.servlet.ModelAndView;
import com.alibaba.fastjson.JSON;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.jeecg.common.aspect.annotation.AutoLog;

 /**
 * @Description: 公告管理
 * @Author: jeecg-boot
 * @Date:   2022-05-06
 * @Version: V1.0
 */
@Api(tags="公告管理")
@RestController
@RequestMapping("/bidding/bidNotice")
@Slf4j
public class BidNoticeController extends JeecgController {
   @Autowired
   private IBidNoticeService bidNoticeService;

   /**
    * 分页列表查询
    *
    * @param bidNotice
    * @param pageNo
    * @param pageSize
    * @param req
    * @return
    */
   @AutoLog(value = "公告管理-分页列表查询")
   @ApiOperation(value="公告管理-分页列表查询", notes="公告管理-分页列表查询")
   @GetMapping(value = "/list")
   public Result queryPageList(BidNotice bidNotice,
                           @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
                           @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
                           HttpServletRequest req) {
      if(oConvertUtils.isNotEmpty(bidNotice.getTitle())){
         bidNotice.setTitle("*"+bidNotice.getTitle()+"*");
      }
      QueryWrapper queryWrapper = QueryGenerator.initQueryWrapper(bidNotice, req.getParameterMap());
      Page page = new Page(pageNo, pageSize);
      queryWrapper.lambda()
            .orderByAsc(BidNotice::getIsTop).orderByAsc(BidNotice::getSort);
      IPage pageList = bidNoticeService.page(page, queryWrapper);
      return Result.OK(pageList);
   }

   /**
    *   添加
    *
    * @param bidNotice
    * @return
    */
   @AutoLog(value = "公告管理-添加")
   @ApiOperation(value="公告管理-添加", notes="公告管理-添加")
   @PostMapping(value = "/add")
   public Result add(@RequestBody BidNotice bidNotice) {
      int aCount = bidNoticeService.count(new LambdaQueryWrapper().eq(BidNotice::getIsTop,"20"));
      bidNotice.setSort(aCount+1);
      bidNotice.setIsTop("20");
      bidNotice.setStatus("20");
      bidNotice.setVisit(0);
      bidNoticeService.save(bidNotice);
      return Result.OK("添加成功!");
   }

    /**
     * 递增指定公告的访问数
     *
     * @param id
     * @return
     */
    @GetMapping("/increVisit")
    public Result increVisit(@RequestParam(name="id",required=true) String id) {
       int visit = bidNoticeService.increVisit(id);
       return Result.ok(visit);
    }

    /**
     *  发布
     *
     * @param id
     * @return
     */
    @AutoLog(value = "通知公告-发布")
    @ApiOperation(value="通知公告-发布", notes="通知公告-发布")
    @GetMapping(value = "/release")
    public Result release(@RequestParam(name="id",required=true) String id) {
       BidNotice bidNotice = bidNoticeService.getById(id);
       bidNotice.setStatus("10");
       bidNotice.setReleaseDate(new Date());
       bidNoticeService.updateById(bidNotice);
       return Result.OK("发布成功!");
    }

    /**
     *  下架
     *
     * @param id
     * @return
     */
    @AutoLog(value = "通知公告-下架")
    @ApiOperation(value="通知公告-下架", notes="通知公告-下架")
    @GetMapping(value = "/notRelease")
    public Result notRelease(@RequestParam(name="id",required=true) String id) {
       BidNotice bidNotice = bidNoticeService.getById(id);
       bidNotice.setStatus("20");
       bidNoticeService.updateById(bidNotice);
       return Result.OK("下架成功!");
    }

    /**
     *  置顶
     *
     * @param id
     * @return
     */
    @AutoLog(value = "通知公告-置顶")
    @ApiOperation(value="通知公告-置顶", notes="通知公告-置顶")
    @GetMapping(value = "/top")
    public Result top(@RequestParam(name="id",required=true) String id) {
       int aCount = bidNoticeService.count(new LambdaQueryWrapper().eq(BidNotice::getIsTop,"10"));
       BidNotice bidNotice = bidNoticeService.getById(id);
       bidNoticeService.updateSortByDel(bidNotice);
       bidNotice.setIsTop("10");
       bidNotice.setSort(aCount+1);
       bidNoticeService.updateById(bidNotice);
       return Result.OK("置顶成功!");
    }

    /**
     *  取消置顶
     *
     * @param id
     * @return
     */
    @AutoLog(value = "通知公告-取消置顶")
    @ApiOperation(value="通知公告-取消置顶", notes="通知公告-取消置顶")
    @GetMapping(value = "/notTop")
    public Result notTop(@RequestParam(name="id",required=true) String id) {
       int aCount = bidNoticeService.count(new LambdaQueryWrapper().eq(BidNotice::getIsTop,"20"));
       BidNotice bidNotice = bidNoticeService.getById(id);
       bidNoticeService.updateSortByDel(bidNotice);
       bidNotice.setIsTop("20");
       bidNotice.setSort(aCount+1);
       bidNoticeService.updateById(bidNotice);
       return Result.OK("取消置顶成功!");
    }

    /**
     *  上移
     *
     * @param id
     * @return
     */
    @AutoLog(value = "通知公告-上移")
    @ApiOperation(value="通知公告-上移", notes="通知公告-上移")
    @GetMapping(value = "/up")
    public Result up(@RequestParam(name="id",required=true) String id) {
       BidNotice bidNotice = bidNoticeService.getById(id);
       int aSort = bidNotice.getSort();
       if(aSort != 1) {
          BidNotice aBidNotice = bidNoticeService.getOne(new QueryWrapper().eq("sort", aSort - 1).eq("is_top",bidNotice.getIsTop()));
          bidNotice.setSort(aSort - 1);
          aBidNotice.setSort(aSort);
          bidNoticeService.updateById(bidNotice);
          bidNoticeService.updateById(aBidNotice);
       }
       return Result.OK("上移成功!");
    }

    /**
     *  下移
     *
     * @param id
     * @return
     */
    @AutoLog(value = "通知公告-下移")
    @ApiOperation(value="通知公告-下移", notes="通知公告-下移")
    @GetMapping(value = "/down")
    public Result down(@RequestParam(name="id",required=true) String id) {
       BidNotice bidNotice = bidNoticeService.getById(id);
       int aSort = bidNotice.getSort();
       int aCount= bidNoticeService.count();
       if(aSort != aCount) {
          BidNotice aBidNotice= bidNoticeService.getOne(new QueryWrapper().eq("sort", aSort + 1).eq("is_top",bidNotice.getIsTop()));
          bidNotice.setSort(aSort + 1);
          aBidNotice.setSort(aSort);
          bidNoticeService.updateById(bidNotice);
          bidNoticeService.updateById(aBidNotice);
       }
       return Result.OK("下移成功!");
    }

   /**
    *  编辑
    *
    * @param bidNotice
    * @return
    */
   @AutoLog(value = "公告管理-编辑")
   @ApiOperation(value="公告管理-编辑", notes="公告管理-编辑")
   @PutMapping(value = "/edit")
   public Result edit(@RequestBody BidNotice bidNotice) {
      bidNoticeService.updateById(bidNotice);
      return Result.OK("编辑成功!");
   }

   /**
    *   通过id删除
    *
    * @param id
    * @return
    */
   @AutoLog(value = "公告管理-通过id删除")
   @ApiOperation(value="公告管理-通过id删除", notes="公告管理-通过id删除")
   @DeleteMapping(value = "/delete")
   public Result delete(@RequestParam(name="id",required=true) String id) {

      BidNotice bidNotice = bidNoticeService.getById(id);
      bidNoticeService.updateSortByDel(bidNotice);
      bidNoticeService.removeById(id);
      return Result.OK("删除成功!");
   }


   /**
    * 通过id查询
    *
    * @param id
    * @return
    */
   @AutoLog(value = "公告管理-通过id查询")
   @ApiOperation(value="公告管理-通过id查询", notes="公告管理-通过id查询")
   @GetMapping(value = "/queryById")
   public Result queryById(@RequestParam(name="id",required=true) String id) {
      BidNotice bidNotice = bidNoticeService.getById(id);
      if(bidNotice==null) {
         return Result.error("未找到对应数据");
      }
      return Result.OK(bidNotice);
   }


}

服务层:

 1、接口

package org.jeecg.modules.bidding.service;

import org.jeecg.modules.bidding.entity.BidNotice;
import com.baomidou.mybatisplus.extension.service.IService;

/**
 * @Description: 公告管理
 * @Author: jeecg-boot
 * @Date:   2022-05-06
 * @Version: V1.0
 */
public interface IBidNoticeService extends IService {
    void updateSortByDel(BidNotice bidNotice);
    int increVisit(String id);
}

2、实现

package org.jeecg.modules.bidding.service.impl;

import org.jeecg.modules.bidding.entity.BidNotice;
import org.jeecg.modules.bidding.mapper.BidNoticeMapper;
import org.jeecg.modules.bidding.service.IBidNoticeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

/**
 * @Description: 公告管理
 * @Author: jeecg-boot
 * @Date:   2022-05-06
 * @Version: V1.0
 */
@Service
public class BidNoticeServiceImpl extends ServiceImpl implements IBidNoticeService {
    @Autowired
    private BidNoticeMapper bidNoticeMapper;
    @Override
    public void updateSortByDel(BidNotice bidNotice) {
        bidNoticeMapper.updateSortByDel(bidNotice);
    }
    @Override
    public synchronized int increVisit(String id) {
        BidNotice bidNotice = bidNoticeMapper.selectById(id);
        bidNotice.setVisit(bidNotice.getVisit()+1);
        bidNoticeMapper.updateById(bidNotice);
        return bidNotice.getVisit();
    }
}

dao层:

1、mapper

package org.jeecg.modules.bidding.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Param;
import org.jeecg.modules.bidding.entity.BidNotice;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;

/**
 * @Description: 公告管理
 * @Author: jeecg-boot
 * @Date:   2022-05-06
 * @Version: V1.0
 */
public interface BidNoticeMapper extends BaseMapper {
    void updateSortByDel(BidNotice bidNotice);
}

2、mybatis文件



    
        update bid_notice
        
            sort = sort - 1
        
        where sort > #{sort}
        and is_top = #{isTop}
    

二、前端




你可能感兴趣的:(java,intellij-idea,vue.js)