瀏覽代碼

整理床位

lihong 2 年之前
父節點
當前提交
8d21dff633

+ 77 - 0
src/main/java/thyyxxk/webserver/controller/medicaladvice/patientinfo/AdjustBedController.java

@@ -0,0 +1,77 @@
+package thyyxxk.webserver.controller.medicaladvice.patientinfo;
+
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+import thyyxxk.webserver.config.auth.PassToken;
+import thyyxxk.webserver.entity.ResultVo;
+import thyyxxk.webserver.entity.medicaladvice.medicamanage.MzZyReq;
+import thyyxxk.webserver.entity.medicaladvice.medicamanage.ZyBedPreMsg;
+import thyyxxk.webserver.entity.medicaladvice.medicamanage.patientinfo.ZyBedMi;
+import thyyxxk.webserver.entity.medicaladvice.medicamanage.patientinfo.ZyBedMiParam;
+import thyyxxk.webserver.service.medicaladvice.patientinfo.AdjustBedService;
+import thyyxxk.webserver.utils.ResultVoUtil;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @Description:整理床位
+ * @Author:lihong
+ * @Date: 2023/5/31
+ */
+@RestController
+@RequestMapping("/medicalAdvice/adjustBed/")
+public class AdjustBedController {
+    @Autowired
+    private AdjustBedService service;
+
+
+    @PostMapping("preAllocationBed")
+    @PassToken
+    public ResultVo<String> preAllocationBed(@RequestBody MzZyReq mzZyReq){
+        return service.preAllocationBed(mzZyReq);
+    }
+
+    @PostMapping("confirmPreBed")
+    public ResultVo<String> confirmPreBed(@RequestBody ZyBedPreMsg msg){
+        return service.confirmPreBed(msg);
+    }
+
+    @PostMapping("queryZyBedPreMsg")
+    public ResultVo<IPage<ZyBedPreMsg>> queryZyBedPreMsg(@RequestBody ZyBedPreMsg msg){
+        return service.queryZyBedPreMsg(msg);
+    }
+    @PostMapping("getIdleBedNoList")
+    public ResultVo<List<Map>> getIdleBedNoList(@RequestBody ZyBedPreMsg msg){
+        return service.getIdleBedNoList(msg);
+    }
+
+    @PostMapping("queryZybedMi")
+    public ResultVo<Map<String,Object>> queryZybedMi(@RequestBody ZyBedMi param){
+        return ResultVoUtil.success(service.queryZybedMi(param));
+    }
+
+    @PostMapping("clearBed")
+    public ResultVo<String> clearBed(@RequestBody ZyBedMi param){
+        return service.clearBed(param);
+    }
+
+    @PostMapping("addBed")
+    public ResultVo<String> addBed(@RequestBody ZyBedMi param){
+        return service.addBed(param);
+    }
+
+    @PostMapping("saveBed")
+    public ResultVo<String> saveBed(@RequestBody ZyBedMiParam params){
+        return service.saveBed(params);
+    }
+    @PostMapping("queryIsPreBed")
+    public ResultVo<String> queryIsPreBed(@RequestBody ZyBedMi param){
+        return service.queryIsPreBed(param);
+    }
+
+}

+ 67 - 0
src/main/java/thyyxxk/webserver/dao/his/medicaladvice/patientinfo/AdjustBedDao.java

@@ -0,0 +1,67 @@
+package thyyxxk.webserver.dao.his.medicaladvice.patientinfo;
+
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+import org.apache.ibatis.annotations.Select;
+import org.apache.ibatis.annotations.Update;
+import thyyxxk.webserver.entity.medicaladvice.medicamanage.MzZyReq;
+import thyyxxk.webserver.entity.medicaladvice.medicamanage.patientinfo.ZyBedMi;
+
+import java.util.List;
+
+/**
+ * @Description:
+ * @Author:lihong
+ * @Date: 2023/5/31
+ */
+@Mapper
+public interface AdjustBedDao {
+    @Select("  select code from a_employee_mi where  dept_code = #{ward} and  code in ( " +
+            "    select user_code from dj_user_role where role_id in (4,12,18)" +
+            "    ) ")
+    List<String> getAdmins(String ward);
+    @Update(" update mz_zy_req set  bed_no = #{bedNo}, req_status =#{reqStatus},pre_bed_confirm_id=#{preBedConfirmId},pre_bed_confirm_date=#{preBedConfirmDate},pre_bed_confirm_remark=#{preBedConfirmRemark} where patient_id=#{patientId} and CONVERT(VARCHAR(30),visit_date,20) =#{visitDateStr} ")
+    void updateBedNo(MzZyReq mzZyReq);
+    @Select("  select top 1 1 from zy_bed_mi where bed_no = #{bedNo} and bed_status ='1' ")
+    Integer isIdleBedNo(String bedNo);
+    @Select(" select  bed_no from zy_bed_mi where bed_status ='1' and ward_code= #{ward} order by cast(bed_no as int) ")
+    List<String> selectIdleBedNoList(String ward);
+    @Select(" SELECT zy_bed_mi.room_no,\n" +
+            "       zy_bed_mi.bed_no,\n" +
+            "       inpatient_no=isnull(zy_actpatient.inpatient_no,zy_bed_mi.inpatient_no),\n" +
+            "       zy_actpatient.name,\n" +
+            "       sex  =case when isnull(zy_actpatient.inpatient_no,'') <> '' then isnull(zy_actpatient.sex,'1') else '0' end,\n" +
+            "       admiss_date=isnull(zy_actpatient.admiss_hour,zy_actpatient.admiss_date),\n" +
+            "       zy_bed_mi.ward_code,\n" +
+            "       zy_bed_mi.dept_code,\n" +
+            "       zy_bed_mi.bed_status,\n" +
+            "       admiss_times=isnull(zy_actpatient.admiss_times,zy_bed_mi.admiss_times),\n" +
+            "       zy_bed_mi.remark  ,\n" +
+            "       zy_actpatient.refer_physician,\n" +
+            "       refer_physician_name =(select name from a_employee_mi where zy_actpatient.refer_physician= code),\n" +
+            "       zy_actpatient.responce_type,\n" +
+            "       responce_type_name = (select name from  zy_zd_responce_type where zy_actpatient.responce_type=code)\n" +
+            " from zy_bed_mi left join  zy_actpatient  on  zy_bed_mi.inpatient_no = zy_actpatient.inpatient_no\n" +
+            "   where   zy_bed_mi.ward_code = #{wardCode} order by cast(zy_bed_mi.bed_no as int) ")
+    List<ZyBedMi> selectZybedMi(ZyBedMi param);
+    @Select(" select top 1 * from   mz_zy_req   where patient_id=#{patientId} and CONVERT(VARCHAR(30),visit_date,20) =#{visitDateStr} ")
+    MzZyReq selectMzZyReq(MzZyReq mzZyReq);
+    @Select(" select top 1 1 from zy_actpatient where bed_no =#{bedNo} and dept =#{wardCode}")
+    Integer isExistPatient(ZyBedMi param);
+    @Update(" update zy_bed_mi set inpatient_no =#{inpatientNo} , admiss_times =#{admissTimes} , bed_status =#{bedStatus} where bed_no =#{bedNo} and dept_code =#{wardCode}")
+    void updatePatientByBed(ZyBedMi param);
+    @Select("  select top 1 req_status from mz_zy_req where patient_id=#{patientId} and CONVERT(VARCHAR(30),visit_date,20) =#{visitDateStr} ")
+    String selectReqStatus(MzZyReq req);
+    @Select(" select top 1 inpatient_no , admiss_times from zy_actpatient where bed_no =#{bedNo} and dept =#{wardCode} ")
+    ZyBedMi selectActInpatientByBed(ZyBedMi param);
+    @Update(" update zy_actpatient SET bed_no =#{bedNo} , bed_status =#{bedStatus} , ward =#{wardCode} WHERE ( inpatient_no =#{inpatientNo} or inpatient_no like ( #{inpatientNo} + '$%' ) ) AND admiss_times =#{admissTimes};")
+    void updateActpatientBed(ZyBedMi zyBedMi);
+    @Update(" update yz_yp_zy_order SET bed_no =#{bedNo} WHERE ( inpatient_no =#{inpatientNo} or inpatient_no =( #{inpatientNo} + '$1' ) or inpatient_no =( #{inpatientNo} + '$2' ) or inpatient_no =( #{inpatientNo} + '$3' ) or inpatient_no =( #{inpatientNo} + '$4' ) or inpatient_no =( #{inpatientNo} + '$5' ) or inpatient_no =( #{inpatientNo} + '$6' ) ) AND admiss_times =#{admissTimes}")
+    void updateYpZyOrder(ZyBedMi zyBedMi);
+    @Update(" update yz_act_occ SET bed_no =#{bedNo} WHERE ( inpatient_no =#{inpatientNo} or inpatient_no =( #{inpatientNo} + '$1' ) or inpatient_no =( #{inpatientNo} + '$2' ) or inpatient_no =( #{inpatientNo} + '$3' ) or inpatient_no =( #{inpatientNo} + '$4' ) or inpatient_no =( #{inpatientNo} + '$5' ) or inpatient_no =( #{inpatientNo} + '$6' ) ) AND admiss_times =#{admissTimes}")
+    void updateYzActOcc(ZyBedMi zyBedMi);
+    @Select(" select top 1 1 from mz_zy_req where req_ward=#{wardCode} and visit_date >=#{startVisitDate} and visit_date<=#{endVisitDate} and bed_no=#{bedNo}")
+    Integer queryIsPreBed(ZyBedMi param);
+    @Select(" select top 1 rtrim(name) name  from mz_patient_mi where patient_id =#{patientId}  ")
+    String selectPatientMi(@Param("patientId") String patientId);
+}

+ 23 - 0
src/main/java/thyyxxk/webserver/dao/his/medicaladvice/patientinfo/ZyBedPreMsgDao.java

@@ -0,0 +1,23 @@
+package thyyxxk.webserver.dao.his.medicaladvice.patientinfo;
+
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.core.toolkit.Constants;
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+import org.apache.ibatis.annotations.Select;
+import thyyxxk.webserver.entity.medicaladvice.medicamanage.ZyBedPreMsg;
+
+/**
+ * 预分配床位消息表
+ * 
+ * @author lh
+ * @email lihong@gmail.com
+ * @date 2023-05-31 10:54:07
+ */
+@Mapper
+public interface ZyBedPreMsgDao extends BaseMapper<ZyBedPreMsg> {
+    @Select("  select a.*,b.req_status preBedStatus,b.pre_bed_confirm_remark,b.bed_no  from zy_bed_pre_msg a left  join  mz_zy_req b on a.patient_id=b.patient_id and CONVERT(VARCHAR(30),a.visit_date,20)=CONVERT(VARCHAR(30),b.visit_date,20) ${ew.customSqlSegment} ")
+    IPage<ZyBedPreMsg> queryZyBedPreMsgPage(IPage<ZyBedPreMsg> page, @Param(Constants.WRAPPER)QueryWrapper queryWrapper);
+}

+ 120 - 0
src/main/java/thyyxxk/webserver/entity/medicaladvice/medicamanage/MzZyReq.java

@@ -0,0 +1,120 @@
+package thyyxxk.webserver.entity.medicaladvice.medicamanage;
+
+import com.baomidou.mybatisplus.annotation.TableName;
+import lombok.Data;
+
+import java.io.Serializable;
+import java.util.Date;
+
+/**
+ * ${comments}
+ * 
+ * @author lh
+ * @email lihong@gmail.com
+ * @date 2023-05-31 10:55:03
+ */
+@Data
+@TableName("mz_zy_req")
+public class MzZyReq implements Serializable {
+	private static final long serialVersionUID = 1L;
+
+	/**
+	 * 新的诊断编码,老的诊断编码太短了长度
+	 */
+	private String icdCodeNew;
+	/**
+	 * 新的诊断名称,老的诊断编码太短了长度
+	 */
+	private String icdTextNew;
+	/**
+	 * 入院病情代码  1 有 2 临床未确定 3 情况不明 4 无
+	 */
+	private Integer conditionCode;
+	/**
+	 * 入院途径代码  1 急诊 2 门诊 3其他医疗机构转入 9 其他
+	 */
+	private Integer routeOfAdmission;
+
+	/**
+	 * 预分配床位确认人
+	 */
+	private String preBedConfirmId;
+	/**
+	 * 预分配床位确认时间
+	 */
+	private Date preBedConfirmDate;
+	/**
+	 * 预分配床位备注
+	 */
+	private String preBedConfirmRemark;
+	/**
+	 * $column.comments
+	 */
+	private String doctorCode;
+	/**
+	 * $column.comments
+	 */
+	private String zySerialNo;
+	/**
+	 * $column.comments
+	 */
+	private String reqWard;
+	/**
+	 * $column.comments
+	 */
+	private String patientId;
+	/**
+	 * $column.comments
+	 */
+	private String icdText;
+	/**
+	 * $column.comments
+	 */
+	private String reqDept;
+	/**
+	 * $column.comments
+	 */
+	private String icdCode;
+	/**
+	 * $column.comments
+	 */
+	private String admissStatus;
+	/**
+	 * $column.comments
+	 */
+	private Date confirmDate;
+	/**
+	 * $column.comments
+	 */
+	private String smallDept;
+	/**
+	 * $column.comments
+	 */
+	private String confirmId;
+	/**
+	 * $column.comments
+	 */
+	private Date visitDate;
+	private String visitDateStr;
+	/**
+	 * $column.comments
+	 */
+	private String responceType;
+	/**
+	 * $column.comments
+	 */
+	private String name;
+	/**
+	 * $column.comments
+	 */
+	private String deptCode;
+	/**
+	 *  0 未确认 1.已确认 2已驳回 3.已住院
+	 */
+	private String reqStatus;
+	/**
+	 * $column.comments
+	 */
+	private String bedNo;
+
+}

+ 77 - 0
src/main/java/thyyxxk/webserver/entity/medicaladvice/medicamanage/ZyBedPreMsg.java

@@ -0,0 +1,77 @@
+package thyyxxk.webserver.entity.medicaladvice.medicamanage;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import lombok.Data;
+
+import java.io.Serializable;
+import java.util.Date;
+
+/**
+ * 预分配床位消息表
+ * 
+ * @author lh
+ * @email lihong@gmail.com
+ * @date 2023-05-31 10:54:07
+ */
+@Data
+@TableName("zy_bed_pre_msg")
+public class ZyBedPreMsg implements Serializable {
+	private static final long serialVersionUID = 1L;
+
+	/**
+	 * 处理人
+	 */
+	private String confirmId;
+	/**
+	 * 处理时间
+	 */
+	private Date confirmDate;
+	/**
+	 * 0 待办 1已办
+	 */
+	private String msgStatus;
+	/**
+	 * 病室
+	 */
+	private String ward;
+	/**
+	 * 门诊号
+	 */
+	private String patientId;
+	/**
+	 * 就诊时间
+	 */
+	private Date visitDate;
+	/**
+	 * 姓名
+	 */
+	private String name;
+	/**
+	 * 时间
+	 */
+	private Date reqDate;
+	/**
+	 * $column.comments
+	 */
+	@TableId(type = IdType.AUTO)
+	private Integer id;
+	@TableField(exist = false)
+	private String bedNo;
+	@TableField(exist = false)
+	/**
+	 * 	预分配床位状态 0 未确认 1.已确认 2已驳回
+	 */
+	private String preBedStatus;
+	@TableField(exist = false)
+	private String wardName;
+	@TableField(exist = false)
+	private String preBedConfirmRemark;
+	@TableField(exist = false)
+	private Integer currentPage;
+	@TableField(exist = false)
+	private Integer pageSize;
+
+}

+ 165 - 0
src/main/java/thyyxxk/webserver/entity/medicaladvice/medicamanage/patientinfo/ZyBedMi.java

@@ -0,0 +1,165 @@
+package thyyxxk.webserver.entity.medicaladvice.medicamanage.patientinfo;
+
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import lombok.Data;
+
+import java.io.Serializable;
+import java.math.BigDecimal;
+import java.util.Date;
+
+/**
+ * ${comments}
+ * 
+ * @author lh
+ * @email lihong@gmail.com
+ * @date 2023-06-01 17:16:48
+ */
+@Data
+@TableName("zy_bed_mi")
+public class ZyBedMi implements Serializable {
+	private static final long serialVersionUID = 1L;
+
+	/**
+	 * $column.comments
+	 */
+	@TableId
+	private String icuFlag;
+	/**
+	 * $column.comments
+	 */
+	private String wardCode;
+	/**
+	 * $column.comments
+	 */
+	private String inpatientNo;
+	/**
+	 * $column.comments
+	 */
+	private Float roomRate2;
+	/**
+	 * $column.comments
+	 */
+	private String chargeCodeAir;
+	/**
+	 * $column.comments
+	 */
+	private String deptCode;
+	/**
+	 * $column.comments
+	 */
+	private Float percent2;
+	/**
+	 * $column.comments
+	 */
+	private Float heatingFee;
+	/**
+	 * $column.comments
+	 */
+	private BigDecimal specialCharge;
+	/**
+	 * $column.comments
+	 */
+	private String zySerialNo;
+	/**
+	 * $column.comments
+	 */
+	private String bedStatus;
+	/**
+	 * $column.comments
+	 */
+	private Float percent5;
+	/**
+	 * $column.comments
+	 */
+	private String chargeCodeBed;
+	/**
+	 * $column.comments
+	 */
+	private String bedNo;
+	/**
+	 * $column.comments
+	 */
+	private Date effDate1;
+	/**
+	 * $column.comments
+	 */
+	private String type;
+	/**
+	 * $column.comments
+	 */
+	private String chargeCodeHeat;
+	/**
+	 * $column.comments
+	 */
+	private String roomNo;
+	/**
+	 * $column.comments
+	 */
+	private Float airconditionFee;
+	/**
+	 * $column.comments
+	 */
+	private Float percent3;
+	/**
+	 * $column.comments
+	 */
+	private String remark;
+	/**
+	 * $column.comments
+	 */
+	private Integer admissTimes;
+	/**
+	 * $column.comments
+	 */
+	private Float percent4;
+	/**
+	 * $column.comments
+	 */
+	private Date effDate2;
+	/**
+	 * $column.comments
+	 */
+	private String sex;
+	/**
+	 * $column.comments
+	 */
+	private Float percent1;
+	/**
+	 * $column.comments
+	 */
+	private String bedPos;
+	/**
+	 * $column.comments
+	 */
+	private Float roomRate1;
+	/**
+	 * $column.comments
+	 */
+	private String heatcoldFlag;
+
+	private String name;
+	private String sexName;
+	/**管床医生 */
+	private String referPhysician;
+	private String referPhysicianName;
+	/**医保类型*/
+	private String responceType;
+	private String startVisitDate;
+	private String endVisitDate;
+	private String responceTypeName;
+
+	private Date admissDate;
+
+	public String getSexName(){
+		switch (this.sex) {
+			case "1":
+                return "男";
+            case "2":
+                return "女";
+            default:
+                return "未知";
+		}
+	}
+
+}

+ 16 - 0
src/main/java/thyyxxk/webserver/entity/medicaladvice/medicamanage/patientinfo/ZyBedMiParam.java

@@ -0,0 +1,16 @@
+package thyyxxk.webserver.entity.medicaladvice.medicamanage.patientinfo;
+
+import lombok.Data;
+
+import java.util.List;
+
+/**
+ * @Description:
+ * @Author:lihong
+ * @Date: 2023/6/3
+ */
+@Data
+public class ZyBedMiParam {
+    private List<ZyBedMi> param;
+    private String wardCode;
+}

+ 19 - 0
src/main/java/thyyxxk/webserver/entity/medicaladvice/medicamanage/weixin/WeiXinPreBedMsgParam.java

@@ -0,0 +1,19 @@
+package thyyxxk.webserver.entity.medicaladvice.medicamanage.weixin;
+
+import lombok.Data;
+
+/**
+ * @Description:
+ * @Author:lihong
+ * @Date: 2023/6/7
+ */
+@Data
+public class WeiXinPreBedMsgParam {
+    /**姓名*/
+    private String name;
+    /**床位信息*/
+    private String bedInfo;
+    private String patientId;
+    private String first;
+
+}

+ 22 - 0
src/main/java/thyyxxk/webserver/service/externalhttp/WxServer.java

@@ -0,0 +1,22 @@
+package thyyxxk.webserver.service.externalhttp;
+
+import com.alibaba.fastjson.JSONObject;
+import com.dtflys.forest.annotation.JSONBody;
+import com.dtflys.forest.annotation.Post;
+
+/**
+ * @Description:调用微信公众号接口
+ * @Author:lihong
+ * @Date: 2023/6/7
+ */
+public interface WxServer {
+    /**
+     * @description:预约床号
+     * @author: lihong
+     * @date: 2023/6/7 10:39
+     * @param: obj
+     * @return: com.alibaba.fastjson.JSONObject
+     **/
+    @Post(url = "http://192.168.200.3/wxserver/wxApi/pushMessage")
+    JSONObject pushMessagePreBedNo(@JSONBody JSONObject obj);
+}

+ 295 - 0
src/main/java/thyyxxk/webserver/service/medicaladvice/patientinfo/AdjustBedService.java

@@ -0,0 +1,295 @@
+package thyyxxk.webserver.service.medicaladvice.patientinfo;
+
+import cn.hutool.core.bean.BeanUtil;
+import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.convert.Convert;
+import cn.hutool.core.date.DateUtil;
+import cn.hutool.core.util.StrUtil;
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+import thyyxxk.webserver.config.exception.BizException;
+import thyyxxk.webserver.config.exception.ExceptionEnum;
+import thyyxxk.webserver.constants.Message;
+import thyyxxk.webserver.dao.his.medicaladvice.patientinfo.AdjustBedDao;
+import thyyxxk.webserver.dao.his.medicaladvice.patientinfo.ZyBedPreMsgDao;
+import thyyxxk.webserver.entity.ResultVo;
+import thyyxxk.webserver.entity.login.UserInfo;
+import thyyxxk.webserver.entity.medicaladvice.medicamanage.MzZyReq;
+import thyyxxk.webserver.entity.medicaladvice.medicamanage.ZyBedPreMsg;
+import thyyxxk.webserver.entity.medicaladvice.medicamanage.patientinfo.ZyBedMi;
+import thyyxxk.webserver.entity.medicaladvice.medicamanage.patientinfo.ZyBedMiParam;
+import thyyxxk.webserver.entity.medicaladvice.medicamanage.weixin.WeiXinPreBedMsgParam;
+import thyyxxk.webserver.service.externalhttp.WxServer;
+import thyyxxk.webserver.service.redislike.RedisLikeService;
+import thyyxxk.webserver.utils.AssertUtil;
+import thyyxxk.webserver.utils.CommonUtil;
+import thyyxxk.webserver.utils.ResultVoUtil;
+import thyyxxk.webserver.utils.SocketMsg;
+import thyyxxk.webserver.websocket.WebSocketServer;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @Description:
+ * @Author:lihong
+ * @Date: 2023/5/31
+ */
+@Slf4j
+@Service
+public class AdjustBedService {
+    @Autowired
+    private AdjustBedDao dao;
+    @Autowired
+    private ZyBedPreMsgDao zyBedPreMsgDao;
+    @Autowired
+    private RedisLikeService redisLikeService;
+    @Autowired
+    private WxServer wxServer;
+
+    public ResultVo<String> preAllocationBed(MzZyReq mzZyReq) {
+        mzZyReq.setVisitDateStr(DateUtil.formatDateTime(mzZyReq.getVisitDate()));
+        MzZyReq zyReq = dao.selectMzZyReq(mzZyReq);
+        //发送消息
+        sendMsg(zyReq.getReqWard(),zyReq.getName());
+        return ResultVoUtil.success("已发送预分配床位消息,等待护士进行确认");
+    }
+
+    public void sendMsg(String ward,String name) {
+        //获取该病室的护士
+        List<String> admins = dao.getAdmins(ward);
+        JSONObject obj = new JSONObject();
+        obj.put("message", StrUtil.format("病人:【{}】进行了床位预分配申请,请前往整理床位页面进行预分配床位",name));
+        admins.forEach(code -> WebSocketServer.sendMessageByUserCode(code, SocketMsg.socketVo(Message.SYSTEM_NOTIFICATION, obj)));
+    }
+    @Transactional(rollbackFor = Exception.class)
+    public ResultVo<String> confirmPreBed(ZyBedPreMsg zyBedPreMsg){
+        BeanUtil.trimStrFields(zyBedPreMsg);
+        ZyBedPreMsg msg = zyBedPreMsgDao.selectById(zyBedPreMsg.getId());
+        if("1".equals(msg.getMsgStatus())){
+            throw new BizException(ExceptionEnum.LOGICAL_ERROR, "该条消息已办,不要重复确认");
+        }
+        if("1".equals(zyBedPreMsg.getPreBedStatus())){
+            AssertUtil.isnotBlank(zyBedPreMsg.getBedNo(),"床位不能为空");
+            //判断床位是否空闲
+            Integer idleBedNo = dao.isIdleBedNo(zyBedPreMsg.getBedNo());
+            if (idleBedNo == null) {
+                throw new BizException(ExceptionEnum.LOGICAL_ERROR, "该床位已有人,请重新分配");
+            }
+        }
+        //消息改为已办
+        UserInfo userInfo = redisLikeService.getUserInfoByToken();
+        Date now = new Date();
+        zyBedPreMsg.setConfirmDate(now);
+        zyBedPreMsg.setConfirmId(userInfo.getCode());
+        zyBedPreMsg.setMsgStatus("1");
+        zyBedPreMsgDao.updateById(zyBedPreMsg);
+
+        //修改住院申请表
+        MzZyReq req = new MzZyReq();
+        req.setPatientId(zyBedPreMsg.getPatientId());
+        req.setVisitDate(zyBedPreMsg.getVisitDate());
+        req.setBedNo(zyBedPreMsg.getBedNo());
+        req.setPreBedConfirmId(userInfo.getCode());
+        req.setPreBedConfirmDate(now);
+        req.setVisitDateStr(DateUtil.formatDateTime(zyBedPreMsg.getVisitDate()));
+        req.setReqStatus(zyBedPreMsg.getPreBedStatus());
+        req.setPreBedConfirmRemark(zyBedPreMsg.getPreBedConfirmRemark());
+        String reqStatus = dao.selectReqStatus(req);
+        if(!"3".equals(reqStatus.trim())){
+            dao.updateBedNo(req);
+            MzZyReq zyReq = dao.selectMzZyReq(req);
+            if ("1".equals(req.getReqStatus()) && isPushMessagePreBedNo(req.getPatientId(),zyReq.getName())) {
+                WeiXinPreBedMsgParam weiXinPreBedMsgParam = new WeiXinPreBedMsgParam();
+                weiXinPreBedMsgParam.setPatientId(req.getPatientId());
+                weiXinPreBedMsgParam.setName(zyReq.getName());
+                weiXinPreBedMsgParam.setBedInfo("1".equals(req.getReqStatus()) ? redisLikeService.getDeptName(zyReq.getReqWard()) + req.getBedNo() + "床" : "");
+                weiXinPreBedMsgParam.setFirst("1".equals(req.getReqStatus()) ? "您已成功预约床位,请及时办理住院!" : req.getPreBedConfirmRemark());
+                try {
+                    pushMessagePreBedNo(weiXinPreBedMsgParam);
+                } catch (Exception e) {
+                    log.error("调用微信床位预约报错", e);
+                }
+            }
+        }
+      return  ResultVoUtil.success(ExceptionEnum.SUCCESS_AND_NOTIFICATION,"成功");
+    }
+
+    private boolean isPushMessagePreBedNo(String patientId,String name) {
+        String mzName = dao.selectPatientMi(patientId);
+        if(StrUtil.equals(name,mzName)){
+            return true;
+        }
+        return false;
+    }
+
+
+    public ResultVo<IPage<ZyBedPreMsg>> queryZyBedPreMsg(ZyBedPreMsg msg) {
+        IPage<ZyBedPreMsg> page = new Page<>(msg.getCurrentPage(), msg.getPageSize());
+        QueryWrapper queryWrapper = new QueryWrapper();
+        queryWrapper.like(StrUtil.isNotBlank(msg.getName()),"a.name",msg.getName());
+        queryWrapper.like(StrUtil.isNotBlank(msg.getMsgStatus()),"a.msg_status",msg.getMsgStatus());
+        UserInfo userInfo = redisLikeService.getUserInfoByToken();
+        if(!userInfo.getRoles().contains(1)){
+            queryWrapper.eq("a.ward",userInfo.getDeptCode());
+        }
+        zyBedPreMsgDao.queryZyBedPreMsgPage(page,queryWrapper);
+        page.getRecords().forEach(item->{
+            item.setWardName(redisLikeService.getDeptName(item.getWard()));
+        });
+        page.setRecords(page.getRecords());
+        page.setTotal(page.getTotal());
+        return ResultVoUtil.success(page);
+    }
+
+
+    public ResultVo<List<Map>> getIdleBedNoList(ZyBedPreMsg msg){
+        List<Map> list = new ArrayList<>();
+        List<String> bedNos =  dao.selectIdleBedNoList(msg.getWard());
+        if(CollUtil.isNotEmpty(bedNos)){
+            bedNos.forEach(bedNo -> {
+                Map map = new HashMap(2);
+                map.put("code",bedNo);
+                map.put("name",bedNo);
+                list.add(map);
+            });
+        }
+        return ResultVoUtil.success(list);
+    }
+
+
+    public Map<String,Object> queryZybedMi(ZyBedMi param){
+        if(StrUtil.isBlank(param.getWardCode())){
+            param.setWardCode(redisLikeService.getUserInfoByToken().getDeptCode());
+        }
+        Map<String,Object> map = new HashMap<>(4);
+        List<ZyBedMi> list = dao.selectZybedMi(param);
+        CommonUtil.BeanTrim(list);
+        map.put("data",list);
+        map.put("bedTotal",list.size());
+        long yzBedTotal = list.stream().filter(o -> StrUtil.isNotBlank(o.getInpatientNo())).count();
+        long ybTotal = list.stream().filter(o -> StrUtil.isNotBlank(o.getInpatientNo()) && !"01".equals(o.getResponceType())).count();
+        map.put("yzBedTotal",yzBedTotal);
+        map.put("ybTotal",ybTotal);
+        return map;
+    }
+
+    public ResultVo<String> clearBed(ZyBedMi param) {
+        AssertUtil.isnotBlank(param.getBedNo(),"床位号不能为空");
+        if(StrUtil.isBlank(param.getWardCode())){
+            param.setWardCode(redisLikeService.getUserInfoByToken().getDeptCode());
+        }
+        //
+        Integer existPatient = dao.isExistPatient(param);
+        if(existPatient !=null){
+            throw new BizException(ExceptionEnum.INTERNAL_SERVER_ERROR,"此床位存在病人信息不能清除");
+        }
+        param.setInpatientNo(null);
+        param.setAdmissTimes(null);
+        param.setBedStatus("1");
+        dao.updatePatientByBed(param);
+        String message = StrUtil.format("清除{}床信息成功",param.getBedNo());
+        return ResultVoUtil.success(ExceptionEnum.SUCCESS_AND_NOTIFICATION,message);
+    }
+
+    public ResultVo<String> addBed(ZyBedMi param) {
+        AssertUtil.isnotBlank(param.getBedNo(),"床位号不能为空");
+        if(StrUtil.isBlank(param.getWardCode())){
+            param.setWardCode(redisLikeService.getUserInfoByToken().getDeptCode());
+        }
+        ZyBedMi zyBedMi = dao.selectActInpatientByBed(param);
+        if(zyBedMi == null || StrUtil.isBlank(zyBedMi.getInpatientNo())){
+            throw new BizException(ExceptionEnum.INTERNAL_SERVER_ERROR,"此床位不存在病人信息,不能添加");
+        }
+        zyBedMi.setBedStatus("2");
+        dao.updatePatientByBed(zyBedMi);
+        String message = StrUtil.format("添加{}床信息成功",param.getBedNo());
+        return ResultVoUtil.success(ExceptionEnum.SUCCESS_AND_NOTIFICATION,message);
+    }
+
+    public ResultVo<String> saveBed(ZyBedMiParam params) {
+        ZyBedMi bedMi = new ZyBedMi();
+        if(StrUtil.isBlank(params.getWardCode())){
+            bedMi.setWardCode(redisLikeService.getUserInfoByToken().getDeptCode());
+        }else {
+            bedMi.setWardCode(params.getWardCode());
+        }
+        List<ZyBedMi> oldZyBedMi = dao.selectZybedMi(bedMi);
+        List<ZyBedMi> newZyBedMi = params.getParam();
+        CommonUtil.BeanTrim(oldZyBedMi);
+        List<ZyBedMi> updateData = new ArrayList<>();
+        newZyBedMi.forEach(newData->{
+            ZyBedMi oldComBedMi = oldZyBedMi.stream().filter(old -> newData.getBedNo().equals(old.getBedNo())).findFirst().get();
+            if(!Convert.toStr(oldComBedMi.getInpatientNo(),"").equals(Convert.toStr(newData.getInpatientNo(),""))){
+                if(StrUtil.isBlank(newData.getWardCode())){
+                    newData.setWardCode(bedMi.getWardCode());
+                }
+                updateData.add(newData);
+            }
+        });
+    if(CollUtil.isNotEmpty(updateData)){
+        updateData.forEach(o->{
+            if(StrUtil.isNotBlank(o.getInpatientNo())){
+                o.setBedStatus("2");
+                dao.updateActpatientBed(o);
+                dao.updateYpZyOrder(o);
+                dao.updateYzActOcc(o);
+            }else {
+                o.setBedStatus("1");
+                o.setInpatientNo(null);
+                o.setAdmissTimes(null);
+            }
+            dao.updatePatientByBed(o);
+        });
+    }
+       return  ResultVoUtil.success(ExceptionEnum.SUCCESS_AND_NOTIFICATION,"保存成功");
+    }
+
+    public ResultVo<String> queryIsPreBed(ZyBedMi param){
+        if(StrUtil.isBlank(param.getWardCode())){
+            param.setWardCode(redisLikeService.getUserInfoByToken().getDeptCode());
+        }else {
+            param.setWardCode(param.getWardCode());
+        }
+        //是否24小时内分配了床位
+        Date now = new Date();
+        param.setEndVisitDate(DateUtil.formatDateTime(now));
+        param.setStartVisitDate(DateUtil.formatDateTime(DateUtil.offsetDay(now,-1)));
+        Integer pre = dao.queryIsPreBed(param);
+        if(pre == null){
+            return ResultVoUtil.success();
+        }else {
+            String str = StrUtil.format("{}床24小时内已经分配的病人,请确认是否继续分配该床",param.getBedNo());
+            return ResultVoUtil.fail(ExceptionEnum.INTERNAL_SERVER_ERROR,str);
+        }
+    }
+
+
+   public void pushMessagePreBedNo(WeiXinPreBedMsgParam param){
+       JSONObject jsonObject = new JSONObject();
+       String msgContentJson = "{\"touser\":\"\",\"data\":" +
+               "{\"keyword3\":{\"color\":\"#173177\",\"value\":\"" + param.getBedInfo() + "\"}," +
+               "\"keyword4\":{\"color\":\"#FF0000\",\"value\":\"泰和医院\"}," +
+               "\"keyword1\":{\"color\":\"#173177\",\"value\":\"" + param.getName() + "\"}," +
+               "\"remark\":{\"color\":\"#FF0000\",\"value\":\"感谢您的使用,祝您健康!\"}," +
+               "\"first\":{\"color\":\"#FF0000\",\"value\":\"" + param.getFirst() + "\"}}," +
+               "\"template_id\":\"gQapOy99TXwDpublt7pWFehB2pzfI0Az5qlhCjaYxB0\"," +
+               "\"url\":\"\"}";
+       jsonObject.put("cardNo",param.getPatientId());
+       jsonObject.put("isCardNoPatientId",true);
+       jsonObject.put("msgContext",JSON.parseObject(msgContentJson));
+       log.info("调用微信接口参数入参{}", JSON.toJSONString(jsonObject));
+       wxServer.pushMessagePreBedNo(jsonObject);
+   }
+
+}