洪城义警-正式版后台
zhongrj
2023-06-27 2ca9993b57bdd090c4345ea6767687e2fbb83014
新增任务导出接口
9 files modified
1 files added
250 ■■■■ changed files
src/main/java/org/springblade/modules/nettyUdpServer/handle/UdpServerHandler.java 6 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/nettyUdpServer/server/UdpServer.java 37 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/taskqd/controller/TaskqdController.java 28 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/taskqd/excel/TaskExcel.java 69 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/taskqd/mapper/TaskqdMapper.java 16 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/taskqd/mapper/TaskqdMapper.xml 33 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/taskqd/service/ITaskqdService.java 17 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/taskqd/service/impl/TaskqdServiceImpl.java 26 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/taskqd/vo/TaskqdVO.java 5 ●●●●● patch | view | raw | blame | history
src/main/resources/application-prod.yml 13 ●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/nettyUdpServer/handle/UdpServerHandler.java
@@ -25,17 +25,11 @@
        String body = new String(req, CharsetUtil.UTF_8);
        System.out.println("【UDP】>>>>>> 收到客户端的数据:"+body);
        // 回复一条信息给客户端
//        channelHandlerContext.writeAndFlush(new DatagramPacket(
//            Unpooled.copiedBuffer("Hello,我是Server,我的时间戳是"+System.currentTimeMillis()
//                , CharsetUtil.UTF_8)
//            , datagramPacket.sender())).sync();
    }
    //捕获异常
    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause)throws Exception {
        //logger.log(Level.INFO, "AuthServerInitHandler exceptionCaught");
        logger.error("UdpServerHandler exceptionCaught"+cause.getMessage());
        System.out.println("UdpServerHandler exceptionCaught"+cause.getMessage());
        cause.printStackTrace();
src/main/java/org/springblade/modules/nettyUdpServer/server/UdpServer.java
@@ -31,43 +31,6 @@
        run();
    }
    /**
     * 不用
     */
    public void init() {
        final NioEventLoopGroup group = new NioEventLoopGroup();
        try {
            Bootstrap b = new Bootstrap();
            b.group(group).channel(NioDatagramChannel.class)
                .option(ChannelOption.SO_BROADCAST, true)
                .handler(new ChannelInitializer<NioDatagramChannel>() {
                    @Override
                    public void initChannel(NioDatagramChannel ch) throws Exception {
                        ChannelPipeline p = ch.pipeline();
                        p.addLast("decoder", new JsonObjectDecoder());
                        p.addLast(new UdpServerHandler());
                    }
                });
            InetAddress address = InetAddress.getLocalHost();
            channel = b.bind(address, port).sync().channel();
            Executors.newSingleThreadExecutor().execute(new Runnable() {
                @Override
                public void run() {
                    try {
                        channel.closeFuture().sync();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    } finally {
                        group.shutdownGracefully();
                    }
                }
            });
            LOG.info("UDP服务器启动, host:{},port:{}", address.getHostAddress(), port);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    //给管道抽象出接口,给Channel更多的能力和配置,例如Channel的状态,参数,IO操作
    //使用ChannelPipeline实现自定义IO
src/main/java/org/springblade/modules/taskqd/controller/TaskqdController.java
@@ -25,9 +25,11 @@
import me.zhyd.oauth.log.Log;
import org.joda.time.DateTime;
import org.springblade.core.boot.ctrl.BladeController;
import org.springblade.core.excel.util.ExcelUtil;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.DateUtil;
import org.springblade.core.tool.utils.Func;
import org.springblade.core.tool.utils.StringUtil;
import org.springblade.modules.task.entity.Task;
@@ -35,12 +37,14 @@
import org.springblade.modules.task.vo.TaskVO;
import org.springblade.modules.task.wrapper.TaskWrapper;
import org.springblade.modules.taskqd.entity.Taskqd;
import org.springblade.modules.taskqd.excel.TaskExcel;
import org.springblade.modules.taskqd.service.impl.TaskqdServiceImpl;
import org.springblade.modules.taskqd.vo.TaskqdVO;
import org.springblade.modules.taskqd.wrapper.TaskqdWrapper;
import org.springblade.modules.webscoket.service.IPushMsgService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
@@ -85,6 +89,19 @@
    public R<IPage<TaskqdVO>> list(Taskqd taskqd, Query query) {
        IPage<Taskqd> pages = taskqdService.page(Condition.getPage(query), Condition.getQueryWrapper(taskqd).orderByDesc("time"));
        return R.data(TaskqdWrapper.build().pageVO(pages));
    }
    /**
     * 自定义分页查询
     * @param taskqd
     * @param query
     * @return
     */
    @GetMapping("/page")
    @ApiOperationSupport(order = 2)
    @ApiOperation(value = "分页", notes = "传入task")
    public R selectTaskQdPage(TaskqdVO taskqd, Query query) {
        return R.data(taskqdService.selectTaskQdPage(Condition.getPage(query), taskqd));
    }
@@ -477,4 +494,15 @@
        List<Taskqd> list = taskqdService.countTaskByJur(jurisdiction,startTime,period);
        return R.data(list);
    }
    /**
     * 导出任务数据
     * @param task
     * @param response
     */
    @GetMapping("export-task")
    public void exportTask(@ApiIgnore @RequestParam TaskqdVO task, HttpServletResponse response) {
        List<TaskExcel> list = taskqdService.exportTask(task);
        ExcelUtil.export(response, "任务数据" + DateUtil.time(), "任务数据表", list, TaskExcel.class);
    }
}
src/main/java/org/springblade/modules/taskqd/excel/TaskExcel.java
New file
@@ -0,0 +1,69 @@
/*
 *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions are met:
 *
 *  Redistributions of source code must retain the above copyright notice,
 *  this list of conditions and the following disclaimer.
 *  Redistributions in binary form must reproduce the above copyright
 *  notice, this list of conditions and the following disclaimer in the
 *  documentation and/or other materials provided with the distribution.
 *  Neither the name of the dreamlu.net developer nor the names of its
 *  contributors may be used to endorse or promote products derived from
 *  this software without specific prior written permission.
 *  Author: Chill 庄骞 (smallchill@163.com)
 */
package org.springblade.modules.taskqd.excel;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.write.style.ColumnWidth;
import com.alibaba.excel.annotation.write.style.ContentRowHeight;
import com.alibaba.excel.annotation.write.style.HeadRowHeight;
import lombok.Data;
import java.io.Serializable;
/**
 * RegionExcel
 *
 * @author Chill
 */
@Data
@ColumnWidth(16)
@HeadRowHeight(20)
@ContentRowHeight(18)
public class TaskExcel implements Serializable {
    private static final long serialVersionUID = 1L;
    @ExcelProperty("培训标题")
    private String rname;
    @ExcelProperty("开始时间")
    private String time;
    @ExcelProperty("结束时间")
    private String endtime;
    @ExcelProperty("培训内容")
    private String content;
    @ExcelProperty("所属辖区")
    private String jurisdictionName;
    @ExcelProperty("集合点")
    private String gathername;
    @ExcelProperty("培训状态")
    private String rtypeName;
    @ExcelProperty("发布人")
    private String fname;
    @ExcelProperty("积分数值")
    private Integer integral;
    @ExcelProperty("接收角色")
    private String trainName;
}
src/main/java/org/springblade/modules/taskqd/mapper/TaskqdMapper.java
@@ -23,6 +23,7 @@
import org.springblade.modules.task.entity.Task;
import org.springblade.modules.task.vo.TaskVO;
import org.springblade.modules.taskqd.entity.Taskqd;
import org.springblade.modules.taskqd.excel.TaskExcel;
import org.springblade.modules.taskqd.vo.TaskqdVO;
import java.util.Date;
@@ -52,4 +53,19 @@
    List<Taskqd> countTaskByJur(@Param("jurisdiction") String jurisdiction, @Param("startTime") String startTime,@Param("period") String period);
    int getRealTime(String hdid);
    /**
     * 自定义分页查询
     * @param page
     * @param taskqd
     * @return
     */
    List<TaskqdVO> selectTaskQdPage(@Param("page")IPage<TaskqdVO> page,@Param("taskqd") TaskqdVO taskqd);
    /**
     * 导出任务数据
     * @param task
     * @return
     */
    List<TaskExcel> selectTaskList(@Param("task")TaskqdVO task);
}
src/main/java/org/springblade/modules/taskqd/mapper/TaskqdMapper.xml
@@ -209,4 +209,37 @@
        FROM sys_taskqd
        WHERE id = #{hdid}
    </select>
    <!--自定义分页查询-->
    <select id="selectTaskQdPage" resultType="org.springblade.modules.taskqd.vo.TaskqdVO">
        select * from sys_taskqd where 1=1
    </select>
    <!--导出任务数据-->
    <select id="selectTaskList" resultType="org.springblade.modules.taskqd.excel.TaskExcel">
        select
        st.id,st.rname,st.time,st.endtime,st.content,st.gathername,st.fname,st.integral,
        sr.role_name as trainName,
        case when rtype='0' then '正在进行'
         when rtype='1' then '已结束'
         when rtype='2' then '任务未开始'
        end as rtypeName,
        sj.dept_name as jurisdictionName
        from sys_taskqd st
        left join sys_jurisdiction sj on sj.id = st.jurisdiction
        left join blade_role sr on sr.id = st.train
        where 1=1
        <if test="task.tasktype!=null and task.tasktype!=''">
            and st.tasktype = #{task.tasktype}
        </if>
        <if test="task.rtype!=null and task.rtype!=''">
            and st.rtype = #{task.rtype}
        </if>
        <if test="task.rname!=null and task.rname!=''">
            and st.rname like concat('%',#{task.rname},'%')
        </if>
        <if test="task.jurisdiction!=null and task.jurisdiction!=''">
            and st.jurisdiction = #{task.jurisdiction}
        </if>
    </select>
</mapper>
src/main/java/org/springblade/modules/taskqd/service/ITaskqdService.java
@@ -16,8 +16,10 @@
 */
package org.springblade.modules.taskqd.service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.IService;
import org.springblade.modules.taskqd.entity.Taskqd;
import org.springblade.modules.taskqd.excel.TaskExcel;
import org.springblade.modules.taskqd.vo.TaskqdVO;
import java.util.Date;
@@ -46,4 +48,19 @@
    List<Taskqd> countTaskByJur(String jurisdiction, String startTime, String period);
    int getRealTime(String hdid);
    /**
     * 自定义分页查询
     * @param taskqd
     * @param page
     * @return
     */
    Object selectTaskQdPage(IPage<TaskqdVO> page, TaskqdVO taskqd);
    /**
     * 导出任务数据
     * @param task
     * @return
     */
    List<TaskExcel> exportTask(TaskqdVO task);
}
src/main/java/org/springblade/modules/taskqd/service/impl/TaskqdServiceImpl.java
@@ -16,8 +16,10 @@
 */
package org.springblade.modules.taskqd.service.impl;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springblade.modules.taskqd.entity.Taskqd;
import org.springblade.modules.taskqd.excel.TaskExcel;
import org.springblade.modules.taskqd.mapper.TaskqdMapper;
import org.springblade.modules.taskqd.service.ITaskqdService;
import org.springblade.modules.taskqd.vo.TaskqdVO;
@@ -99,4 +101,28 @@
    public int getRealTime(String hdid) {
        return baseMapper.getRealTime(hdid);
    }
    /**
     * 自定义分页查询
     * @param taskqd
     * @param page
     * @return
     */
    @Override
    public Object selectTaskQdPage(IPage<TaskqdVO> page, TaskqdVO taskqd) {
        if (null!=taskqd.getIsPage()){
            return baseMapper.selectTaskQdPage(null,taskqd);
        }
        return page.setRecords(baseMapper.selectTaskQdPage(page,taskqd));
    }
    /**
     * 导出任务数据
     * @param task
     * @return
     */
    @Override
    public List<TaskExcel> exportTask(TaskqdVO task) {
        return baseMapper.selectTaskList(task);
    }
}
src/main/java/org/springblade/modules/taskqd/vo/TaskqdVO.java
@@ -37,4 +37,9 @@
    private String type;
    private Integer nums;
    /**
     * 是否分页查询
     */
    private Integer isPage;
}
src/main/resources/application-prod.yml
@@ -5,8 +5,8 @@
    #    host: 127.0.0.1
    #    port: 6379
    host: 192.168.90.24
    port: 6382
    host: 127.0.0.1
    port: 6379
    password:
    database: 0
    ssl: false
@@ -17,9 +17,9 @@
  datasource:
    # MySql
    #
    url: jdbc:mysql://36.134.81.48:3306/qfqkpublic?useSSL=false&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true&serverTimezone=GMT%2B8&nullCatalogMeansCurrent=true&allowPublicKeyRetrieval=true
    url: jdbc:mysql://127.0.0.1:3306/qfqkpublic?useSSL=false&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true&serverTimezone=GMT%2B8&nullCatalogMeansCurrent=true&allowPublicKeyRetrieval=true
    username: root
    password: jfpt123
    password: HCyj@2022
    #    url: jdbc:mysql://61.131.136.25:2083/qfqkpublic?useSSL=false&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true&serverTimezone=GMT%2B8&nullCatalogMeansCurrent=true&allowPublicKeyRetrieval=true&allowMultiQueries=true
    #    username: root
@@ -49,12 +49,13 @@
#ftp 设置
ftp:
  sqlConnect: jdbc:mysql://36.134.81.48:3306/qfqkpublic?useSSL=false&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true&serverTimezone=GMT%2B8&nullCatalogMeansCurrent=true&allowPublicKeyRetrieval=true
  sqlConnect: jdbc:mysql://106.225.193.35:3306/qfqkpublic?useSSL=false&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true&serverTimezone=GMT%2B8&nullCatalogMeansCurrent=true&allowPublicKeyRetrieval=true
  ftpHost: 117.40.91.118
  ftpPort: 21
  ftpUserName: zhbain
  ftpPassword: zhbain@123
  ftpPath: yly/qfqk/
  ftpBasePath: yly
  ftpFilePath: qfqk
  localPath: /home/zhongsong/qfqk/
  ip: http://47.49.21.216:9000
  jsonUrl: /home/zhongsong/qfqk/