ソースを参照

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

# Conflicts:
#	common/common-entity/sql记录
yeshijie 3 年 前
コミット
46004c346f

+ 18 - 0
common/common-entity/sql记录

@ -992,3 +992,21 @@ alter table wlyy_outpatient ADD is_agree  varchar(2);
alter table base_doctor ADD is_sign  varchar(2);
alter table base_doctor ADD last_sign_time  timestamp;
-- 2021-06-02 ysj
CREATE TABLE `base_seq` (
  `val` int(11) NOT NULL,
  `type` tinyint(4) NOT NULL COMMENT '类型1生活照料'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='自增序列';
INSERT INTO `base`.`base_seq` (`val`, `type`) VALUES ('1000000001', '1');
CREATE FUNCTION seq(seq_type TINYINT (4)) returns int
begin
 UPDATE base_seq SET val=last_insert_id(val+1) WHERE type=seq_type;
 RETURN last_insert_id();
end;
alter table base_life_care_order add column doctor_sign_time datetime DEFAULT NULL COMMENT '医生签到时间';
alter table base_life_care_order add column doctor_sign_way tinyint(1) DEFAULT NULL COMMENT '医生签到方式:1-定位,2-扫码,3-拍照';
alter table base_life_care_order add column doctor_sign_location varchar(50) DEFAULT NULL COMMENT '医生签到位置,记录详细地址';
alter table base_life_care_order add column doctor_sign_img varchar(3000) DEFAULT NULL COMMENT '医生签到照片';

+ 52 - 1
common/common-entity/src/main/java/com/yihu/jw/entity/care/lifeCare/LifeCareOrderDO.java

@ -23,7 +23,8 @@ public class LifeCareOrderDO extends UuidIdentityEntityWithOperator {
    public enum Status {
        cancel(-1, "已取消"),
        waitForAccept(1, "待(医生)接单"),
        waitForAccept(1, "待(医生)接单"),//待服务
        signIn(3, "已签到"),
        complete(2,"已完成");
        private Integer type;
@ -257,7 +258,26 @@ public class LifeCareOrderDO extends UuidIdentityEntityWithOperator {
    private String hospitalName;
    private Integer type;//发起工单类型(1本人发起 2家人待预约 3医生代预约)
    private String relationCode;//业务关联
    /**
     * 医生签到时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+08:00")
    private Date doctorSignTime;
    /**
     * 医生签到方式:1-定位,2-扫码
     */
    private Integer doctorSignWay;
    /**
     * 医生签到位置,记录详细地址
     */
    private String doctorSignLocation;
    /**
     * 医生签到照片
     */
    private String doctorSignImg;
    @Column(name = "number")
    public String getNumber() {
@ -585,4 +605,35 @@ public class LifeCareOrderDO extends UuidIdentityEntityWithOperator {
        this.relationCode = relationCode;
    }
    @Column(name = "doctor_sign_time")
    public Date getDoctorSignTime() {
        return doctorSignTime;
    }
    public void setDoctorSignTime(Date doctorSignTime) {
        this.doctorSignTime = doctorSignTime;
    }
    @Column(name = "doctor_sign_way")
    public Integer getDoctorSignWay() {
        return doctorSignWay;
    }
    public void setDoctorSignWay(Integer doctorSignWay) {
        this.doctorSignWay = doctorSignWay;
    }
    @Column(name = "doctor_sign_location")
    public String getDoctorSignLocation() {
        return doctorSignLocation;
    }
    public void setDoctorSignLocation(String doctorSignLocation) {
        this.doctorSignLocation = doctorSignLocation;
    }
    @Column(name = "doctor_sign_img")
    public String getDoctorSignImg() {
        return doctorSignImg;
    }
    public void setDoctorSignImg(String doctorSignImg) {
        this.doctorSignImg = doctorSignImg;
    }
}

+ 2 - 0
svr/svr-cloud-care/src/main/java/com/yihu/jw/care/dao/lifeCare/LifeCareOrderDao.java

@ -8,4 +8,6 @@ import org.springframework.data.repository.PagingAndSortingRepository;
 * Created by yeshijie on 2021/3/26.
 */
public interface LifeCareOrderDao extends PagingAndSortingRepository<LifeCareOrderDO, String>, JpaSpecificationExecutor<LifeCareOrderDO> {
    boolean existsByPatientAndStatusIn(String patient, Integer[] status);
}

+ 44 - 0
svr/svr-cloud-care/src/main/java/com/yihu/jw/care/endpoint/lifeCare/DoctorLifeCareEndpoint.java

@ -115,4 +115,48 @@ public class DoctorLifeCareEndpoint extends EnvelopRestEndpoint {
        }
        return PageEnvelop.getError("查询失败");
    }
    @PostMapping(value = "proxyCreate")
    @ApiOperation(value = "创建生活照料--医生代预约")
    public Envelop proxyCreate(
            @ApiParam(name = "doctor", value = "医生id") @RequestParam(value = "doctor", required = true) String doctor,
            @ApiParam(name = "jsonData", value = "Json数据", required = true) @RequestParam String jsonData) {
        try{
            JSONObject result = lifeCareOrderService.create(jsonData,doctor);
            if (result.getIntValue(ResponseContant.resultFlag) == ResponseContant.fail) {
                return Envelop.getError(result.getString(ResponseContant.resultMsg),-1);
            }
            return Envelop.getSuccess(result.getString("orderId"));
        }catch (Exception e){
            e.printStackTrace();
            return failedException(e);
        }
    }
    @PostMapping("signIn")
    @ApiOperation(value = "服务签到")
    @ObserverRequired
    public Envelop signIn(
            @ApiParam(value = "工单id", name = "orderId")
            @RequestParam(value = "orderId", required = true) String orderId,
            @ApiParam(value = "签到时间", name = "signTime")
            @RequestParam(value = "signTime", required = false) String signTime,
            @ApiParam(value = "签到方式:1-定位,2-扫码,3-拍照,4-二维码", name = "signWay")
            @RequestParam(value = "signWay", required = false) Integer signWay,
            @ApiParam(value = "签到地址", name = "signLocation")
            @RequestParam(value = "signLocation", required = false) String signLocation,
            @ApiParam(value = "签到照片", name = "signImg")
            @RequestParam(value = "signImg", required = false) String signImg,
            @ApiParam(value = "二维码内容", name = "twoDimensionalCode")
            @RequestParam(value = "twoDimensionalCode", required = false) String twoDimensionalCode) {
        try {
            LifeCareOrderDO result = lifeCareOrderService.signIn(orderId, signTime, signWay, signLocation, signImg,twoDimensionalCode,getUID());
            if (result!=null) {
                return Envelop.getError("签到失败");
            }
            return Envelop.getSuccess("签到成功");
        } catch (Exception e) {
            return failedException(e);
        }
    }
}

+ 31 - 0
svr/svr-cloud-care/src/main/java/com/yihu/jw/care/service/common/OrderNoService.java

@ -0,0 +1,31 @@
package com.yihu.jw.care.service.common;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
/**
 * Created with IntelliJ IDEA.
 *
 * @Author: yeshijie
 * @Date: 2021/6/2
 * @Description:
 */
@Service
public class OrderNoService {
    @Autowired
    private JdbcTemplate jdbcTemplate;
    /**
     * 根据类型获取订单号
     * @param type
     * @return
     */
    public String getOrderNo(Integer type){
        String sql = "SELECT cast(seq("+type+") as char)";
        String orderNo = jdbcTemplate.queryForObject(sql,String.class);
        return orderNo;
    }
}

+ 168 - 23
svr/svr-cloud-care/src/main/java/com/yihu/jw/care/service/lifeCare/LifeCareOrderService.java

@ -1,10 +1,12 @@
package com.yihu.jw.care.service.lifeCare;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.yihu.jw.care.dao.lifeCare.LifeCareCancelLogDao;
import com.yihu.jw.care.dao.lifeCare.LifeCareFeeDetailDao;
import com.yihu.jw.care.dao.lifeCare.LifeCareItemDictDao;
import com.yihu.jw.care.dao.lifeCare.LifeCareOrderDao;
import com.yihu.jw.care.service.common.OrderNoService;
import com.yihu.jw.care.util.MessageUtil;
import com.yihu.jw.doctor.dao.BaseDoctorDao;
import com.yihu.jw.doctor.dao.BaseDoctorHospitalDao;
@ -21,9 +23,11 @@ import com.yihu.jw.patient.dao.BasePatientDao;
import com.yihu.jw.restmodel.ResponseContant;
import com.yihu.jw.restmodel.web.PageEnvelop;
import com.yihu.jw.util.common.IdCardUtil;
import com.yihu.jw.util.date.DateUtil;
import com.yihu.jw.util.entity.EntityUtils;
import com.yihu.jw.wechat.dao.BasePatientWechatDao;
import com.yihu.mysql.query.BaseJpaService;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.map.HashedMap;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
@ -70,6 +74,8 @@ public class LifeCareOrderService extends BaseJpaService<LifeCareOrderDO, LifeCa
    private BaseOrgDao baseOrgDao;
    @Autowired
    private BaseDoctorDao doctorDao;
    @Autowired
    private OrderNoService orderNoService;
    /**
     * 记录完成情况
@ -140,9 +146,10 @@ public class LifeCareOrderService extends BaseJpaService<LifeCareOrderDO, LifeCa
        sql +=  "  WHERE  a.hospital = ? group BY a.status";
        List<Map<String, Object>> list = jdbcTemplate.queryForList(sql, hospital);
        Map<String, Integer> map = new HashMap<>();
        //状态 待服务 1、已完成 2 、已取消 -1
        //状态 待服务 1、已完成 2 、已取消 -1 已签到 3
        map.put("1",0);
        map.put("2",0);
        map.put("3",0);
        map.put("-1",0);
        int total = 0;
        for (Map<String, Object> one:list){
@ -401,6 +408,7 @@ public class LifeCareOrderService extends BaseJpaService<LifeCareOrderDO, LifeCa
        return result;
    }
    /**
     * 申请生活照料
     *
@ -413,16 +421,19 @@ public class LifeCareOrderService extends BaseJpaService<LifeCareOrderDO, LifeCa
        JSONObject result = new JSONObject();
        JSONObject jsonObjectParam;
        LifeCareOrderDO orderDO = null;
        try {
            jsonObjectParam = JSONObject.parseObject(jsonData);
            if (jsonObjectParam.getJSONObject("order").getInteger("type")==1||jsonObjectParam.getJSONObject("order").getInteger("type")==2){
            orderDO = EntityUtils.jsonToEntity(jsonObjectParam.get("order").toString(), LifeCareOrderDO.class);
            Integer type = orderDO.getType();
            if (type==1||type==2){
                //本人或家人代发起
                BasePatientDO patientDO = patientDao.findById(proxyPatient);
                jsonObjectParam.put("proxyPatient",proxyPatient);
                jsonObjectParam.put("proxyPatientName",patientDO.getName());
                jsonObjectParam.put("proxyPatientPhone",patientDO.getMobile());
            }
            if (jsonObjectParam.getJSONObject("order").getInteger("type")==3) {//医生代发起
            }else if (type==3) {
                //医生代发起
                BaseDoctorDO doctorDO = doctorDao.findById(proxyPatient);
                jsonObjectParam.put("proxyPatient",proxyPatient);
                jsonObjectParam.put("proxyPatientName",doctorDO.getName());
@ -436,17 +447,6 @@ public class LifeCareOrderService extends BaseJpaService<LifeCareOrderDO, LifeCa
            logger.error(failMsg);
            return result;
        }
        LifeCareOrderDO orderDO = null;
        try {
            orderDO = EntityUtils.jsonToEntity(jsonObjectParam.get("order").toString(), LifeCareOrderDO.class);
        } catch (Exception e) {
            result.put(ResponseContant.resultFlag, ResponseContant.fail);
            String failMsg = "生活照料工单服务基本信息:" + e.getMessage();
            result.put(ResponseContant.resultMsg, failMsg);
            logger.error(failMsg);
            return result;
        }
        orderDO.setCreateTime(new Date());
        orderDO.setCreateUser(orderDO.getProxyPatient());
        orderDO.setCreateUserName(orderDO.getProxyPatientName());
@ -470,14 +470,8 @@ public class LifeCareOrderService extends BaseJpaService<LifeCareOrderDO, LifeCa
            BaseOrgDO orgDO = baseOrgDao.findByCode(orderDO.getHospital());
            orderDO.setHospitalName(orgDO.getName());
        }
        orderDO.setNumber(orderNoService.getOrderNo(1));
        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);
        }
        this.save(orderDO);
        result.put("orderId",orderDO.getId());
@ -498,7 +492,7 @@ public class LifeCareOrderService extends BaseJpaService<LifeCareOrderDO, LifeCa
            totalFee = new BigDecimal(0);
        }
        for ( LifeCareFeeDetailDO feeDetailDO : feeDetailDOList) {
        for (LifeCareFeeDetailDO feeDetailDO : feeDetailDOList) {
            try {
                //工单主表中记录总费用
                totalFee = totalFee.add(feeDetailDO.getFee().multiply(BigDecimal.valueOf(feeDetailDO.getNumber())));
@ -542,6 +536,30 @@ public class LifeCareOrderService extends BaseJpaService<LifeCareOrderDO, LifeCa
        return false;
    }
    @Transactional(rollbackFor = Exception.class)
    public boolean orderWithFeeDelete(JSONObject jsonObjectParam,LifeCareOrderDO orderDO) {
        BigDecimal totalFee = orderDO.getTotalFee();
        //删除的服务项
        JSONArray itemArray = jsonObjectParam.getJSONArray("deleteItemArr");
        if (!CollectionUtils.isEmpty(itemArray)) {
            List<LifeCareFeeDetailDO> list = new ArrayList<>();
            //删除的服务项要减去服务项费用
            BigDecimal itemFee = new BigDecimal(0);
            for(Object oneId : itemArray) {
                JSONObject oneIdJson = (JSONObject) oneId;
                LifeCareFeeDetailDO doorFeeDetail = lifeCareFeeDetailDao.findOne(String.valueOf(oneIdJson.get("id")));
                if(doorFeeDetail.getPayStatus()==0){
                    doorFeeDetail.setStatus(3);
                    doorFeeDetail.setUpdateTime(new Date());
                    list.add(doorFeeDetail);
                    itemFee = itemFee.add(doorFeeDetail.getFee().multiply(BigDecimal.valueOf(doorFeeDetail.getNumber())));
                }
            }
            lifeCareFeeDetailDao.save(list);
        }
        return false;
    }
    public PageEnvelop getPatientOrderList(String patient, Integer status, int page, int size) {
        page = page>0?page-1:0;
@ -561,4 +579,131 @@ public class LifeCareOrderService extends BaseJpaService<LifeCareOrderDO, LifeCa
    }
    /**
     * 签到保存
     * @param orderId
     * @param signTime
     * @param signWay
     * @param signLocation
     * @param signImg
     * @return
     */
    public LifeCareOrderDO signIn(String orderId, String signTime, Integer signWay, String signLocation,
                             String signImg, String twoDimensionalCode,String doctorId) throws Exception {
        LifeCareOrderDO lifeCareOrderDO = this.lifeCareOrderDao.findOne(orderId);
        lifeCareOrderDO.setDoctorSignTime(DateUtil.strToDate(signTime));
        lifeCareOrderDO.setDoctorSignWay(signWay);
        // 签到方式-2扫码时,需要去解析地址
        lifeCareOrderDO.setDoctorSignLocation(signLocation);
        lifeCareOrderDO.setDoctorSignImg(StringUtils.isEmpty(signImg) ? null : signImg);
        //3 已签到
        lifeCareOrderDO.setStatus(3);
        BaseDoctorDO doctorDO = doctorDao.findById(doctorId);
        lifeCareOrderDO.setUpdateTime(new Date());
        lifeCareOrderDO.setUpdateUser(doctorId);
        lifeCareOrderDO.setUpdateUserName(doctorDO.getName());
        if(signWay == 4 ){//扫码签到
            if (twoDimensionalCode.equals(lifeCareOrderDO.getNumber())){
                lifeCareOrderDO = lifeCareOrderDao.save(lifeCareOrderDO);
                return lifeCareOrderDO;
            }else {
                logger.info("扫码签到失败");
                return null;
            }
        }else {
            lifeCareOrderDO = lifeCareOrderDao.save(lifeCareOrderDO);
            return lifeCareOrderDO;
        }
    }
    /**
     * 生活照料代预约-- 废弃用原来的接口
     * @param jsonData
     * @param doctorCode
     * @return
     */
    @Transactional
    public JSONObject proxyCreate(String jsonData,String doctorCode) {
        JSONObject result = new JSONObject();
        JSONObject jsonObjectParam;
        try {
            jsonObjectParam = JSONObject.parseObject(jsonData);
        } catch (Exception e) {
            result.put(ResponseContant.resultFlag, ResponseContant.fail);
            String failMsg = "参数转换成JSON对象异常:" + e.getMessage();
            result.put(ResponseContant.resultMsg, failMsg);
            logger.error(failMsg);
            return result;
        }
        LifeCareOrderDO orderDO = null;
        try {
            orderDO = EntityUtils.jsonToEntity(jsonObjectParam.get("order").toString(), LifeCareOrderDO.class);
        } catch (Exception e) {
            result.put(ResponseContant.resultFlag, ResponseContant.fail);
            String failMsg = "生活照料工单服务基本信息:" + e.getMessage();
            result.put(ResponseContant.resultMsg, failMsg);
            logger.error(failMsg);
            return result;
        }
        if(StringUtils.isEmpty(orderDO.getPatient())){
            result.put(ResponseContant.resultFlag, ResponseContant.fail);
            String failMsg = "当前服务对象code为空,请联系管理员检查参数!patient = " + orderDO.getPatient();
            result.put(ResponseContant.resultMsg, failMsg);
            logger.error(failMsg);
            return result;
        }
        //医生代预约
        orderDO.setType(3);
        BaseDoctorDO doctorDO = doctorDao.findById(doctorCode);
        orderDO.setProxyPatient(doctorCode);
        orderDO.setProxyPatientName(doctorDO.getName());
        orderDO.setProxyPatientPhone(doctorDO.getMobile());
        //判断工单是否已存在,新建或者编辑
        if(StringUtils.isBlank(orderDO.getId())) {
            //已取消的订单也可以申请
            boolean bool = lifeCareOrderDao.existsByPatientAndStatusIn(orderDO.getPatient(),
                    new Integer[]{LifeCareOrderDO.Status.waitForAccept.getType()
                    });
            if(bool){
                String failMsg = "当前服务对象存在未完成的生活照料,请先完成该服务!";
                result.put(ResponseContant.resultFlag, ResponseContant.fail);
                result.put(ResponseContant.resultMsg, failMsg);
                logger.error(failMsg);
                return result;
            }
            orderDO.setNumber(orderNoService.getOrderNo(1));
            orderDO.setHospital(jsonObjectParam.getJSONObject("hospital").get("code").toString());
            orderDO.setCreateTime(new Date());
            orderDO.setCreateUser(orderDO.getProxyPatient());
            orderDO.setCreateUserName(orderDO.getProxyPatientName());
        }else {
            LifeCareOrderDO serviceOrderDO = lifeCareOrderDao.findOne(orderDO.getId());
            // 删除出诊医生或服务项
            Boolean b = this.orderWithFeeDelete(jsonObjectParam, serviceOrderDO);
            if(b){
                String failMsg = "删除服务项失败!";
                result.put(ResponseContant.resultFlag, ResponseContant.fail);
                result.put(ResponseContant.resultMsg, failMsg);
                return result;
            }
            orderDO.setNumber(serviceOrderDO.getNumber());
            orderDO.setHospital(serviceOrderDO.getHospital());
            orderDO.setUpdateTime(new Date());
            orderDO.setUpdateUser(orderDO.getProxyPatient());
            orderDO.setUpdateUserName(orderDO.getProxyPatientName());
        }
        orderDO.setStatus(2);
        orderDO.setType(3);
        this.save(orderDO);
        result.put("orderId",orderDO.getId());
        //新增工单与服务项费用关联关系
        if (orderWithPackageItemFeeAdd(result, jsonObjectParam, orderDO,doctorCode)) {return result;}
        result.put(ResponseContant.resultFlag, ResponseContant.success);
        return result;
    }
}