New file |
| | |
| | | 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 io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiImplicitParam; |
| | | import io.swagger.annotations.ApiImplicitParams; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.collections4.MapUtils; |
| | | import org.apache.commons.lang.StringUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | 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.*; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | |
| | | /** |
| | | * 石家庄喜高科技有限责任公司 版权所有 © Copyright 2020<br> |
| | | * |
| | | * @Description: 筛查机构信息表 |
| | | * @Project: 用户中心 |
| | | * @CreateDate: Created in 2020-10-12 17:10:31 <br> |
| | | * @Author: <a href="78125310@kidgrow.com">dougang</a> |
| | | * @version: 1.0 |
| | | */ |
| | | @Slf4j |
| | | @RestController |
| | | @RequestMapping("/screeningorganizationinfo") |
| | | @Api(tags = "筛查机构信息表") |
| | | public class ScreeningOrganizationInfoController extends BaseController { |
| | | @Autowired |
| | | private IScreeningOrganizationInfoService organizationInfoService; |
| | | |
| | | @Autowired |
| | | private RedisUtils redisUtils; |
| | | |
| | | private final String URL = "url"; |
| | | |
| | | /** |
| | | * 列表 |
| | | */ |
| | | @ApiOperation(value = "查询列表") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "page", value = "分页起始位置", required = true, dataType = "Integer"), |
| | | @ApiImplicitParam(name = "limit", value = "分页结束位置", required = true, dataType = "Integer") |
| | | }) |
| | | @GetMapping |
| | | public PageResult<ScreeningOrganizationInfo> list(@RequestParam Map<String, Object> params) { |
| | | if (params.size() == 0) { |
| | | params.put("page", 1); |
| | | params.put("limit", 10); |
| | | } |
| | | return organizationInfoService.findList(params); |
| | | } |
| | | |
| | | /** |
| | | * 查询 |
| | | */ |
| | | @ApiOperation(value = "查询") |
| | | @GetMapping("/{organizationId}") |
| | | public ResultBody findById(@PathVariable String organizationId) { |
| | | ScreeningOrganizationInfo model = organizationInfoService.getById(organizationId); |
| | | return ResultBody.ok().data(model).msg("查询成功"); |
| | | } |
| | | |
| | | /** |
| | | * 根据OrganizationInfo当做查询条件进行查询 |
| | | */ |
| | | @ApiOperation(value = "根据OrganizationInfo当做查询条件进行查询") |
| | | @PostMapping("/query") |
| | | public ResultBody findByObject(@RequestBody ScreeningOrganizationInfo organizationInfo) { |
| | | ScreeningOrganizationInfo model = organizationInfoService.findByObject(organizationInfo); |
| | | return ResultBody.ok().data(model).msg("查询成功"); |
| | | } |
| | | |
| | | /** |
| | | * 新增or更新 |
| | | */ |
| | | @ApiOperation(value = "保存") |
| | | @PostMapping |
| | | public ResultBody save(@Valid @RequestBody ScreeningOrganizationInfo organizationInfo, BindingResult bindingResult) { |
| | | List<String> errMsg = new ArrayList<>(); |
| | | if (bindingResult.hasErrors()) { |
| | | for (ObjectError error : bindingResult.getAllErrors()) { |
| | | errMsg.add(error.getDefaultMessage()); |
| | | } |
| | | 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) { |
| | | return ResultBody.ok().data(organizationInfo).msg("保存成功"); |
| | | } else { |
| | | return ResultBody.failed().msg("保存失败"); |
| | | } |
| | | } |
| | | } |
| | | |
| | | private String createQr(String id) { |
| | | String url = ""; |
| | | String str = "{\"action_name\": \"QR_LIMIT_STR_SCENE\", \"action_info\": {\"scene\": {\"scene_str\": \"kagscreening_\" " + id + "}}}"; |
| | | |
| | | 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(); |
| | | |
| | | |
| | | if (StringUtils.isBlank(result)) { |
| | | return url; |
| | | } |
| | | |
| | | JSONObject strJson = JSONObject.parseObject(result); |
| | | if (strJson.containsKey(URL)) { |
| | | url = strJson.getString("url"); |
| | | } |
| | | |
| | | return url; |
| | | } |
| | | |
| | | /** |
| | | * 删除 |
| | | */ |
| | | @ApiOperation(value = "删除") |
| | | @DeleteMapping("/{id}") |
| | | public ResultBody delete(@PathVariable String organizationId) { |
| | | boolean v = organizationInfoService.removeById(organizationId); |
| | | if (v) { |
| | | return ResultBody.ok().msg("删除成功"); |
| | | } else { |
| | | return ResultBody.failed().msg("删除失败"); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 下载二维码 |
| | | */ |
| | | @ApiOperation(value = "下载二维码") |
| | | @PostMapping("/downLoad") |
| | | public void downLoad(@RequestBody Map<String, Object> param, HttpServletResponse response) { |
| | | OutputStream out = null; |
| | | InputStream fileInputStream = null; |
| | | try { |
| | | String base64Str = QRCodeUtil.creatRrCode(MapUtils.getString(param, "url"), 258, 258, 3); |
| | | String fileName = MapUtils.getString(param, "no") + ".png"; |
| | | |
| | | BASE64Decoder dencoder = new BASE64Decoder(); |
| | | byte[] arr = dencoder.decodeBuffer(base64Str.split(",")[1]); |
| | | |
| | | // 设置输出的格式 |
| | | response.reset(); |
| | | response.setContentType("application/x-msdownload"); |
| | | response.addHeader("Content-Length", "" + arr.length); |
| | | response.addHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\""); |
| | | |
| | | 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); |
| | | } |
| | | |
| | | } catch (Exception w) { |
| | | log.error("", w); |
| | | } finally { |
| | | try { |
| | | out.close(); |
| | | fileInputStream.close(); |
| | | } 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(); |
| | | } |
| | | } |
| | | } |