| | |
| | | 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.apache.commons.collections4.MapUtils; |
| | | import org.apache.commons.lang.StringUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.core.io.ClassPathResource; |
| | | 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.File; |
| | | import java.io.InputStream; |
| | | import java.io.OutputStream; |
| | | import java.util.ArrayList; |
| | |
| | | } |
| | | return ResultBody.failed().msg(errMsg.toString()); |
| | | } else { |
| | | if (organizationInfo.getId() == null) { |
| | | //新增机构增加关注二维码 |
| | | String url = createQr(String.valueOf(organizationInfo.getId())); |
| | | if (StringUtils.isNotBlank(url)) { |
| | | organizationInfo.setQrCode(url); |
| | | } |
| | | } |
| | | boolean v = organizationInfoService.saveOrUpdate(organizationInfo); |
| | | if (v) { |
| | | if (StringUtils.isBlank(organizationInfo.getQrCode())) { |
| | | //新增机构增加关注二维码 |
| | | String url = createQr(String.valueOf(organizationInfo.getId())); |
| | | if (StringUtils.isNotBlank(url)) { |
| | | organizationInfo.setQrCode(url); |
| | | organizationInfoService.updateById(organizationInfo); |
| | | } |
| | | } |
| | | return ResultBody.ok().data(organizationInfo).msg("保存成功"); |
| | | } else { |
| | | return ResultBody.failed().msg("保存失败"); |
| | |
| | | } |
| | | |
| | | private String createQr(String id) { |
| | | log.info("***************创建筛查机构二维码开始*******************"); |
| | | String url = ""; |
| | | String str = "{\"action_name\": \"QR_LIMIT_STR_SCENE\", \"action_info\": {\"scene\": {\"scene_str\": \"kagscreening_\" " + id + "}}}"; |
| | | |
| | | String str = "{\"action_name\": \"QR_LIMIT_STR_SCENE\", \"action_info\": {\"scene\": {\"scene_str\": \"kagscreening_" + id + "\"}}}"; |
| | | log.info("***************创建筛查机构二维码参数" + str + "*******************"); |
| | | String token = redisUtils.get("Wechat:Token:KagReceiveToken").toString(); |
| | | String result = HttpRequest.post("https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=" + token) |
| | | .header("Content-Type", "application/json") |
| | | .body(str).execute().body(); |
| | | |
| | | |
| | | log.info("***************创建筛查机构二维码结果=>" + result); |
| | | if (StringUtils.isBlank(result)) { |
| | | return url; |
| | | } |
| | |
| | | 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) { |
| | | String[] area = areaCode.split("#"); |
| | | |
| | | list.forEach(u -> { |
| | | ScreeningOrganizationInfo organizationInfo = new ScreeningOrganizationInfo(); |
| | | BeanUtil.copyProperties(u, organizationInfo); |
| | | organizationInfo.setSourceHospitalName(hospitalName); |
| | | organizationInfo.setSourceHospitalId(Long.parseLong(hospitalId)); |
| | | organizationInfo.setProvince(area[0]); |
| | | organizationInfo.setCity(area[1]); |
| | | organizationInfo.setArea(area[2]); |
| | | organizationInfo.setAreaCode(areaName); |
| | | organizationInfoService.saveOrUpdate(organizationInfo); |
| | | if (StringUtils.isBlank(organizationInfo.getQrCode())) { |
| | | organizationInfo.setQrCode(createQr(String.valueOf(organizationInfo.getId()))); |
| | | organizationInfoService.updateById(organizationInfo); |
| | | } |
| | | }); |
| | | |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("导入失败", e); |
| | | } |
| | | return ResultBody.ok().msg("导入数据成功,一共【" + rowNum + "】行"); |
| | | } |
| | | |
| | | /** |
| | | * 下载模板 |
| | | */ |
| | | @ApiOperation(value = "下载模板") |
| | | @PostMapping("/export") |
| | | public void export(HttpServletResponse response) { |
| | | try { |
| | | InputStream inStream = null; |
| | | ClassPathResource resource = new ClassPathResource(File.separator + "template" + File.separator + "机构导入模板.xlsx"); |
| | | if (resource.exists()) { |
| | | inStream = resource.getInputStream(); |
| | | } |
| | | // 设置输出的格式 |
| | | 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(); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 通过医院ID查询机构列表 |
| | | */ |
| | | @ApiOperation(value = "通过医院ID查询机构列表") |
| | | @PostMapping("/getOrganizationListByHospitalId") |
| | | public ResultBody getOrganizationListByHospitalId(@RequestBody String id) { |
| | | List<ScreeningOrganizationInfo> byHospitalId = organizationInfoService.findByHospitalId(Long.valueOf(id)); |
| | | if (byHospitalId != null && byHospitalId.size() > 0) { |
| | | return ResultBody.ok().data(byHospitalId).msg("查询成功"); |
| | | } |
| | | return ResultBody.failed().msg("查询失败"); |
| | | } |
| | | |
| | | /** |
| | | * 关键字查询列表 |
| | | */ |
| | | @ApiOperation(value = "关键字查询列表") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "page", value = "分页起始位置", required = true, dataType = "Integer"), |
| | | @ApiImplicitParam(name = "limit", value = "分页结束位置", required = true, dataType = "Integer") |
| | | }) |
| | | @PostMapping(value = "/listByKeyWord") |
| | | public PageResult<ScreeningOrganizationInfo> listByKeyWord(@RequestParam Map<String, Object> params) { |
| | | if (params.size() == 0) { |
| | | params.put("page", 1); |
| | | params.put("limit", 10); |
| | | } |
| | | return organizationInfoService.findByKeyWord(params); |
| | | } |
| | | } |