|
@@ -31,6 +31,7 @@ import com.fs.im.service.IImService;
|
|
|
import com.fs.system.oss.CloudStorageService;
|
|
|
import com.fs.system.oss.OSSFactory;
|
|
|
import com.google.zxing.WriterException;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.aop.framework.AopContext;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.context.annotation.Lazy;
|
|
@@ -38,6 +39,7 @@ import org.springframework.scheduling.annotation.Async;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Propagation;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
import javax.imageio.ImageIO;
|
|
|
import java.awt.*;
|
|
@@ -57,6 +59,7 @@ import java.util.List;
|
|
|
* @date 2023-06-13
|
|
|
*/
|
|
|
@Service
|
|
|
+@Slf4j
|
|
|
public class FsPrescribeServiceImpl implements IFsPrescribeService
|
|
|
{
|
|
|
@Autowired
|
|
@@ -396,7 +399,8 @@ public class FsPrescribeServiceImpl implements IFsPrescribeService
|
|
|
public String PrescribeImg(Long PrescribeId){
|
|
|
FsPrescribeVO f = fsPrescribeMapper.selectFsPrescribeByPrescribeIdVO(PrescribeId);
|
|
|
if (f==null){
|
|
|
- return "";
|
|
|
+ log.error("[生成处方图片] 订单号 {} 找不到",PrescribeId);
|
|
|
+ throw new IllegalArgumentException(String.format("[生成处方图片] 处方单号 %d 找不到",PrescribeId));
|
|
|
}
|
|
|
FsStoreOrder fsStoreOrder = storeOrderService.selectFsStoreOrderByOrderId(f.getStoreOrderId());
|
|
|
FsInquiryOrderVO order = fsInquiryOrderMapper.selectFsInquiryOrderVOByOrderId(f.getInquiryOrderId());
|
|
@@ -412,8 +416,9 @@ public class FsPrescribeServiceImpl implements IFsPrescribeService
|
|
|
// list.add(fsPrescribeDrug);
|
|
|
// }
|
|
|
// }
|
|
|
- if (list.size()==0){
|
|
|
- return "";
|
|
|
+ if(CollectionUtils.isEmpty(list)) {
|
|
|
+ log.error(String.format("[生成处方图片] 当前处方单 %d 找不到药品数据 %s",PrescribeId,JSON.toJSONString(list)));
|
|
|
+ throw new IllegalArgumentException(String.format("[生成处方图片] 当前处方单 %d 找不到药品数据 %s",PrescribeId,JSON.toJSONString(list)));
|
|
|
}
|
|
|
if (f.getPrescribeType()==1){
|
|
|
PrescribeXyImgParam o = new PrescribeXyImgParam();
|
|
@@ -436,7 +441,7 @@ public class FsPrescribeServiceImpl implements IFsPrescribeService
|
|
|
FsPrescribeUsageDTO usage = JSONUtil.toBean(f.getUsageJson(), FsPrescribeUsageDTO.class);
|
|
|
remark=usage.getRemark();
|
|
|
}
|
|
|
- if (remark!=null&&remark!=""){
|
|
|
+ if (StringUtils.isNotBlank(remark)){
|
|
|
o.setRemark(remark);
|
|
|
}else {
|
|
|
o.setRemark("请按照用药说明书服用药品,如有不适,请及时就医!");
|
|
@@ -901,20 +906,129 @@ public class FsPrescribeServiceImpl implements IFsPrescribeService
|
|
|
|
|
|
@Override
|
|
|
public void auditPrescribe() {
|
|
|
+ log.info("自动审方定时任务开始执行");
|
|
|
+
|
|
|
List<FsPrescribe> FsPrescribes=fsPrescribeDrugMapper.selectFsPrescribeNoAudit();
|
|
|
+ log.info("查询到待审核处方数量:{}", FsPrescribes.size());
|
|
|
+
|
|
|
+ IFsPrescribeService fsPrescribeService = (IFsPrescribeService) AopContext.currentProxy();
|
|
|
for (FsPrescribe fsPrescribe : FsPrescribes) {
|
|
|
+ log.info("开始处理处方单,处方ID:{}", fsPrescribe.getPrescribeId());
|
|
|
+
|
|
|
Long id = doctorMapper.selectFsDoctorType2Ids(fsPrescribe.getPrescribeType());
|
|
|
+ log.info("获取到处方类型对应的医生ID:{}", id);
|
|
|
+
|
|
|
FsPrescribeAuditParam param=new FsPrescribeAuditParam();
|
|
|
param.setDoctorId(id);
|
|
|
param.setStatus(1);
|
|
|
param.setPrescribeId(fsPrescribe.getPrescribeId());
|
|
|
- IFsPrescribeService fsPrescribeService = (IFsPrescribeService) AopContext.currentProxy();
|
|
|
- // 创建订单 & 发送消息
|
|
|
- fsPrescribeService.audit(param);
|
|
|
+ log.info("构建审方参数:医生ID={}, 处方ID={}, 状态={}", id, fsPrescribe.getPrescribeId(), 1);
|
|
|
+
|
|
|
+ try{
|
|
|
+ fsPrescribeService.generateOrderAndPres(param, id);
|
|
|
+ }catch (Throwable e) {
|
|
|
+ log.error("生成处方订单和处方图片失败!参数: {}",param,e);
|
|
|
+ }
|
|
|
+
|
|
|
+ try{
|
|
|
+ sendImMsg(fsPrescribeService, fsPrescribe.getPrescribeId());
|
|
|
+ }catch (Exception e) {
|
|
|
+ log.error("发送IM失败 {}",fsPrescribe,e);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void sendImMsg(IFsPrescribeService fsPrescribeService, Long prescribeId) {
|
|
|
+ log.info("开始发送IM消息,处方ID: {}", prescribeId);
|
|
|
+
|
|
|
+ //IM发送消息
|
|
|
+ FsPrescribe prescribe = fsPrescribeService.selectFsPrescribeByPrescribeId(prescribeId);
|
|
|
+ log.info("查询到处方信息: {}", prescribe);
|
|
|
+
|
|
|
+ //发送信息
|
|
|
+ String orderId=prescribe.getInquiryOrderId().toString();
|
|
|
+ MsgDTO msgDTO=new MsgDTO();
|
|
|
+ MsgCustomDTO customDTO=new MsgCustomDTO();
|
|
|
+ FsInquiryOrder fsInquiryOrder = fsInquiryOrderMapper.selectFsInquiryOrderByOrderId(prescribe.getInquiryOrderId());
|
|
|
+ customDTO.setType("inquiry");
|
|
|
+ customDTO.setOrderId(orderId);
|
|
|
+ customDTO.setImType(1);
|
|
|
+ customDTO.setOrderType(fsInquiryOrder.getOrderType());
|
|
|
+ msgDTO.setCloudCustomData(JSONUtil.toJsonStr(customDTO));
|
|
|
+ msgDTO.setFrom_Account("D-"+prescribe.getDoctorId());
|
|
|
+ msgDTO.setTo_Account("U-"+prescribe.getUserId());
|
|
|
+ List<MsgDataDTO> msgs=new ArrayList<>();
|
|
|
+ MsgDataDTO msg=new MsgDataDTO();
|
|
|
+ String ext= JSONUtil.toJsonStr(prescribe);
|
|
|
+
|
|
|
+ msg.setMsgContent(new MsgDataFormatDTO("prescribe",ext,orderId));
|
|
|
+ msg.setMsgType("TIMCustomElem");//TIMCustomElem
|
|
|
+ msgs.add(msg);
|
|
|
+ msgDTO.setMsgBody(msgs);
|
|
|
+ log.info("准备调用IM发送消息接口,发送方: {}, 接收方: {}, 问诊单号: {}",
|
|
|
+ msgDTO.getFrom_Account(), msgDTO.getTo_Account(), orderId);
|
|
|
+ imService.sendMsg(msgDTO);
|
|
|
+ log.info("IM消息发送完成,问诊单号: {}", orderId);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void generatePrescribeImg(){
|
|
|
+ log.info("处方图片生成定时任务开始执行");
|
|
|
+ long startTime = System.currentTimeMillis();
|
|
|
+
|
|
|
+ IFsPrescribeService fsPrescribeService = (IFsPrescribeService) AopContext.currentProxy();
|
|
|
+
|
|
|
+ List<FsPrescribe> fsPrescribes = fsPrescribeDrugMapper.selectPenddingPrescribeImgData();
|
|
|
+ log.info("待生成处方图片的数据量: {}", fsPrescribes.size());
|
|
|
+
|
|
|
+ for (FsPrescribe fsPrescribe : fsPrescribes) {
|
|
|
+ Long prescribeId = fsPrescribe.getPrescribeId();
|
|
|
+ log.info("开始处理处方单号: {}", prescribeId);
|
|
|
+ try {
|
|
|
+ fsPrescribeService.PrescribeImg(prescribeId);
|
|
|
+ log.info("处方单号: {} 图片生成成功", prescribeId);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("处方单号: {} 图片生成失败, 错误信息: {}", prescribeId, e.getMessage(), e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ long endTime = System.currentTimeMillis();
|
|
|
+ log.info("处方图片生成定时任务结束,共处理{}条数据,总耗时: {}毫秒", fsPrescribes.size(), (endTime - startTime));
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Throwable.class)
|
|
|
+ public void generateOrderAndPres(FsPrescribeAuditParam param, Long id) {
|
|
|
+ log.info("开始生成订单和处方单,处方单ID: {}, 参数: {}", param.getPrescribeId(), param);
|
|
|
+
|
|
|
+ IFsPrescribeService fsPrescribeService = (IFsPrescribeService) AopContext.currentProxy();
|
|
|
+ try{
|
|
|
+ log.info("开始创建订单,处方单ID: {}", param.getPrescribeId());
|
|
|
+ // 创建订单
|
|
|
+ fsPrescribeService.auditWithoutMsg(param);
|
|
|
+ log.info("创建订单成功,处方单ID: {}", param.getPrescribeId());
|
|
|
+
|
|
|
+ } catch (Throwable e) {
|
|
|
+ log.error("创建订单 发生异常 参数: {}", param,e);
|
|
|
+ throw e;
|
|
|
+ }
|
|
|
|
|
|
+ try{
|
|
|
// 生成处方单图片
|
|
|
- fsPrescribeService.PrescribeImg(id);
|
|
|
+ log.info("开始生成处方单图片,处方单ID: {}", param.getPrescribeId());
|
|
|
+
|
|
|
+ fsPrescribeService.PrescribeImg(param.getPrescribeId());
|
|
|
+ log.info("生成处方单图片成功,处方单ID: {}", param.getPrescribeId());
|
|
|
+
|
|
|
+ }catch (Throwable e) {
|
|
|
+ log.error("生成处方单图片 发生异常 参数: {}", param,e);
|
|
|
+ throw e;
|
|
|
}
|
|
|
+
|
|
|
+ log.info("完成生成订单和处方单,处方单ID: {}", param.getPrescribeId());
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -965,6 +1079,33 @@ public class FsPrescribeServiceImpl implements IFsPrescribeService
|
|
|
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public R auditWithoutMsg(FsPrescribeAuditParam param) {
|
|
|
+ FsPrescribe prescribe=this.selectFsPrescribeByPrescribeId(param.getPrescribeId());
|
|
|
+ if(prescribe.getStatus()!=0){
|
|
|
+ return R.error("非法操作");
|
|
|
+ }
|
|
|
+ FsPrescribe map=new FsPrescribe();
|
|
|
+ map.setPrescribeId(param.getPrescribeId());
|
|
|
+ map.setDrugDoctorId(param.getDoctorId());
|
|
|
+ map.setStatus(param.getStatus());
|
|
|
+ map.setAuditReason(param.getAuditReason());
|
|
|
+ map.setAuditTime(new Date());
|
|
|
+ FsDoctor doctor=doctorService.selectFsDoctorByDoctorId(map.getDrugDoctorId());
|
|
|
+ if(StringUtils.isNotEmpty(doctor.getSignUrl())){
|
|
|
+ map.setDrugDoctorSignUrl(doctor.getSignUrl());
|
|
|
+ }
|
|
|
+ if(param.getStatus().equals(1)){
|
|
|
+ this.updateFsPrescribe(map);
|
|
|
+ //写入订单
|
|
|
+ storeOrderService.createOrder(prescribe.getPrescribeId());
|
|
|
+
|
|
|
+ return R.ok();
|
|
|
+ }
|
|
|
+ return R.ok("操作成功");
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
public void penDrawString( Graphics2D pen,String value,int x,int y){
|
|
|
if (value!=null){
|
|
|
pen.drawString(value,x,y);
|