Browse Source

Merge branch 'dev' of http://192.168.1.220:10080/Amoy2/wlyy2.0 into dev

LAPTOP-KB9HII50\70708 1 year ago
parent
commit
b4f588dd03

+ 4 - 0
business/base-service/src/main/java/com/yihu/jw/hospital/prescription/service/PrescriptionService.java

@ -8396,6 +8396,10 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
            } else {
                System.out.println("获取顺丰物流面单信息:1");
                sfexpress_obj = expressageDOList.get(0);
                List<WlyyPrescriptionDO> wlyyPrescriptionDOS1 = prescriptionDao.findByOutpatientId(wlyyPrescriptionDOS.getOutpatientId());
                if (StringUtils.isNoneBlank(sfexpress_obj.getMailno())&&wlyyPrescriptionDOS1.size()>1){
                    throw new Exception("已存在地址"+sfexpress_obj.getAddress()+"、电话"+sfexpress_obj.getMobile()+"的快递单(单号"+sfexpress_obj.getMailno()+"),请将此处方与其打包一起。");
                }
                String sql = "SELECT\n" +
                        "\tpe.outpatient_id as outpatientId,\n" +
                        "\tpe.mailno as mailno,\n" +

+ 1 - 1
business/base-service/src/main/java/com/yihu/jw/hospital/prescription/service/entrance/EntranceService.java

@ -1822,7 +1822,7 @@ public class EntranceService {
                    BusinessOrderRefundDO businessOrderRefundDO = new BusinessOrderRefundDO();
                    businessOrderRefundDO.setOrderNo(businessOrderDO.getOrderNo());
                    businessOrderRefundDO.setOutRefundNo(outRefundNo);
                    businessOrderRefundDO.setStatus(1);
                    businessOrderRefundDO.setStatus(2);
                    businessOrderRefundDO.setCreateTime(new Date());
                    businessOrderRefundDO.setUpdateTime(new Date());
                    businessOrderRefundDO.setPatient(businessOrderDO.getPatient());

+ 1 - 1
business/base-service/src/main/java/com/yihu/jw/order/BusinessOrderService.java

@ -1360,7 +1360,7 @@ public class BusinessOrderService extends BaseJpaService<BusinessOrderDO,Busines
        BusinessOrderDO businessOrderDO = businessOrderDao.selectByRelationCode(relationCode);
        return businessOrderDO;
    }
    public BusinessOrderDO selectStatusById(Integer id){
    public BusinessOrderDO selectStatusById(String id){
        BusinessOrderDO businessOrderDO = businessOrderDao.findOne(id);
        return businessOrderDO;
    }

+ 1 - 1
business/base-service/src/main/java/com/yihu/jw/order/dao/BusinessOrderDao.java

@ -10,7 +10,7 @@ import java.util.Date;
import java.util.List;
public interface BusinessOrderDao extends PagingAndSortingRepository<BusinessOrderDO, Integer>, JpaSpecificationExecutor<BusinessOrderDO>  {
public interface BusinessOrderDao extends PagingAndSortingRepository<BusinessOrderDO, String>, JpaSpecificationExecutor<BusinessOrderDO>  {
    @Query("from BusinessOrderDO w where w.traceNo = ?1 and w.orderNo=?2")

+ 9 - 0
starter/swagger-starter/pom.xml

@ -12,6 +12,11 @@
    <artifactId>swagger-starter</artifactId>
    <dependencies>
        <dependency>
            <groupId>com.github.xiaoymin</groupId>
            <artifactId>knife4j-spring-boot-starter</artifactId>
            <version>2.0.2</version>
        </dependency>
        <dependency>
            <groupId>com.github.xiaoymin</groupId>
            <artifactId>swagger-bootstrap-ui</artifactId>
@ -37,6 +42,10 @@
            <artifactId>swagger2markup</artifactId>
            <version>${version.swagger2markup}</version>
        </dependency>
    </dependencies>
</project>

+ 5 - 3
starter/swagger-starter/src/main/java/com/yihu/jw/SwaggerConfig.java

@ -1,6 +1,7 @@
package com.yihu.jw;
import com.github.xiaoymin.swaggerbootstrapui.annotations.EnableSwaggerBootstrapUI;
import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
//import com.github.xiaoymin.swaggerbootstrapui.annotations.EnableSwaggerBootstrapUI;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
@ -21,9 +22,10 @@ import java.util.List;
import static com.google.common.base.Predicates.or;
import static springfox.documentation.builders.PathSelectors.regex;
@Configuration
@EnableKnife4j
@EnableSwagger2
@EnableSwaggerBootstrapUI
@Configuration
//@EnableSwaggerBootstrapUI
public class SwaggerConfig {
    public static final String API_VERSION = "v1.0";

+ 53 - 5
svr/svr-cloud-care/src/main/java/com/yihu/jw/care/endpoint/patient/PayEndpoint.java

@ -90,7 +90,7 @@ public class PayEndpoint extends EnvelopRestEndpoint {
    @GetMapping("orderInfo")
    @ApiOperation(value = "订单详情")
    public ObjEnvelop orderInfo(@ApiParam(name = "id", value = "订单id")
                                    @RequestParam(value = "id", required = false) Integer id,
                                    @RequestParam(value = "id", required = false) String id,
                                @ApiParam(name = "orderId", value = "工单id")
                                @RequestParam(value = "orderId", required = false) String orderId) {
        try {
@ -110,7 +110,7 @@ public class PayEndpoint extends EnvelopRestEndpoint {
    @ObserverRequired
    public Envelop cancleOrder(
            @ApiParam(name = "id", value = "订单id")
            @RequestParam(value = "id", required = true) Integer id) {
            @RequestParam(value = "id", required = true) String id) {
        try{
            String res = payService.cancleOrder(id);
            if(StringUtil.isBlank(res)){
@ -163,7 +163,7 @@ public class PayEndpoint extends EnvelopRestEndpoint {
            @ApiParam(name = "relationId", value = "业务id,如生活照料id 上面辅导id")
            @RequestParam(value = "relationId", required = false) String relationId,
            @ApiParam(name = "orderId", value = "订单id")
            @RequestParam(value = "orderId", required = false) Integer orderId,HttpServletRequest request) {
            @RequestParam(value = "orderId", required = false) String orderId,HttpServletRequest request) {
        try{
            return payService.wxWapPay(relationId, orderId, request);
        }catch (Exception e){
@ -171,6 +171,54 @@ public class PayEndpoint extends EnvelopRestEndpoint {
        }
    }
    @PostMapping(value = "cloudWxPay")
    @ApiOperation(value = "云照护支付")
    @ObserverRequired
    public ObjEnvelop wxWapPay(
            @ApiParam(name = "relationCode", value = "关联表id")
            @RequestParam(value = "relationCode", required = false) String relationCode,
            @ApiParam(name = "relationName", value = "关联表名称")
            @RequestParam(value = "relationName", required = false) String relationName,
            @ApiParam(name = "orderType", value = "订单类型")
            @RequestParam(value = "orderType", required = false) String orderType,
            @ApiParam(name = "patient", value = "居民code")
            @RequestParam(value = "patient", required = false) String patient,
            @ApiParam(name = "doctor", value = "医生code")
            @RequestParam(value = "doctor", required = false) String doctor,
            @ApiParam(name = "fee", value = "费用金额")
            @RequestParam(value = "fee", required = false) String fee,
            @ApiParam(name = "depositType", value = "支付类型")
            @RequestParam(value = "depositType", required = false) String depositType,
            @ApiParam(name = "appletCode", value = "费用金额")
            @RequestParam(value = "appletCode", required = false) String appletCode) {
        try{
            return ObjEnvelop.getSuccess("请求成功",payService.cloudWxPay(relationCode,relationName,orderType,patient,doctor,fee,depositType, appletCode));
        }catch (Exception e){
            return failedObjEnvelopException2(e);
        }
    }
    @PostMapping(value = "cloudWxRefund")
    @ApiOperation(value = "云照护支付退款")
    @ObserverRequired
    public ObjEnvelop wxWapPay(
            @ApiParam(name = "orderNo", value = "订单号码")
            @RequestParam(value = "orderNo", required = false) String orderNo,
            @ApiParam(name = "refundPrice", value = "退款金额")
            @RequestParam(value = "refundPrice", required = false) Double refundPrice,
            @ApiParam(name = "description", value = "退款描述")
            @RequestParam(value = "description", required = false) String description,
            @ApiParam(name = "patient", value = "居民code")
            @RequestParam(value = "patient", required = false) String patient) {
        try{
            return ObjEnvelop.getSuccess("请求成功",payService.cloudWxRefund(patient,orderNo,refundPrice,description));
        }catch (Exception e){
            return failedObjEnvelopException2(e);
        }
    }
    @PostMapping(value = "applyRefund")
    @ApiOperation(value = "申请退款")
    @ObserverRequired
@ -180,7 +228,7 @@ public class PayEndpoint extends EnvelopRestEndpoint {
            @ApiParam(name = "enclosure", value = "退款附件")
            @RequestParam(value = "enclosure", required = false) String enclosure,
            @ApiParam(name = "id", value = "订单id")
            @RequestParam(value = "id", required = true) Integer id) {
            @RequestParam(value = "id", required = true) String id) {
        try{
            String res = payService.applyRefund(id, description, enclosure);
            if(StringUtil.isBlank(res)){
@ -199,7 +247,7 @@ public class PayEndpoint extends EnvelopRestEndpoint {
            @ApiParam(name = "relationId", value = "业务id,如生活照料id 上门辅导id")
            @RequestParam(value = "relationId", required = false) String relationId,
            @ApiParam(name = "orderId", value = "订单id")
            @RequestParam(value = "orderId", required = false) Integer orderId,HttpServletRequest request) {
            @RequestParam(value = "orderId", required = false) String orderId,HttpServletRequest request) {
        try{
            return  payService.wxNativePay(relationId, orderId, request);
        }catch (Exception e){

+ 170 - 5
svr/svr-cloud-care/src/main/java/com/yihu/jw/care/service/pay/PayService.java

@ -1,6 +1,7 @@
package com.yihu.jw.care.service.pay;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.yihu.fastdfs.FastDFSUtil;
@ -13,12 +14,19 @@ import com.yihu.jw.care.service.lifeCare.LifeCareOrderService;
import com.yihu.jw.care.util.WxpayUtil;
import com.yihu.jw.care.util.XMLUtil;
import com.yihu.jw.entity.base.patient.BasePatientDO;
import com.yihu.jw.entity.base.wx.BasePatientWechatDo;
import com.yihu.jw.entity.base.wx.WxWechatDO;
import com.yihu.jw.entity.care.common.WxPayHttpLogDO;
import com.yihu.jw.entity.care.doorCoach.BaseDoorCoachFeeDetailDO;
import com.yihu.jw.entity.care.doorCoach.BaseDoorCoachOrderDO;
import com.yihu.jw.entity.care.lifeCare.LifeCareFeeDetailDO;
import com.yihu.jw.entity.care.lifeCare.LifeCareOrderDO;
import com.yihu.jw.entity.hospital.consult.WlyyHospitalSysDictDO;
import com.yihu.jw.entity.hospital.healthCare.YlzMedicalRelationDO;
import com.yihu.jw.entity.hospital.mapping.DoctorMappingDO;
import com.yihu.jw.entity.hospital.prescription.WlyyOutpatientDO;
import com.yihu.jw.entity.hospital.prescription.WlyyPrescriptionDO;
import com.yihu.jw.entity.hospital.prescription.WlyyPrescriptionInfoDO;
import com.yihu.jw.entity.order.BusinessOrderDO;
import com.yihu.jw.entity.order.BusinessOrderRefundDO;
import com.yihu.jw.order.BusinessOrderService;
@ -33,6 +41,8 @@ import com.yihu.jw.util.common.QrcodeUtil;
import com.yihu.jw.util.date.DateUtil;
import com.yihu.jw.utils.StringUtil;
import com.yihu.jw.wechat.dao.WechatDao;
import org.apache.commons.collections.map.HashedMap;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@ -189,7 +199,7 @@ public class PayService {
     * 订单详情接口
     * @param id
     */
    public JSONObject orderInfo(Integer id,String orderId){
    public JSONObject orderInfo(String id,String orderId){
        JSONObject resJson = new JSONObject();
        BusinessOrderDO businessOrderDO;
        if(StringUtil.isBlank(orderId)){
@ -237,7 +247,7 @@ public class PayService {
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
    public String applyRefund(Integer id,String description,String enclosure){
    public String applyRefund(String id,String description,String enclosure){
        BusinessOrderDO businessOrderDO = businessOrderDao.findOne(id);
        String type = businessOrderDO.getOrderCategory();
        String orderId = businessOrderDO.getRelationCode();
@ -286,7 +296,7 @@ public class PayService {
     * 取消订单
     * @param id
     */
    public String cancleOrder(Integer id){
    public String cancleOrder(String id){
        BusinessOrderDO businessOrderDO = businessOrderDao.findOne(id);
        if(businessOrderDO.getStatus()==0){
            String type = businessOrderDO.getOrderCategory();
@ -578,7 +588,7 @@ public class PayService {
     * @throws Exception
     */
    @Transactional(rollbackFor = Exception.class)
    public ObjEnvelop wxNativePay(String relationId,Integer orderId,HttpServletRequest request) throws Exception {
    public ObjEnvelop wxNativePay(String relationId,String orderId,HttpServletRequest request) throws Exception {
        BusinessOrderDO businessOrderDO;
        if(StringUtil.isBlank(relationId)){
            businessOrderDO = businessOrderDao.findOne(orderId);
@ -656,7 +666,7 @@ public class PayService {
     * @throws Exception
     */
    @Transactional(rollbackFor = Exception.class)
    public ObjEnvelop wxWapPay(String relationId,Integer orderId,HttpServletRequest request) throws Exception {
    public ObjEnvelop wxWapPay(String relationId,String orderId,HttpServletRequest request) throws Exception {
        BusinessOrderDO businessOrderDO;
        if(StringUtil.isBlank(relationId)){
            businessOrderDO = businessOrderDao.findOne(orderId);
@ -797,6 +807,161 @@ public class PayService {
        return businessOrderDO;
    }
    /**
     * 云照护微信支付
     *
     * @param relationCode
     * @param relationName
     * @param orderType
     * @param depositType
     * @return
     * @throws Exception
     */
    public Map<String,Object> cloudWxPay(String relationCode,String relationName,String orderType,String patient,String doctor,
                                         String fee,String depositType,String appletCode) throws Exception {
        try {
            WxWechatDO wxWechatDO = wechatDao.findById(wechatId);
            if(wxWechatDO==null){
                throw new Exception("can't find wechat:the wxId is "+wechatId);
            }
            BusinessOrderDO businessOrderDO = businessOrderDao.selectByRelationCode(relationCode);
            BasePatientDO patientDO = new BasePatientDO();
            if (StringUtils.isNoneBlank(patient)){
                patientDO = patientDao.findOne(patient);
            }
            if (businessOrderDO==null) {
                businessOrderDO = new BusinessOrderDO();
                businessOrderDO.setCreateTime(new Date());
                businessOrderDO.setUpdateTime(new Date());
                businessOrderDO.setStatus(0);
                businessOrderDO.setOrderNo(getOrderNo());
                businessOrderDO.setUploadStatus(0);
                businessOrderDO.setPayType(1);
                businessOrderDO.setRelationCode(relationCode);
                businessOrderDO.setRelationName(relationName);
                businessOrderDO.setOrderCategory(orderType);
                businessOrderDO.setOrderType(Integer.parseInt(orderType));
                businessOrderDO.setDoctor(doctor);
                businessOrderDO.setPatient(patient);
                businessOrderDO.setPatientName(patientDO.getName());
                String a = String.valueOf(String.format("%.2f",Double.parseDouble(fee)));
                BigDecimal b = new BigDecimal(a);
                BigDecimal c = new BigDecimal(String.valueOf(100));
                BigDecimal bc = b.multiply(c);
                businessOrderDO.setPayPrice(bc.doubleValue());
                businessOrderDO.setDescription(relationName);
                businessOrderDO = businessOrderDao.save(businessOrderDO);
            }else {
                if (businessOrderDO.getStatus()==1){
                    throw new Exception("该订单已支付过");
                }
                String a = String.valueOf(String.format("%.2f",Double.parseDouble(fee)));
                BigDecimal b = new BigDecimal(a);
                BigDecimal c = new BigDecimal(String.valueOf(100));
                BigDecimal bc = b.multiply(c);
                businessOrderDO.setPayPrice(bc.doubleValue());
                businessOrderDO = businessOrderDao.save(businessOrderDO);
            }
            Map<String,Object> map = new HashedMap();
            if(wxWechatDO==null){
                throw new Exception("can't find wechat:the wxId is "+wechatId);
            }
            if (businessOrderDO!=null){
                if (businessOrderDO.getStatus()==1){
                    throw new Exception("该处方已支付过");
                }
                String openId = "";
                if (StringUtils.isNotBlank(appletCode)){
                    log.info("appletCode不为空"+appletCode);
                    Map<String,Object> objectMap = businessOrderService.checkApplets(appletCode,wxWechatDO.getApplets(),wxWechatDO.getAppletsSecret());
                    if (objectMap!=null){
                        openId = objectMap.get("openid").toString();
                        log.info("appletCode"+appletCode);
                        log.info("openid"+openId);
                    }
                }else {
                    log.info("appletCode为空"+appletCode);
                    openId = patientDO.getOpenid();
                }
                businessOrderDO.setOrderNo(getOrderNo());
                businessOrderDO= businessOrderDao.save(businessOrderDO);
                String url = wxWechatDO.getBaseUrl();
                String notifyUrl =url;
                String totalFee =businessOrderDO.getPayPrice().intValue()+"";
                map = businessOrderService.unifiedorder(wechatId,businessOrderDO.getDescription(),totalFee, depositType,openId,businessOrderDO.getOrderNo(),notifyUrl,businessOrderDO.getPatient());
            }
            return map;
        }catch (Exception e){
            e.printStackTrace();
            return null;
        }
    }
    /**
     * 云照护支付退款
     * @param wechatId
     * @param patient
     * @param orderNo
     * @param refundPrice
     * @param description
     * @return
     * @throws Exception
     */
    public Map<String,Object> cloudWxRefund(String patient,String orderNo,Double refundPrice,String description) throws Exception {
        WxWechatDO wxWechatDO = wechatDao.findById(wechatId);
        if (wxWechatDO==null){
            throw new Exception("this wechatId is null");
        }
        BusinessOrderDO businessOrderDO = businessOrderDao.selectByOrderNo(orderNo);
        if (businessOrderDO==null){
            throw new Exception("this orderId not exit");
        }
        BasePatientDO patientDO = patientDao.findById(patient);
        if (patientDO==null){
            throw new Exception("this patient not exit");
        }
        BusinessOrderRefundDO orderRefundDO = orderRefundDao.selectByOrderNo(orderNo);
        if (orderRefundDO==null){
            orderRefundDO = new BusinessOrderRefundDO();
        }
        orderRefundDO.setCreateTime(new Date());
        orderRefundDO.setUpdateTime(new Date());
        orderRefundDO.setStatus(1);
        orderRefundDO.setOrderNo(orderNo);
        orderRefundDO.setOrderPrice(businessOrderDO.getPayPrice());
        orderRefundDO.setRefundPrice(refundPrice);
        orderRefundDO.setAppId(wxWechatDO.getAppId());
        orderRefundDO.setMchId(wxWechatDO.getMchId());
        orderRefundDO.setOutRefundNo("HLWYY"+businessOrderDO.getOrderType()+System.currentTimeMillis()+(int)(Math.random()*900)+100);
        orderRefundDO.setPatient(patient);
        orderRefundDO.setPatientName(patientDO.getName());
        orderRefundDO.setRefundDesc(description);
        orderRefundDO = orderRefundDao.save(orderRefundDO);
        Integer orderPrice = orderRefundDO.getOrderPrice().intValue();
        Integer refundPrice1 = orderRefundDO.getRefundPrice().intValue();
        Map<String,Object> map = businessOrderService.refund(wechatId,orderRefundDO.getOrderNo(),orderRefundDO.getOutRefundNo(),orderPrice.toString(),refundPrice1.toString(),orderRefundDO.getRefundDesc());
        log.info("map"+map);
        if (map.get("return_code").toString().equalsIgnoreCase("SUCCESS")){
            if (map.get("result_code").toString().equalsIgnoreCase("FAIL")){
                orderRefundDO.setStatus(10);
                orderRefundDO.setRefundTime(new Date());
                orderRefundDO.setRefundDesc(map.get("err_code_des").toString());
                orderRefundDao.save(orderRefundDO);
            }else {
                orderRefundDO.setStatus(2);
                orderRefundDO.setRefundTime(new Date());
                orderRefundDao.save(orderRefundDO);
            }
        }else if (map.get("return_code").toString().equalsIgnoreCase("CLOSED")||map.get("return_code").toString().equalsIgnoreCase("ABNORMAL")||map.get("return_code").toString().equalsIgnoreCase("PROCESSING")){
            orderRefundDO.setStatus(10);
            orderRefundDO.setRefundTime(new Date());
            orderRefundDao.save(orderRefundDO);
        }
        return map;
    }
    public String getOrderNo(){
        return ""+System.currentTimeMillis()+(int)(Math.random()*900)+100;
    }

+ 1 - 1
svr/svr-internet-hospital/src/main/java/com/yihu/jw/hospital/endpoint/prescription/PrescriptionEndpoint.java

@ -2266,7 +2266,7 @@ public class PrescriptionEndpoint extends EnvelopRestEndpoint {
    @ApiOperation("查询支付状态")
    public ObjEnvelop selectOrderStatusById(
            @ApiParam(name = "id", value = "订单id", required = true)
            @RequestParam(required = true) Integer id) throws Exception {
            @RequestParam(required = true) String id) throws Exception {
        try {
            return ObjEnvelop.getSuccess("ok", businessOrderService.selectStatusById(id));
        } catch (Exception e) {

+ 2 - 4
svr/svr-visit-behind/src/main/java/com/yihu/jw/hospital/module/door/dao/WlyyDoorServiceOrderDao.java

@ -2,11 +2,11 @@ package com.yihu.jw.hospital.module.door.dao;
import com.yihu.jw.entity.door.WlyyDoorServiceOrderDO;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.transaction.annotation.Transactional;
import java.util.Date;
import java.util.List;
@ -23,14 +23,13 @@ import java.util.List;
 * </pre>
 * @since 1.
 */
public interface WlyyDoorServiceOrderDao extends PagingAndSortingRepository<WlyyDoorServiceOrderDO, String>, JpaSpecificationExecutor<WlyyDoorServiceOrderDO> {
public interface WlyyDoorServiceOrderDao extends JpaRepository<WlyyDoorServiceOrderDO, String>, JpaSpecificationExecutor<WlyyDoorServiceOrderDO> {
    boolean existsByPatientAndStatusNot(String patient, int status);
    boolean existsByPatientAndStatusIn(String patient, Integer[] status);
    @Modifying
    @Transactional
    @Query("update WlyyDoorServiceOrderDO o set o.conclusionStatus = 1 where o.id = ?1")
    void updateConclusionStatus(String orderId);
@ -38,7 +37,6 @@ public interface WlyyDoorServiceOrderDao extends PagingAndSortingRepository<Wlyy
    List<WlyyDoorServiceOrderDO> getNotFinishOrderByDoctor(String doctor);
    @Modifying
    @Transactional
    @Query("update WlyyDoorServiceOrderDO o set o.prescriptionStatus = 1,o.status = 4, o.prescriptionCode = ?2, o.prescriptionTime = ?3 where o.id = ?1")
    void updatePrescriptionById(String orderId, String prescriptionCode, Date prescriptionTime);

+ 124 - 109
svr/svr-visit-behind/src/main/java/com/yihu/jw/hospital/module/door/service/WlyyDoorServiceOrderService.java

@ -21,7 +21,6 @@ import com.yihu.jw.hospital.task.PushMsgTask;
import com.yihu.jw.hospital.utils.WeiXinAccessTokenUtils;
import com.yihu.jw.im.dao.ConsultDao;
import com.yihu.jw.im.util.ImUtil;
import com.yihu.jw.patient.dao.BasePatientDao;
import com.yihu.jw.patient.service.BasePatientService;
import com.yihu.jw.restmodel.ResponseContant;
@ -29,7 +28,6 @@ import com.yihu.jw.restmodel.qvo.ParamQvo;
import com.yihu.jw.util.common.IdCardUtil;
import com.yihu.jw.util.common.QrcodeUtil;
import com.yihu.jw.util.date.DateUtil;
import com.yihu.jw.util.http.HttpClientUtil;
import com.yihu.jw.utils.EntityUtils;
import com.yihu.mysql.query.BaseJpaService;
@ -648,120 +646,137 @@ public class WlyyDoorServiceOrderService extends BaseJpaService<WlyyDoorServiceO
     * @param jsonData
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
//    @Transactional(rollbackFor = Exception.class)
//    public JSONObject create(String jsonData) throws Exception {
//        logger.info("创建上门服务jsonData参数:" + jsonData);
//
//        JSONObject result = new JSONObject();
//        JSONObject jsonObjectParam = JSONObject.parseObject(jsonData);
//
//        WlyyDoorServiceOrderDO orderDO = EntityUtils.jsonToEntity(
//                jsonObjectParam.get("order").toString(), WlyyDoorServiceOrderDO.class);
//
//        orderDO.setNumber(getRandomIntStr());
//        orderDO.setCreateTime(new Date());
//        orderDO.setCreateUser(orderDO.getProxyPatient());
//        orderDO.setCreateUserName(orderDO.getProxyPatientName());
//        orderDO.setOrderInfo("0");
//
//        if (StringUtils.isEmpty(orderDO.getPatient())) {
//            throw new Exception("当前服务对象code为空,请联系管理员检查参数!patient = " + orderDO.getPatient());
//        }
//
//        if (StringUtils.isEmpty(orderDO.getProxyPatient())) {
//            String failMsg = "当前代理对象code为空,请联系管理员检查参数!proxyPatient = " + orderDO.getProxyPatient();
//            throw new Exception(failMsg);
//        }
//
//        //判断师傅存在为完成的上门服务订单
//        boolean bool = wlyyDoorServiceOrderDao.existsByPatientAndStatusIn(orderDO.getPatient(),
//                new Integer[]{WlyyDoorServiceOrderDO.Status.waitForSend.getType(),
//                        WlyyDoorServiceOrderDO.Status.waitForAccept.getType(),
//                        WlyyDoorServiceOrderDO.Status.waitForServe.getType(),
//                        WlyyDoorServiceOrderDO.Status.accept.getType(),
//                });
//
//        if (bool) {
//            String failMsg = "当前服务对象存在未完成的上门服务,请先完成该服务!";
//            throw new Exception(failMsg);
//        }
//
//        orderDO.setHospital(jsonObjectParam.getJSONObject("hospital").get("code").toString());
//        orderDO.setCreateTime(new Date());
//        //判断创建上门服务类型,发起类型(1本人发起 2家人待预约 3医生代预约)
//        if (orderDO.getProxyPatient().equals(orderDO.getPatient())) {
//            orderDO.setType(1);
//        } else if (!orderDO.getProxyPatient().equals(orderDO.getPatient())) {
//            orderDO.setType(2);
//        }
//        orderDO.setServiceStatus("1");
//        //保存服务订单
//        wlyyDoorServiceOrderDao.save(orderDO);
//
//        //创建咨询
//        JSONObject successOrNot = consultTeamService.addDoorServiceConsult(orderDO.getId());
//        ConsultTeamDo consultTeam = (ConsultTeamDo) successOrNot.get(ResponseContant.resultMsg);
//
//        //新增工单与服务项费用关联关系
//        if (orderWithPackageItemFeeAdd(result, jsonObjectParam, orderDO)) {
//            return result;
//        }
//        //获取机构的调度员
//        List<Map<String, Object>> dispatcherList = queryDispatcherInfoByPatient(jsonObjectParam.getJSONObject("hospital").get("code").toString());
//        //没有调度员的模式
////        if (dispatcherList.isEmpty()
////                && StringUtils.isEmpty(orderDO.getDoctor())
////                && StringUtils.isEmpty(orderDO.getExpectedDoctorName())) {
////            orderDO.setStatus(2);
////            //应该是康复模板的康复下转,才有签约--先注释
////            orderDO.setDoctor(signFamily.getDoctor());
////            orderDO.setDoctorName(signFamily.getDoctorName());
////            this.save(orderDO);
////            WlyyDoorServiceOrderDO wlyyDoorServiceOrder = wlyyDoorServiceOrderDao.findById(orderDO.getId());
////            //新增工单医生关联关系
////            if (orderWithDoctorAdd(result, jsonObjectParam, wlyyDoorServiceOrder)) {
////                return result;
////            }
////            // 给服务医生发接单消息--先注释
////            this.createMessage(orderDO.getId(), orderDO.getProxyPatient(), signFamily.getDoctor(), 407, "服务工单待接单", "您有新的服务工单,请前往处理");
////            //发送智能助手消息-微信消息先注释
////            sendWeixinMessage(4, signFamily.getDoctor(), orderDO.getPatient());
////            result.put(ResponseContant.resultFlag, ResponseContant.success);
////            result.put(ResponseContant.resultMsg, consultTeam);
////            return result;
////        }
//
//        //有调度员
//        if (!dispatcherList.isEmpty()) {
//            for (Map<String, Object> map : dispatcherList) {
//                String dispatcher = map.get("code").toString();
//                // 派单消息-首页
//                this.createMessage(orderDO.getId(), "system", dispatcher, 402, "新增居民预约服务申请", orderDO.getPatientName() + "提交了服务预约申请,请您前往处理");
//                // 派单-实时工单消息  430 居民提交工单申请-- 张三提交了服务工单12345678申请
//                this.createMessage(orderDO.getId(), "system", dispatcher, 430, "居民提交工单申请", orderDO.getPatientName() + "提交了服务工单" + orderDO.getNumber() + "申请");
//            }
//        }
//
//        //给机构调度员发送医生助手消息
//        for (Map<String, Object> map : dispatcherList) {
//            //这边还没有微信消息的功能呢。
//            sendWeixinMessage(3, map.get("user_code") + "", orderDO.getPatient());
//        }
//        result.put(ResponseContant.resultFlag, ResponseContant.success);
//        result.put(ResponseContant.resultMsg, consultTeam);
//
//        //发送 预约卡片信息(2101类型)
//        JSONObject orderInfoContent = this.queryOrderCardInfo(orderDO);
//        orderInfoContent.put("re_msg_type", 0);//居民预约
//        //发送消息
//        int i = qucikSendIM(orderDO.getId(), "system", "智能助手", "2101", orderInfoContent.toJSONString());
////        if (i != 1) {
////            throw new Exception("上门服务工单消息发送失败");
////        }
//
//        if (StringUtils.isNoneBlank(orderDO.getDoctor())) {
//            //服务医生修改,直接转派
//            BaseDoctorDO transDoctor = doctorDao.findById(orderDO.getDoctor());
//            sendOrderToDoctor(orderDO.getId(), null, "system", "系统", transDoctor.getId(), transDoctor.getName(), transDoctor.getJobTitleName());
//        }
//        return result;
//    }
    public JSONObject create(String jsonData) throws Exception {
        logger.info("创建上门服务jsonData参数:" + jsonData);
        JSONObject result = new JSONObject();
        JSONObject jsonObjectParam = JSONObject.parseObject(jsonData);
        WlyyDoorServiceOrderDO orderDO = EntityUtils.jsonToEntity(
                jsonObjectParam.get("order").toString(), WlyyDoorServiceOrderDO.class);
        orderDO.setNumber(getRandomIntStr());
        orderDO.setCreateTime(new Date());
        orderDO.setCreateUser(orderDO.getProxyPatient());
        orderDO.setCreateUserName(orderDO.getProxyPatientName());
        orderDO.setOrderInfo("0");
        if (StringUtils.isEmpty(orderDO.getPatient())) {
            throw new Exception("当前服务对象code为空,请联系管理员检查参数!patient = " + orderDO.getPatient());
        }
        if (StringUtils.isEmpty(orderDO.getProxyPatient())) {
            String failMsg = "当前代理对象code为空,请联系管理员检查参数!proxyPatient = " + orderDO.getProxyPatient();
            throw new Exception(failMsg);
        }
        //判断师傅存在为完成的上门服务订单
        boolean bool = wlyyDoorServiceOrderDao.existsByPatientAndStatusIn(orderDO.getPatient(),
                new Integer[]{WlyyDoorServiceOrderDO.Status.waitForSend.getType(),
                        WlyyDoorServiceOrderDO.Status.waitForAccept.getType(),
                        WlyyDoorServiceOrderDO.Status.waitForServe.getType(),
                        WlyyDoorServiceOrderDO.Status.accept.getType(),
                });
        if (bool) {
            String failMsg = "当前服务对象存在未完成的上门服务,请先完成该服务!";
            throw new Exception(failMsg);
        }
        orderDO.setHospital(jsonObjectParam.getJSONObject("hospital").get("code").toString());
        orderDO.setCreateTime(new Date());
        //判断创建上门服务类型,发起类型(1本人发起 2家人待预约 3医生代预约)
        if (orderDO.getProxyPatient().equals(orderDO.getPatient())) {
            orderDO.setType(1);
        } else if (!orderDO.getProxyPatient().equals(orderDO.getPatient())) {
            orderDO.setType(2);
        }
        orderDO.setServiceStatus("1");
        WlyyDoorServiceOrderDO orderDO =new WlyyDoorServiceOrderDO();
        //保存服务订单
        wlyyDoorServiceOrderDao.save(orderDO);
        //创建咨询
        JSONObject successOrNot = consultTeamService.addDoorServiceConsult(orderDO.getId());
        ConsultTeamDo consultTeam = (ConsultTeamDo) successOrNot.get(ResponseContant.resultMsg);
        //新增工单与服务项费用关联关系
        if (orderWithPackageItemFeeAdd(result, jsonObjectParam, orderDO)) {
            return result;
        }
        //获取机构的调度员
        List<Map<String, Object>> dispatcherList = queryDispatcherInfoByPatient(jsonObjectParam.getJSONObject("hospital").get("code").toString());
        //没有调度员的模式
//        if (dispatcherList.isEmpty()
//                && StringUtils.isEmpty(orderDO.getDoctor())
//                && StringUtils.isEmpty(orderDO.getExpectedDoctorName())) {
//            orderDO.setStatus(2);
//            //应该是康复模板的康复下转,才有签约--先注释
//            orderDO.setDoctor(signFamily.getDoctor());
//            orderDO.setDoctorName(signFamily.getDoctorName());
//            this.save(orderDO);
//            WlyyDoorServiceOrderDO wlyyDoorServiceOrder = wlyyDoorServiceOrderDao.findById(orderDO.getId());
//            //新增工单医生关联关系
//            if (orderWithDoctorAdd(result, jsonObjectParam, wlyyDoorServiceOrder)) {
//                return result;
//            }
//            // 给服务医生发接单消息--先注释
//            this.createMessage(orderDO.getId(), orderDO.getProxyPatient(), signFamily.getDoctor(), 407, "服务工单待接单", "您有新的服务工单,请前往处理");
//            //发送智能助手消息-微信消息先注释
//            sendWeixinMessage(4, signFamily.getDoctor(), orderDO.getPatient());
//            result.put(ResponseContant.resultFlag, ResponseContant.success);
//            result.put(ResponseContant.resultMsg, consultTeam);
//            return result;
//        }
        //有调度员
        if (!dispatcherList.isEmpty()) {
            for (Map<String, Object> map : dispatcherList) {
                String dispatcher = map.get("code").toString();
                // 派单消息-首页
                this.createMessage(orderDO.getId(), "system", dispatcher, 402, "新增居民预约服务申请", orderDO.getPatientName() + "提交了服务预约申请,请您前往处理");
                // 派单-实时工单消息  430 居民提交工单申请-- 张三提交了服务工单12345678申请
                this.createMessage(orderDO.getId(), "system", dispatcher, 430, "居民提交工单申请", orderDO.getPatientName() + "提交了服务工单" + orderDO.getNumber() + "申请");
            }
        }
        //给机构调度员发送医生助手消息
        for (Map<String, Object> map : dispatcherList) {
            //这边还没有微信消息的功能呢。
            sendWeixinMessage(3, map.get("user_code") + "", orderDO.getPatient());
        }
        result.put(ResponseContant.resultFlag, ResponseContant.success);
        result.put(ResponseContant.resultMsg, consultTeam);
        //发送 预约卡片信息(2101类型)
        JSONObject orderInfoContent = this.queryOrderCardInfo(orderDO);
        orderInfoContent.put("re_msg_type", 0);//居民预约
        //发送消息
        int i = qucikSendIM(orderDO.getId(), "system", "智能助手", "2101", orderInfoContent.toJSONString());
//        if (i != 1) {
//            throw new Exception("上门服务工单消息发送失败");
//        }
        if (StringUtils.isNoneBlank(orderDO.getDoctor())) {
            //服务医生修改,直接转派
            BaseDoctorDO transDoctor = doctorDao.findById(orderDO.getDoctor());
            sendOrderToDoctor(orderDO.getId(), null, "system", "系统", transDoctor.getId(), transDoctor.getName(), transDoctor.getJobTitleName());
        }
        return result;
    }
@ -1979,7 +1994,7 @@ public class WlyyDoorServiceOrderService extends BaseJpaService<WlyyDoorServiceO
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    if (parArray!=null){
                    if (parArray != null) {
                        parArray.forEach(
                                oneParObj -> {
                                    org.json.JSONObject oneParJson = (org.json.JSONObject) oneParObj;