InsureLogController.java 4.6 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 23
import cn.timer.api.dto.insure.PolicyLogDto;
import cn.timer.api.utils.Page;
翁国栋 committed
24 25 26 27 28
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
29
import com.google.common.collect.Maps;
翁国栋 committed
30 31
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
翁国栋 committed
32
import org.apache.ibatis.annotations.Param;
翁国栋 committed
33
import org.springframework.beans.factory.annotation.Autowired;
翁国栋 committed
34 35
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
翁国栋 committed
36 37

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

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


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

翁国栋 committed
57
    @GetMapping(value = "/logList")
284718418@qq.com committed
58
    @ApiOperation(value = "12.日志列表", httpMethod = "GET", notes = "日志列表")
翁国栋 committed
59 60 61 62 63 64 65 66 67
    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
68
    @ApiOperation(value = "12.人员清单", httpMethod = "GET", notes = "人员清单")
翁国栋 committed
69 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
    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
112
    @ApiOperation(value = "日志列表--8小时端", httpMethod = "GET", notes = "日志列表")
翁国栋 committed
113 114 115 116 117 118 119
    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
120

翁国栋 committed
121

翁国栋 committed
122
}