| | |
| | | package com.kidgrow.oprationcenter.controller; |
| | | |
| | | import cn.hutool.core.bean.BeanUtil; |
| | | import cn.hutool.http.HttpRequest; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.kidgrow.common.controller.BaseController; |
| | | import com.kidgrow.common.model.PageResult; |
| | | import com.kidgrow.common.model.ResultBody; |
| | | import com.kidgrow.common.utils.ExcelUtil; |
| | | import com.kidgrow.common.utils.QRCodeUtil; |
| | | import com.kidgrow.oprationcenter.model.ScreeningOrganizationExcel; |
| | | import com.kidgrow.oprationcenter.model.ScreeningOrganizationInfo; |
| | | import com.kidgrow.oprationcenter.service.IScreeningOrganizationInfoService; |
| | | import com.kidgrow.redis.util.RedisUtils; |
| | |
| | | import org.springframework.validation.BindingResult; |
| | | import org.springframework.validation.ObjectError; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | import sun.misc.BASE64Decoder; |
| | | |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import javax.validation.Valid; |
| | | import java.io.ByteArrayInputStream; |
| | | import java.io.InputStream; |
| | | import java.io.OutputStream; |
| | | import java.io.*; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | |
| | | out = response.getOutputStream(); |
| | | fileInputStream = new ByteArrayInputStream(arr); |
| | | int len = 0; |
| | | byte[] by = new byte[1024*10]; |
| | | while ((len = fileInputStream.read(by))>0){ |
| | | out.write(by,0,len); |
| | | byte[] by = new byte[1024 * 10]; |
| | | while ((len = fileInputStream.read(by)) > 0) { |
| | | out.write(by, 0, len); |
| | | } |
| | | |
| | | }catch (Exception w){ |
| | | log.error("",w); |
| | | }finally { |
| | | } catch (Exception w) { |
| | | log.error("", w); |
| | | } finally { |
| | | try { |
| | | out.close(); |
| | | fileInputStream.close(); |
| | | }catch(Exception w){ |
| | | } catch (Exception w) { |
| | | |
| | | } |
| | | |
| | | } |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 导入文件 |
| | | */ |
| | | @ApiOperation(value = "导入") |
| | | @PostMapping("/import") |
| | | public ResultBody downLoad(@RequestParam("file") MultipartFile excel, |
| | | @RequestParam("hospitalId") String hospitalId, |
| | | @RequestParam("areaCode") String areaCode, |
| | | @RequestParam("areaName") String areaName, |
| | | @RequestParam("hospitalName") String hospitalName) { |
| | | |
| | | int rowNum = 0; |
| | | |
| | | try { |
| | | if (!excel.isEmpty()) { |
| | | List<ScreeningOrganizationExcel> list = ExcelUtil.importExcel(excel, 0, 1, ScreeningOrganizationExcel.class); |
| | | rowNum = list.size(); |
| | | if (rowNum > 0) { |
| | | List<ScreeningOrganizationInfo> users = new ArrayList<>(rowNum); |
| | | String[] area = areaCode.split("#"); |
| | | |
| | | list.forEach(u -> { |
| | | ScreeningOrganizationInfo user = new ScreeningOrganizationInfo(); |
| | | BeanUtil.copyProperties(u, user); |
| | | user.setSourceHospitalName(hospitalName); |
| | | user.setSourceHospitalId(Long.parseLong(hospitalId)); |
| | | user.setProvince(area[0]); |
| | | user.setCity(area[1]); |
| | | user.setArea(area[2]); |
| | | user.setAreaCode(areaName); |
| | | users.add(user); |
| | | }); |
| | | organizationInfoService.saveBatch(users); |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("导入失败", e); |
| | | } |
| | | return ResultBody.ok().msg("导入数据成功,一共【" + rowNum + "】行"); |
| | | } |
| | | |
| | | /** |
| | | * 下载模板 |
| | | */ |
| | | @ApiOperation(value = "下载模板") |
| | | @PostMapping("/export") |
| | | public void export(HttpServletResponse response) { |
| | | try { |
| | | InputStream inStream =this.getClass().getResourceAsStream("/static/pages/template/机构导入模板.xlsx"); |
| | | // 设置输出的格式 |
| | | response.reset(); |
| | | response.setContentType("bin"); |
| | | response.addHeader("Content-Disposition", "attachment; filename=机构导入模板.xlsx"); |
| | | // 循环取出流中的数据 |
| | | byte[] b = new byte[100]; |
| | | int len; |
| | | |
| | | while ((len = inStream.read(b)) > 0) { |
| | | response.getOutputStream().write(b, 0, len); |
| | | } |
| | | inStream.close(); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | } |