|
@ -1,22 +1,33 @@
|
|
|
package com.yihu.jw.care.service.course;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.yihu.jw.care.dao.course.CourseCatalogueDao;
|
|
|
import com.yihu.jw.care.dao.course.CourseDao;
|
|
|
import com.yihu.jw.care.dao.course.CourseSalesOrderRecordDao;
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
import com.yihu.jw.care.dao.course.*;
|
|
|
import com.yihu.jw.doctor.dao.BaseDoctorDao;
|
|
|
import com.yihu.jw.doctor.dao.BaseDoctorHospitalDao;
|
|
|
import com.yihu.jw.entity.base.doctor.BaseDoctorDO;
|
|
|
import com.yihu.jw.entity.base.doctor.BaseDoctorHospitalDO;
|
|
|
import com.yihu.jw.entity.care.course.CourseDO;
|
|
|
import com.yihu.jw.entity.care.course.CourseSalesOrderRecordDO;
|
|
|
import com.yihu.jw.entity.care.course.PatientOrderRefundDO;
|
|
|
import com.yihu.jw.entity.care.course.RecruitStudentsRecordDO;
|
|
|
import com.yihu.jw.entity.order.BusinessOrderDO;
|
|
|
import com.yihu.jw.order.dao.BusinessOrderDao;
|
|
|
import com.yihu.jw.patient.dao.BasePatientDao;
|
|
|
import com.yihu.jw.restmodel.ResponseContant;
|
|
|
import com.yihu.jw.util.date.DateUtil;
|
|
|
import com.yihu.jw.utils.StringUtil;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.jdbc.core.BeanPropertyRowMapper;
|
|
|
import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
|
import static com.yihu.jw.rm.iot.IotRequestMapping.Common.hospital;
|
|
|
|
|
|
/**
|
|
|
* Created with IntelliJ IDEA.
|
|
|
*
|
|
@ -39,9 +50,107 @@ public class CourseService {
|
|
|
private BaseDoctorDao doctorDao;
|
|
|
@Autowired
|
|
|
private JdbcTemplate jdbcTemplate;
|
|
|
@Autowired
|
|
|
private RecruitStudentsRecordDao recruitStudentsRecordDao;
|
|
|
@Autowired
|
|
|
private BusinessOrderDao businessOrderDao;
|
|
|
@Autowired
|
|
|
private PatientOrderRefundDao patientOrderRefundDao;
|
|
|
@Autowired
|
|
|
private ObjectMapper objectMapper;
|
|
|
@Autowired
|
|
|
private BaseDoctorHospitalDao baseDoctorHospitalDao;
|
|
|
|
|
|
public String getOrderNo(String type){
|
|
|
return type + System.currentTimeMillis()+(int)(Math.random() * 900)+100 +"";
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 取消订单
|
|
|
* @param id
|
|
|
* @param type
|
|
|
* @return
|
|
|
*/
|
|
|
public String cancalOrder(String id,String type){
|
|
|
if("1".equals(type)){
|
|
|
//招生
|
|
|
RecruitStudentsRecordDO recordDO = recruitStudentsRecordDao.findOne(id);
|
|
|
if(!"2".equals(recordDO.getStatus())){
|
|
|
return "只有待支付的订单才能取消";
|
|
|
}
|
|
|
recordDO.setStatus("7");
|
|
|
recruitStudentsRecordDao.save(recordDO);
|
|
|
}else if("2".equals(type)){
|
|
|
//课程
|
|
|
CourseSalesOrderRecordDO recordDO = courseSalesOrderRecordDao.findOne(id);
|
|
|
if(!"2".equals(recordDO.getStatus())){
|
|
|
return "只有待支付的订单才能取消";
|
|
|
}
|
|
|
recordDO.setStatus("7");
|
|
|
courseSalesOrderRecordDao.save(recordDO);
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 订单详情接口
|
|
|
* @param id
|
|
|
* @param type
|
|
|
*/
|
|
|
public JSONObject orderInfo(String id,String type){
|
|
|
JSONObject resJson = new JSONObject();
|
|
|
resJson.put("type",type);
|
|
|
resJson.put("id",id);
|
|
|
String status = "";
|
|
|
if("1".equals(type)){
|
|
|
//招生
|
|
|
RecruitStudentsRecordDO recordDO = recruitStudentsRecordDao.findOne(id);
|
|
|
status = recordDO.getStatus();
|
|
|
resJson.put("title",recordDO.getRecruitName());
|
|
|
resJson.put("status",recordDO.getStatus());
|
|
|
resJson.put("price",recordDO.getPrice());
|
|
|
resJson.put("orderNo",recordDO.getOrderNo());
|
|
|
}else if("2".equals(type)){
|
|
|
//课程
|
|
|
CourseSalesOrderRecordDO recordDO = courseSalesOrderRecordDao.findOne(id);
|
|
|
status = recordDO.getStatus();
|
|
|
resJson.put("title",recordDO.getCourseName());
|
|
|
resJson.put("status",recordDO.getStatus());
|
|
|
resJson.put("price",recordDO.getPrice());
|
|
|
resJson.put("orderNo",recordDO.getOrderNo());
|
|
|
}
|
|
|
boolean flag = "3".equals(status)||"5".equals(status)||"6".equals(status);
|
|
|
if(flag){
|
|
|
//支付信息
|
|
|
BusinessOrderDO businessOrderDO = businessOrderDao.selectByRelationCode(id);
|
|
|
if(businessOrderDO!=null){
|
|
|
JSONObject json = new JSONObject();
|
|
|
json.put("payPrice",businessOrderDO.getPayPrice());
|
|
|
json.put("payTime",DateUtil.dateToStrLong(businessOrderDO.getPayTime()));
|
|
|
json.put("payType",businessOrderDO.getPayType());
|
|
|
resJson.put("businessOrderDO",json);
|
|
|
}
|
|
|
}
|
|
|
if("5".equals(status)||"6".equals(status)){
|
|
|
//退款信息
|
|
|
PatientOrderRefundDO refundDO = patientOrderRefundDao.findByTypeAndOrderId(type,id);
|
|
|
if(refundDO!=null){
|
|
|
JSONObject json = new JSONObject();
|
|
|
json.put("createTime", DateUtil.dateToStrLong(refundDO.getCreateTime()));
|
|
|
json.put("refundPrice",refundDO.getRefundPrice());
|
|
|
json.put("status",refundDO.getStatus());
|
|
|
json.put("refundDesc",refundDO.getRefundDesc());
|
|
|
json.put("enclosure",refundDO.getEnclosure());
|
|
|
resJson.put("refundDO",json);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
return resJson;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 顶部状态栏订单各分类总条数
|
|
|
* 待审核 1 待支付 2 已支付 3 审核未通过 4 已退款 5 退款中 6 已取消 7
|
|
|
* @param patient
|
|
|
* @return
|
|
|
*/
|
|
@ -55,12 +164,14 @@ public class CourseService {
|
|
|
|
|
|
List<Map<String, Object>> list = jdbcTemplate.queryForList(sql);
|
|
|
Map<String, Integer> map = new HashMap<>();
|
|
|
//状态 待服务 1、已完成 2 、已取消 -1
|
|
|
//状态 待审核 1 待支付 2 已支付 3 审核未通过 4 已退款 5 退款中 6 已取消 7
|
|
|
map.put("1",0);
|
|
|
map.put("2",0);
|
|
|
map.put("3",0);
|
|
|
map.put("4",0);
|
|
|
map.put("5",0);
|
|
|
map.put("6",0);
|
|
|
map.put("7",0);
|
|
|
int total = 0;
|
|
|
if(list.size()>0){
|
|
|
for (Map<String, Object> one:list){
|
|
@ -69,79 +180,125 @@ public class CourseService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
map.put("total", total);
|
|
|
return map;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 新增课程
|
|
|
* @param doctorId
|
|
|
* @param jsonData
|
|
|
* @return
|
|
|
*/
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public JSONObject addCourse(String doctorId,String jsonData){
|
|
|
JSONObject result = new JSONObject();
|
|
|
JSONObject json = JSON.parseObject(jsonData);
|
|
|
BaseDoctorDO doctorDO = doctorDao.findById(doctorId);
|
|
|
List<BaseDoctorHospitalDO> baseDoctorHospitalDO = baseDoctorHospitalDao.findByDoctorCode(doctorId);
|
|
|
CourseDO courseDO = null;
|
|
|
try{
|
|
|
courseDO = objectMapper.readValue(json.getJSONObject("course").toString(), CourseDO.class);
|
|
|
}catch (Exception e){
|
|
|
e.printStackTrace();
|
|
|
result.put(ResponseContant.resultFlag, ResponseContant.fail);
|
|
|
result.put(ResponseContant.resultMsg, "传参有误");
|
|
|
}
|
|
|
|
|
|
public JSONObject patientOrderList(String patient, Integer status, int page, int size) {
|
|
|
courseDO.setStatus("1");
|
|
|
courseDO.setDel(1);
|
|
|
courseDO.setDoctor(doctorId);
|
|
|
courseDO.setDoctorName(doctorDO.getName());
|
|
|
courseDO.setOrgCode(baseDoctorHospitalDO.get(0).getOrgCode());
|
|
|
courseDO.setOrgName(baseDoctorHospitalDO.get(0).getOrgName());
|
|
|
if("1".equals(courseDO.getType())){
|
|
|
//直播课程
|
|
|
courseDO.setLiveStatus("1");
|
|
|
}
|
|
|
|
|
|
result.put(ResponseContant.resultFlag, ResponseContant.success);
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 教师我的课程
|
|
|
* @param doctor
|
|
|
* @param page
|
|
|
* @param size
|
|
|
* @return
|
|
|
*/
|
|
|
public JSONObject myCourseList(String doctor,String type, int page, int size) {
|
|
|
JSONObject result = new JSONObject();
|
|
|
int start = 0 == page ? page++ : (page - 1) * size;
|
|
|
int end = 0 == size ? 15 : size;
|
|
|
StringBuffer buffer = new StringBuffer();
|
|
|
|
|
|
String sql = "SELECT " +
|
|
|
" p.name AS patientName, " +
|
|
|
" p.photo AS photo, " +
|
|
|
" p.idcard," +
|
|
|
" case p.sex " +
|
|
|
" when 1 then '男' " +
|
|
|
" when 2 then '女' " +
|
|
|
" end AS sex, " +
|
|
|
" TIMESTAMPDIFF(year,p.birthday,NOW()) AS age," +
|
|
|
" o.id as orderId, " +
|
|
|
" o.patient_phone as phone, " +
|
|
|
" o.proxy_patient as proxyPatient, " +
|
|
|
" o.patient as patient, " +
|
|
|
" o.number as number, " +
|
|
|
" o.patient_expected_serve_time as serveTime, o.doctor, o.doctor_name as doctorName, " +
|
|
|
" o.serve_address as address, " +
|
|
|
" o.type as type, " +
|
|
|
" o.serve_lon as lon, " +
|
|
|
" o.serve_lat as lat, " +
|
|
|
" o.`status` as status " +
|
|
|
" FROM " +
|
|
|
" ( base_life_care_order o " +
|
|
|
" LEFT JOIN base_patient p ON o.patient = p.id ) "+
|
|
|
" WHERE " +
|
|
|
" o.hospital = '{hospital}' and o.type != 3 " +buffer+
|
|
|
" AND ( o.`status` = {status} OR -100 = {status} ) " +
|
|
|
" ORDER BY o.create_time desc " +
|
|
|
int end = 0 == size ? 3 : size;
|
|
|
String filter = " where a.doctor = '"+doctor+"' ";
|
|
|
if(!StringUtil.isBlank(type)){
|
|
|
filter += " and a.type = '"+type+"' ";
|
|
|
}
|
|
|
String sql = "SELECT * from base_course a " +filter +
|
|
|
" ORDER BY a.create_time desc " +
|
|
|
" LIMIT {start},{end};";
|
|
|
|
|
|
String finalSql = sql.replace("{status}", String.valueOf(status))
|
|
|
.replace("{start}", String.valueOf(start))
|
|
|
String finalSql = sql.replace("{start}", String.valueOf(start))
|
|
|
.replace("{end}", String.valueOf(end));
|
|
|
|
|
|
String countSql = "SELECT " +
|
|
|
" count(o.id) " +
|
|
|
" FROM " +
|
|
|
" base_life_care_order o " +
|
|
|
" LEFT JOIN base_patient p ON o.patient = p.id " +
|
|
|
" WHERE " +
|
|
|
" o.hospital = '{hospital}' " +buffer+
|
|
|
" AND (o.`status` = {status} or -100 = {status})";
|
|
|
String countSql = "SELECT count(a.id) FROM base_course a " +filter ;
|
|
|
List<CourseDO> sqlResultlist = jdbcTemplate.query(finalSql,new BeanPropertyRowMapper<>(CourseDO.class));
|
|
|
Long count = jdbcTemplate.queryForObject(countSql, Long.class);
|
|
|
|
|
|
String finqlCountSql = countSql.replace("{hospital}", hospital)
|
|
|
.replace("{status}", String.valueOf(status));
|
|
|
result.put(ResponseContant.resultFlag, ResponseContant.success);
|
|
|
result.put(ResponseContant.resultMsg, sqlResultlist);
|
|
|
JSONObject countItem = new JSONObject();
|
|
|
countItem.put("count", count);
|
|
|
result.putAll(countItem);
|
|
|
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 居民我的订单列表
|
|
|
* @param patient
|
|
|
* @param status
|
|
|
* @param page
|
|
|
* @param size
|
|
|
* @return
|
|
|
*/
|
|
|
public JSONObject patientOrderList(String patient, String status, int page, int size) {
|
|
|
JSONObject result = new JSONObject();
|
|
|
int start = 0 == page ? page++ : (page - 1) * size;
|
|
|
int end = 0 == size ? 15 : size;
|
|
|
String filter = " where patient = '"+patient+"' ";
|
|
|
if(!StringUtil.isEmpty(status)){
|
|
|
filter += " and status = "+ status +" ";
|
|
|
}
|
|
|
|
|
|
String sqlUnion = " SELECT id,`status`,recruit_name title,pay_type payType,price,1 type,DATE_FORMAT(create_time,'%Y-%m-%d %H:%i:%s') createTime " +
|
|
|
" from base_recruit_students_record " + filter+
|
|
|
" UNION ALL " +
|
|
|
" SELECT id,`status`,course_name title,pay_type payType,price,2 type,DATE_FORMAT(create_time,'%Y-%m-%d %H:%i:%s') createTime " +
|
|
|
" from base_course_sales_order_record " + filter+" ";
|
|
|
|
|
|
String sql = "SELECT * from ( " + sqlUnion + " ) a " +
|
|
|
" ORDER BY a.createTime desc " +
|
|
|
" LIMIT {start},{end};";
|
|
|
String finalSql = sql.replace("{start}", String.valueOf(start))
|
|
|
.replace("{end}", String.valueOf(end));
|
|
|
|
|
|
String countSql = "SELECT count(a.id) FROM ( " + sqlUnion + " ) a " ;
|
|
|
List<Map<String,Object>> sqlResultlist;
|
|
|
try {
|
|
|
sqlResultlist = jdbcTemplate.queryForList(finalSql);
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
result.put(ResponseContant.resultFlag, ResponseContant.fail);
|
|
|
result.put(ResponseContant.resultMsg, "从数据库查询生活照料工单列表信息失败");
|
|
|
result.put(ResponseContant.resultMsg, "从数据库查询工单列表信息失败");
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
Long count;
|
|
|
try {
|
|
|
count = jdbcTemplate.queryForObject(finqlCountSql, Long.class);
|
|
|
count = jdbcTemplate.queryForObject(countSql, Long.class);
|
|
|
} catch (Exception e) {
|
|
|
result.put(ResponseContant.resultFlag, ResponseContant.fail);
|
|
|
result.put(ResponseContant.resultMsg, "从数据库统计生活照料工单数量失败" );
|
|
|
result.put(ResponseContant.resultMsg, "从数据库统计工单数量失败" );
|
|
|
return result;
|
|
|
}
|
|
|
|