diff --git a/src/main/java/com/glxp/api/constant/RedissonCacheKey.java b/src/main/java/com/glxp/api/constant/RedissonCacheKey.java index 8d889c4d..d8a96798 100644 --- a/src/main/java/com/glxp/api/constant/RedissonCacheKey.java +++ b/src/main/java/com/glxp/api/constant/RedissonCacheKey.java @@ -43,4 +43,16 @@ public interface RedissonCacheKey { * 复制单据 */ String COPY_ORDER = "copy_order"; + + + /** + * 下载患者信息 + */ + String DL_SICKER = "dl_sicker"; + + /** + * 下载患者处方 + */ + String DL_SICKER_PRECRIBE = "dl_sicker_precribe"; + } diff --git a/src/main/java/com/glxp/api/controller/basic/BasicSickerController.java b/src/main/java/com/glxp/api/controller/basic/BasicSickerController.java index 28ea1b4e..7d357bd8 100644 --- a/src/main/java/com/glxp/api/controller/basic/BasicSickerController.java +++ b/src/main/java/com/glxp/api/controller/basic/BasicSickerController.java @@ -1,19 +1,19 @@ package com.glxp.api.controller.basic; -import cn.hutool.core.util.IdUtil; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import cn.hutool.core.thread.ThreadUtil; import com.github.pagehelper.PageInfo; +import com.glxp.api.annotation.CusRedissonAnnotation; import com.glxp.api.common.enums.ResultEnum; import com.glxp.api.common.res.BaseResponse; import com.glxp.api.common.util.ResultVOUtils; +import com.glxp.api.constant.RedissonCacheKey; import com.glxp.api.controller.BaseController; -import com.glxp.api.entity.auth.AuthAdmin; -import com.glxp.api.entity.basic.BasicSkSickerEntity; import com.glxp.api.req.basic.BasicSkSickerRequest; +import com.glxp.api.req.basic.GetSickRequest; import com.glxp.api.res.PageSimpleResponse; import com.glxp.api.res.basic.BasicSkSickerResponse; -import com.glxp.api.service.basic.BasicSkPrescribeService; import com.glxp.api.service.basic.BasicSkSickerService; +import lombok.extern.slf4j.Slf4j; import org.springframework.validation.BindingResult; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; @@ -21,9 +21,9 @@ import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RestController; import javax.annotation.Resource; -import java.util.Date; import java.util.List; +@Slf4j @RestController public class BasicSickerController extends BaseController { @@ -41,4 +41,18 @@ public class BasicSickerController extends BaseController { return ResultVOUtils.success(pageSimpleResponse); } + @CusRedissonAnnotation(cacheName = RedissonCacheKey.DL_SICKER, key = {"#getSickRequest.thirdSys"}, waitTime = 3, timeOutMsg = "后台正在下载,请勿重复提交") + @PostMapping("/udiwms/basic/sk/sicker/download") + public BaseResponse sickerDl(@RequestBody GetSickRequest getSickRequest, BindingResult bindingResult) { + + if (bindingResult.hasErrors()) { + return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, bindingResult.getFieldError().getDefaultMessage()); + } + ThreadUtil.execAsync(() -> { + basicSkSickerService.downloadSicker(getSickRequest); + }); + return ResultVOUtils.success("后台已开始下载,请稍后刷新查看!"); + } + + } diff --git a/src/main/java/com/glxp/api/controller/basic/BasicSkPrescribeController.java b/src/main/java/com/glxp/api/controller/basic/BasicSkPrescribeController.java index dc6ae4fd..7205f169 100644 --- a/src/main/java/com/glxp/api/controller/basic/BasicSkPrescribeController.java +++ b/src/main/java/com/glxp/api/controller/basic/BasicSkPrescribeController.java @@ -1,16 +1,22 @@ package com.glxp.api.controller.basic; import cn.hutool.core.bean.BeanUtil; +import cn.hutool.core.thread.ThreadUtil; import cn.hutool.core.util.StrUtil; import com.github.pagehelper.PageInfo; +import com.glxp.api.annotation.CusRedissonAnnotation; import com.glxp.api.common.enums.ResultEnum; import com.glxp.api.common.res.BaseResponse; import com.glxp.api.common.util.ResultVOUtils; +import com.glxp.api.constant.RedissonCacheKey; import com.glxp.api.controller.BaseController; import com.glxp.api.entity.basic.BasicSkPrescribeEntity; import com.glxp.api.entity.basic.BasicSkPrescribeItemEntity; import com.glxp.api.entity.basic.BasicSkSickerEntity; +import com.glxp.api.req.basic.BasicProductTypeRequest; import com.glxp.api.req.basic.BasicSkPrescribeRequest; +import com.glxp.api.req.basic.GetSickPrescribeRequest; +import com.glxp.api.req.basic.GetSickRequest; import com.glxp.api.res.PageSimpleResponse; import com.glxp.api.res.basic.BasicSkPrescribeResponse; import com.glxp.api.res.basic.BasicSkSickerResponse; @@ -20,6 +26,8 @@ import com.glxp.api.service.basic.BasicSkSickerService; import com.glxp.api.vo.basic.BasicSkPrescribeDetailVo; import org.springframework.validation.BindingResult; import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RestController; import javax.annotation.Resource; @@ -72,4 +80,18 @@ public class BasicSkPrescribeController extends BaseController { } + @CusRedissonAnnotation(cacheName = RedissonCacheKey.DL_SICKER_PRECRIBE, key = {"#getSickPrescribeRequest.sickCode"}, waitTime = 3, timeOutMsg = "后台正在下载,请勿重复提交") + @PostMapping("/udiwms/basic/sk/prescribe/download") + public BaseResponse sickerPrescribeDl(@RequestBody GetSickPrescribeRequest getSickPrescribeRequest, BindingResult bindingResult) { + + if (bindingResult.hasErrors()) { + return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, bindingResult.getFieldError().getDefaultMessage()); + } + ThreadUtil.execAsync(() -> { + basicSkPrescribeService.downloadSickerPrescribe(getSickPrescribeRequest); + }); + return ResultVOUtils.success("后台已开始下载,请稍后刷新查看!"); + } + + } diff --git a/src/main/java/com/glxp/api/dao/basic/BasicSkPrescribeMapper.java b/src/main/java/com/glxp/api/dao/basic/BasicSkPrescribeMapper.java index 5cab3e92..b494daaf 100644 --- a/src/main/java/com/glxp/api/dao/basic/BasicSkPrescribeMapper.java +++ b/src/main/java/com/glxp/api/dao/basic/BasicSkPrescribeMapper.java @@ -1,6 +1,7 @@ package com.glxp.api.dao.basic; import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.glxp.api.dao.BaseMapperPlus; import com.glxp.api.entity.basic.BasicSkPrescribeEntity; import com.glxp.api.req.basic.BasicSkPrescribeRequest; import com.glxp.api.res.basic.BasicSkPrescribeResponse; @@ -9,7 +10,7 @@ import org.apache.ibatis.annotations.Mapper; import java.util.List; @Mapper -public interface BasicSkPrescribeMapper extends BaseMapper { +public interface BasicSkPrescribeMapper extends BaseMapperPlus { List filterList(BasicSkPrescribeRequest basicSkPrescribeRequest); diff --git a/src/main/java/com/glxp/api/dao/basic/BasicSkSickerMapper.java b/src/main/java/com/glxp/api/dao/basic/BasicSkSickerMapper.java index 6fb9d9d7..733ebcbd 100644 --- a/src/main/java/com/glxp/api/dao/basic/BasicSkSickerMapper.java +++ b/src/main/java/com/glxp/api/dao/basic/BasicSkSickerMapper.java @@ -1,6 +1,7 @@ package com.glxp.api.dao.basic; import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.glxp.api.dao.BaseMapperPlus; import com.glxp.api.entity.basic.BasicSkSickerEntity; import com.glxp.api.req.basic.BasicSkSickerRequest; import com.glxp.api.res.basic.BasicSkSickerResponse; @@ -9,7 +10,7 @@ import org.apache.ibatis.annotations.Mapper; import java.util.List; @Mapper -public interface BasicSkSickerMapper extends BaseMapper { +public interface BasicSkSickerMapper extends BaseMapperPlus { List filterList(BasicSkSickerRequest basicSkSickerRequest); diff --git a/src/main/java/com/glxp/api/http/ErpBasicClient.java b/src/main/java/com/glxp/api/http/ErpBasicClient.java index 45127efd..e99da0b8 100644 --- a/src/main/java/com/glxp/api/http/ErpBasicClient.java +++ b/src/main/java/com/glxp/api/http/ErpBasicClient.java @@ -9,8 +9,12 @@ import com.glxp.api.entity.thrsys.ThrSystemBusApiEntity; import com.glxp.api.entity.thrsys.ThrSystemEntity; import com.glxp.api.http.req.UdiwmsBusTypeRequest; import com.glxp.api.http.req.UdiwmsUnitRequest; +import com.glxp.api.req.basic.GetSickPrescribeRequest; +import com.glxp.api.req.basic.GetSickRequest; import com.glxp.api.req.thrsys.*; import com.glxp.api.res.PageSimpleResponse; +import com.glxp.api.res.basic.BasicSkPrescribeResponse; +import com.glxp.api.res.basic.BasicSkSickerResponse; import com.glxp.api.res.thrsys.ThrCorpsResponse; import com.glxp.api.res.thrsys.ThrProductsResponse; import com.glxp.api.res.thrsys.UdiwmsWarehouseDetail; @@ -95,6 +99,51 @@ public class ErpBasicClient { } } + /** + * 获取患者信息 + * + * @param getSickRequest + * @return + */ + public BaseResponse> getSicker(GetSickRequest getSickRequest) { + ThrSystemEntity basicThirdSysEntity = basicThirdSysService.selectByThirdId(getSickRequest.getThirdSys()); + String url = basicThirdSysEntity.getThridUrl() + "/udiwms/erp/sicker/getInfo"; + try { + String response = httpOkClient.uCloudPost(url, getSickRequest); + BaseResponse> listBaseResponse = + JSONObject.parseObject(response, new TypeReference>>() { + }); + + return listBaseResponse; + } catch (Exception e) { + log.error("获取患者信息异常", e); + return ResultVOUtils.error(500, "连接第三方系统接口服务出错"); + } + } + + + /** + * 获取患者处方信息 + * + * @param getSickPrescribeRequest + * @return + */ + public BaseResponse> getSickPrescribe(GetSickPrescribeRequest getSickPrescribeRequest) { + ThrSystemEntity basicThirdSysEntity = basicThirdSysService.selectByThirdId(getSickPrescribeRequest.getThirdSys()); + String url = basicThirdSysEntity.getThridUrl() + "/udiwms/erp/sicker/getPrescribe"; + try { + String response = httpOkClient.uCloudPost(url, getSickPrescribeRequest); + BaseResponse> listBaseResponse = + JSONObject.parseObject(response, new TypeReference>>() { + }); + + return listBaseResponse; + } catch (Exception e) { + log.error("获取患者处方信息", e); + return ResultVOUtils.error(500, "连接第三方系统接口服务出错"); + } + } + //测试连通性 public BaseResponse testConnection(ThrSystemEntity thrSystemEntity) { String response = httpOkClient.uCloudPost(thrSystemEntity.getThridUrl() + "/udiwms/erp/testLocal", "{}"); diff --git a/src/main/java/com/glxp/api/req/basic/GetSickPrescribeRequest.java b/src/main/java/com/glxp/api/req/basic/GetSickPrescribeRequest.java new file mode 100644 index 00000000..0dfac2cb --- /dev/null +++ b/src/main/java/com/glxp/api/req/basic/GetSickPrescribeRequest.java @@ -0,0 +1,16 @@ +package com.glxp.api.req.basic; + +import com.glxp.api.util.page.ListPageRequest; +import lombok.Data; + +@Data +public class GetSickPrescribeRequest extends ListPageRequest { + + private String code; + private String sickName; + private String sickCode; + private String idNum; + private String phone; + private String searchTime; + private String thirdSys; +} diff --git a/src/main/java/com/glxp/api/req/basic/GetSickRequest.java b/src/main/java/com/glxp/api/req/basic/GetSickRequest.java new file mode 100644 index 00000000..1f9e8af0 --- /dev/null +++ b/src/main/java/com/glxp/api/req/basic/GetSickRequest.java @@ -0,0 +1,20 @@ +package com.glxp.api.req.basic; + +import com.glxp.api.util.page.ListPageRequest; +import lombok.Data; + +@Data +public class GetSickRequest extends ListPageRequest { + + + private String code; + private String name; + private String adNum; + private String idNum; + private String phone; + private String searchTime; + + private String thirdSys; + + +} diff --git a/src/main/java/com/glxp/api/service/basic/BasicSkPrescribeService.java b/src/main/java/com/glxp/api/service/basic/BasicSkPrescribeService.java index 67ddf3df..865fd134 100644 --- a/src/main/java/com/glxp/api/service/basic/BasicSkPrescribeService.java +++ b/src/main/java/com/glxp/api/service/basic/BasicSkPrescribeService.java @@ -1,23 +1,47 @@ package com.glxp.api.service.basic; +import cn.hutool.core.bean.BeanUtil; +import cn.hutool.core.bean.copier.CopyOptions; +import cn.hutool.core.util.IdUtil; +import cn.hutool.core.util.StrUtil; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.github.pagehelper.PageHelper; +import com.glxp.api.common.res.BaseResponse; +import com.glxp.api.common.util.ResultVOUtils; import com.glxp.api.dao.basic.BasicSkProjectMapper; +import com.glxp.api.entity.basic.BasicSkSickerEntity; +import com.glxp.api.entity.basic.UdiRelevanceEntity; +import com.glxp.api.entity.thrsys.ThrProductsEntity; +import com.glxp.api.http.ErpBasicClient; import com.glxp.api.req.basic.BasicSkPrescribeRequest; import com.glxp.api.req.basic.BasicSkProjectRequest; +import com.glxp.api.req.basic.GetSickPrescribeRequest; +import com.glxp.api.req.basic.GetSickRequest; +import com.glxp.api.req.thrsys.FilterThrProductsRequest; +import com.glxp.api.res.PageSimpleResponse; import com.glxp.api.res.basic.BasicSkPrescribeResponse; import com.glxp.api.res.basic.BasicSkProjectResponse; +import com.glxp.api.res.basic.BasicSkSickerResponse; +import com.glxp.api.res.thrsys.ThrProductsResponse; +import com.glxp.api.util.IntUtil; +import org.springframework.beans.BeanUtils; import org.springframework.stereotype.Service; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.glxp.api.entity.basic.BasicSkPrescribeEntity; import com.glxp.api.dao.basic.BasicSkPrescribeMapper; import javax.annotation.Resource; +import java.util.ArrayList; import java.util.Collections; +import java.util.Date; import java.util.List; @Service public class BasicSkPrescribeService extends ServiceImpl { + @Resource + ErpBasicClient erpBasicClient; + public List filterList(BasicSkPrescribeRequest basicSkPrescribeRequest) { if (basicSkPrescribeRequest == null) { return Collections.emptyList(); @@ -29,4 +53,38 @@ public class BasicSkPrescribeService extends ServiceImpl data = super.baseMapper.filterList(basicSkPrescribeRequest); return data; } + + + public BaseResponse downloadSickerPrescribe(GetSickPrescribeRequest request) { + int page = 1; + int limit = 200; + request.setThirdSys("thirdId"); + request.setLimit(limit); + while (true) { + request.setPage(page); + BaseResponse> baseResponse = erpBasicClient.getSickPrescribe(request); + if (baseResponse.getCode() == 20000) { + List list = baseResponse.getData().getList(); + + List basicSkPrescribeEntities = new ArrayList<>(); + + list.forEach(item -> { + BasicSkPrescribeEntity basicSkSickerEntity = new BasicSkPrescribeEntity(); + BeanUtil.copyProperties(item, basicSkSickerEntity); + //todo 数据转换 + basicSkPrescribeEntities.add(basicSkSickerEntity); + }); + if (list.size() >= limit && !baseResponse.getData().getTotal().equals(-666)) { + super.baseMapper.replaceBatchs(basicSkPrescribeEntities); + page++; + } else { + break; + } + } else { + return ResultVOUtils.error(500, "下载异常中断"); + } + } + return ResultVOUtils.success("下载成功!"); + } + } diff --git a/src/main/java/com/glxp/api/service/basic/BasicSkSickerService.java b/src/main/java/com/glxp/api/service/basic/BasicSkSickerService.java index 5199096c..6152c461 100644 --- a/src/main/java/com/glxp/api/service/basic/BasicSkSickerService.java +++ b/src/main/java/com/glxp/api/service/basic/BasicSkSickerService.java @@ -1,9 +1,16 @@ package com.glxp.api.service.basic; +import cn.hutool.core.bean.BeanUtil; import com.github.pagehelper.PageHelper; +import com.glxp.api.common.res.BaseResponse; +import com.glxp.api.common.util.ResultVOUtils; import com.glxp.api.dao.basic.BasicSkProjectMapper; +import com.glxp.api.entity.basic.BasicSkPrescribeEntity; +import com.glxp.api.http.ErpBasicClient; import com.glxp.api.req.basic.BasicSkProjectRequest; import com.glxp.api.req.basic.BasicSkSickerRequest; +import com.glxp.api.req.basic.GetSickRequest; +import com.glxp.api.res.PageSimpleResponse; import com.glxp.api.res.basic.BasicSkProjectResponse; import com.glxp.api.res.basic.BasicSkSickerResponse; import org.springframework.stereotype.Service; @@ -12,6 +19,7 @@ import com.glxp.api.entity.basic.BasicSkSickerEntity; import com.glxp.api.dao.basic.BasicSkSickerMapper; import javax.annotation.Resource; +import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -19,6 +27,8 @@ import java.util.List; public class BasicSkSickerService extends ServiceImpl { @Resource BasicSkSickerMapper basicSkSickerMapper; + @Resource + ErpBasicClient erpBasicClient; public List filterList(BasicSkSickerRequest basicSkSickerRequest) { if (basicSkSickerRequest == null) { @@ -31,4 +41,38 @@ public class BasicSkSickerService extends ServiceImpl data = basicSkSickerMapper.filterList(basicSkSickerRequest); return data; } + + + public BaseResponse downloadSicker(GetSickRequest request) { + int page = 1; + int limit = 200; + request.setThirdSys("thirdId"); + request.setLimit(limit); + while (true) { + request.setPage(page); + BaseResponse> baseResponse = erpBasicClient.getSicker(request); + if (baseResponse.getCode() == 20000) { + List list = baseResponse.getData().getList(); + + List basicSkSickerEntities = new ArrayList<>(); + + list.forEach(item -> { + BasicSkSickerEntity basicSkSickerEntity = new BasicSkSickerEntity(); + BeanUtil.copyProperties(item, basicSkSickerEntity); + //todo 数据转换 + basicSkSickerEntities.add(basicSkSickerEntity); + }); + if (list.size() >= limit && !baseResponse.getData().getTotal().equals(-666)) { + basicSkSickerMapper.replaceBatchs(basicSkSickerEntities); + page++; + } else { + break; + } + } else { + return ResultVOUtils.error(500, "下载异常中断"); + } + } + return ResultVOUtils.success("下载成功!"); + } + }