InsureLogController.java 5.08 KB
Newer Older
翁国栋 committed
1 2
package cn.timer.api.controller.insure;

翁国栋 committed
3 4 5 6 7 8 9 10 11
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;
翁国栋 committed
12 13 14
import java.util.List;
import java.util.Map;

翁国栋 committed
15 16
import cn.timer.api.bean.insure.InsureLog;
import cn.timer.api.bean.insure.InsureProduct;
翁国栋 committed
17
import cn.timer.api.bean.qyzx.QyzxEntInfoM;
翁国栋 committed
18 19
import cn.timer.api.config.annotation.CurrentUser;
import cn.timer.api.config.annotation.UserBean;
翁国栋 committed
20
import cn.timer.api.dao.insure.InsureLogMapper;
翁国栋 committed
21
import cn.timer.api.dto.insure.InsureDto;
翁国栋 committed
22
import cn.timer.api.dto.insure.LogDto;
翁国栋 committed
23 24
import cn.timer.api.dto.insure.PolicyLogDto;
import cn.timer.api.utils.Page;
翁国栋 committed
25 26 27 28 29
import cn.timer.api.utils.Result;
import cn.timer.api.utils.ResultUtil;
import com.alibaba.fastjson.JSONObject;
import com.aliyun.oss.common.utils.StringUtils;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
翁国栋 committed
30
import com.google.common.collect.Maps;
翁国栋 committed
31 32
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
翁国栋 committed
33
import org.apache.ibatis.annotations.Param;
翁国栋 committed
34
import org.springframework.beans.factory.annotation.Autowired;
翁国栋 committed
35 36
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
翁国栋 committed
37 38

import org.springframework.stereotype.Controller;
翁国栋 committed
39
import org.springframework.web.multipart.MultipartFile;
翁国栋 committed
40

翁国栋 committed
41 42
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
翁国栋 committed
43 44 45 46 47 48 49


/**
 * @author wgd
 * @email 862422848@qq.com
 * @date 2022-03-22 09:55:46
 */
翁国栋 committed
50
@Api(tags = "8.0保险列表")
翁国栋 committed
51
@RestController
翁国栋 committed
52 53
@Transactional
@RequestMapping(value = "/insureLog", produces = {"application/json"})
翁国栋 committed
54 55 56
public class InsureLogController {
    @Autowired
    private InsureLogMapper insureLogMapper;
翁国栋 committed
57

翁国栋 committed
58
    @GetMapping(value = "/logList")
284718418@qq.com committed
59
    @ApiOperation(value = "12.日志列表", httpMethod = "GET", notes = "日志列表")
翁国栋 committed
60 61 62 63 64 65 66 67 68
    public Result<Object> logList(@RequestParam("policyId") String policyId) {
        List<InsureLog> list = insureLogMapper.selectListById(policyId);
        if (list.size() > 0) {
            return ResultUtil.data(list);
        }
        return ResultUtil.error("暂无日志");
    }

    @GetMapping(value = "/downUserExcel")
284718418@qq.com committed
69
    @ApiOperation(value = "12.人员清单", httpMethod = "GET", notes = "人员清单")
翁国栋 committed
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
    public void downUserExcel(@RequestParam("logId") String logId, HttpServletRequest request, HttpServletResponse response) {
        InsureLog insureLog = InsureLog.builder().id(Integer.parseInt(logId)).build().selectById();
        if (insureLog == null || StringUtils.isNullOrEmpty(insureLog.getFileUrl())) {
            return;
        }
        DateTimeFormatter dtf2 = DateTimeFormatter.ofPattern("yyyyMMddHHmmss");
        OutputStream sos = null;
        BufferedInputStream bis = null;
        try {
            response.setContentType("application/octet-stream");
            response.setHeader("content-disposition", "attachment; filename=" + new String((dtf2.format(LocalDateTime.now()) + ".xlsx").getBytes("UTF8"), "ISO-8859-1"));
            response.setCharacterEncoding("UTF-8");
            sos = response.getOutputStream();
            String destUrl = "http:" + insureLog.getFileUrl();
            URL url = new URL(destUrl);
            HttpURLConnection httpUrl = (HttpURLConnection) url.openConnection();
            //连接指定的网络资源
            httpUrl.connect();
            //获取网络输入流
            bis = new BufferedInputStream(httpUrl.getInputStream());
            int b;
            while ((b = bis.read()) != -1) {
                sos.write(b);
            }
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                sos.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
            try {
                bis.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    @PostMapping(value = "/insureLogList")
284718418@qq.com committed
113
    @ApiOperation(value = "日志列表--8小时端", httpMethod = "GET", notes = "日志列表")
翁国栋 committed
114 115 116 117 118 119 120
    public Result<Object> insureLogList(@CurrentUser UserBean userBean, @RequestBody Page page) {
        Map map = Maps.newHashMap();
        List<PolicyLogDto> list = insureLogMapper.selectLogListByOrgCode(userBean.getOrgCode(),page);
        map.put("list", list);
        map.put("total", insureLogMapper.selectLogTotalByOrgCode(userBean.getOrgCode()));
        return ResultUtil.data(map);
    }
翁国栋 committed
121

翁国栋 committed
122 123 124 125 126 127 128 129 130
    @PostMapping(value = "/actionLogList")
    @ApiOperation(value = "操作列表--运营后台", httpMethod = "GET", notes = "日志列表")
    public Result<Object> actionLogList(@RequestBody LogDto logDto) {
        Map map = Maps.newHashMap();
        List<InsureLog>  list=insureLogMapper.logList(logDto);
        map.put("list", list);
        map.put("totalNum",insureLogMapper.logListTotal(logDto));
        return ResultUtil.data(map);
    }
翁国栋 committed
131
}