|
@ -21,6 +21,7 @@ import com.yihu.jw.util.date.DateUtil;
|
|
|
import com.yihu.jw.utils.StringUtil;
|
|
|
import com.yihu.jw.utils.hibernate.HibenateUtils;
|
|
|
import com.yihu.mysql.query.BaseJpaService;
|
|
|
import org.jsoup.helper.DataUtil;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
@ -29,10 +30,9 @@ import org.springframework.util.StringUtils;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.util.Date;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.text.DecimalFormat;
|
|
|
import java.text.ParseException;
|
|
|
import java.util.*;
|
|
|
import java.util.logging.Logger;
|
|
|
|
|
|
/**
|
|
@ -3445,7 +3445,7 @@ public class MedicinedeviceService extends BaseJpaService<Mediicinedevice, Medi
|
|
|
* 物联网大屏单个设备信息数据
|
|
|
* @return
|
|
|
*/
|
|
|
public JSONObject getDeviceInfo(String deviceId,Integer day){
|
|
|
public JSONObject getDeviceInfo(String deviceId,Integer day) throws ParseException {
|
|
|
JSONObject jsonObject = new JSONObject();
|
|
|
Mediicinedevice mediicinedevice = deviceDao.findOne(deviceId);
|
|
|
jsonObject.put("device",mediicinedevice);
|
|
@ -3455,16 +3455,36 @@ public class MedicinedeviceService extends BaseJpaService<Mediicinedevice, Medi
|
|
|
//扫码
|
|
|
String saomasql = "SELECT DATE_FORMAT(o.shipping_time, \"%Y-%m-%d\") as \"date\", COUNT(1) AS \"count\" FROM " +
|
|
|
"t_mediicine_order o WHERE o.sell_state=1 AND o.shipping_type=1 " +condition+
|
|
|
"GROUP BY DATE_FORMAT(o.shipping_time, \"%Y-%m-%d\") ORDER BY DATE_FORMAT(o.shipping_time, \"%Y-%m-%d\") ASC";
|
|
|
" GROUP BY DATE_FORMAT(o.shipping_time, \"%Y-%m-%d\") ORDER BY DATE_FORMAT(o.shipping_time, \"%Y-%m-%d\") ASC";
|
|
|
//医保
|
|
|
String yibaosql = "SELECT DATE_FORMAT(o.shipping_time, \"%Y-%m-%d\") as \"date\", COUNT(1) AS \"count\" FROM " +
|
|
|
"t_mediicine_order o WHERE o.sell_state=1 AND o.shipping_type=2 " +condition+
|
|
|
"GROUP BY DATE_FORMAT(o.shipping_time, \"%Y-%m-%d\") ORDER BY DATE_FORMAT(o.shipping_time, \"%Y-%m-%d\") ASC";
|
|
|
" GROUP BY DATE_FORMAT(o.shipping_time, \"%Y-%m-%d\") ORDER BY DATE_FORMAT(o.shipping_time, \"%Y-%m-%d\") ASC";
|
|
|
|
|
|
List<Map<String,Object>> saomadateList = DateUtil.findDates(startDate,DateUtil.getNowDate());
|
|
|
List<Map<String,Object>> saomaList = jdbcTemplate.queryForList(saomasql);
|
|
|
for (Map<String,Object> map:saomadateList){
|
|
|
String date = map.get("date").toString();
|
|
|
for (Map<String,Object> objectMap:saomaList){
|
|
|
String date1 = objectMap.get("date").toString();
|
|
|
if (date1.equalsIgnoreCase(date)){
|
|
|
map.put("count",objectMap.get("count"));
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
List<Map<String,Object>> yibaodateList = DateUtil.findDates(startDate,DateUtil.getNowDate());
|
|
|
List<Map<String,Object>> yibaoList = jdbcTemplate.queryForList(yibaosql);
|
|
|
jsonObject.put("saomaList",saomaList);
|
|
|
jsonObject.put("yibaoList",yibaoList);
|
|
|
for (Map<String,Object> map:yibaodateList){
|
|
|
String date = map.get("date").toString();
|
|
|
for (Map<String,Object> objectMap:yibaoList){
|
|
|
String date1 = objectMap.get("date").toString();
|
|
|
if (date1.equalsIgnoreCase(date)){
|
|
|
map.put("count",objectMap.get("count"));
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
jsonObject.put("saomaList",saomadateList);
|
|
|
jsonObject.put("yibaoList",yibaodateList);
|
|
|
|
|
|
String shippingTypeTotal = "SELECT o.shipping_type as \"shippingType\", COUNT(1) as \"count\" FROM t_mediicine_order o " +
|
|
|
" WHERE o.sell_state=1 "+condition+" GROUP BY o.shipping_type";
|
|
@ -3486,4 +3506,223 @@ public class MedicinedeviceService extends BaseJpaService<Mediicinedevice, Medi
|
|
|
return jsonObject;
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 总览-设备
|
|
|
* @param level 1、市级、2、区级、3、社区
|
|
|
* @param area 对应级别code
|
|
|
* @return
|
|
|
*/
|
|
|
public JSONObject getDeviceStatistics(int level,String area,String startTime,String endTime){
|
|
|
JSONObject object = new JSONObject();
|
|
|
String condition = "";
|
|
|
if (level==1){
|
|
|
condition = "";
|
|
|
}else if (level==2){
|
|
|
condition = " and d.belong_community IN (select h.code from dm_hospital h where h.town = '"+area+"') ";
|
|
|
}else if (level==3){
|
|
|
condition = " and d.belong_community ='"+area+"' ";
|
|
|
}
|
|
|
//设备总数
|
|
|
String total = "SELECT COUNT(1) as \"count\" FROM t_mediicine_device d WHERE d.del=1 "+condition;
|
|
|
//在线设备
|
|
|
String onlineTotal = total + " and d.network_status = 1 ";
|
|
|
//离线设备
|
|
|
String noOnlineTotal = total + " and d.network_status = 0 ";
|
|
|
//未分配
|
|
|
String noDistributionTotal = total + " and d.belong_community is null ";
|
|
|
Map<String,Object> totalMap = jdbcTemplate.queryForMap(total);
|
|
|
Map<String,Object> onlineTotalMap = jdbcTemplate.queryForMap(onlineTotal);
|
|
|
Map<String,Object> noOnlineTotalMap = jdbcTemplate.queryForMap(noOnlineTotal);
|
|
|
Map<String,Object> noDistributionTotalMap = jdbcTemplate.queryForMap(noDistributionTotal);
|
|
|
Double onlineTotal1 = 0.0;
|
|
|
Double total1 = 0.0;
|
|
|
Integer noOnlineTotal1 = 0;
|
|
|
Integer noDistributionTotal1 = 0;
|
|
|
if (onlineTotalMap!=null){
|
|
|
onlineTotal1 = Double.parseDouble(onlineTotalMap.get("count").toString());
|
|
|
}
|
|
|
if (totalMap!=null){
|
|
|
total1 = Double.parseDouble(totalMap.get("count").toString());
|
|
|
}
|
|
|
if (noOnlineTotalMap!=null){
|
|
|
noOnlineTotal1 = Integer.parseInt(noOnlineTotalMap.get("count").toString());
|
|
|
}
|
|
|
if (noDistributionTotalMap!=null){
|
|
|
noDistributionTotal1 = Integer.parseInt(noDistributionTotalMap.get("count").toString());
|
|
|
}
|
|
|
DecimalFormat df = new DecimalFormat("#.##");
|
|
|
String rate = df.format(onlineTotal1/total1);
|
|
|
Double rate1 = Double.parseDouble(rate)*100;
|
|
|
String onlineRate = rate1+"%";
|
|
|
object.put("total",total1);
|
|
|
object.put("onlineTotal",onlineTotal1);
|
|
|
object.put("onlineRate",onlineRate);
|
|
|
object.put("noOnlineTotal",noOnlineTotal1);
|
|
|
object.put("noDistributionTotal",noDistributionTotal1);
|
|
|
return object;
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 总览-销售额
|
|
|
* @param level 1、市级、2、区级、3、社区
|
|
|
* @param area
|
|
|
* @return
|
|
|
*/
|
|
|
public JSONObject getDevicePriceStatistics(int level,String area,int day){
|
|
|
JSONObject object = new JSONObject();
|
|
|
String condition = "";
|
|
|
if (level==1){
|
|
|
condition = "";
|
|
|
}else if (level==2){
|
|
|
condition = " o.shipping_equ IN (select d.equ_num from t_mediicine_device d where d.belong_community IN (select h.code from dm_hospital h where h.town = '"+area+"')) ";
|
|
|
}else if (level==3){
|
|
|
condition = " o.shipping_equ IN (select d.equ_num from t_mediicine_device d where d.belong_community = '"+area+"') ";
|
|
|
}
|
|
|
Date startDate = null;
|
|
|
if (day==1){
|
|
|
startDate = DateUtil.strToDateLong(DateUtil.getStringDateShort()+" 00:00:00");
|
|
|
}else {
|
|
|
startDate = DateUtil.getPreDays(new Date(),-day);
|
|
|
}
|
|
|
|
|
|
String endTime = DateUtil.getStringDate();
|
|
|
String timeCondition = " and o.shipping_time >='"+DateUtil.dateToStrLong(startDate)+"' and o.shipping_time <= '"+endTime+"' ";
|
|
|
String sql = "SELECT SUM(o.order_amount) as \"amount\" FROM t_mediicine_order o WHERE o.sell_state=1 "+condition+ timeCondition;
|
|
|
Map<String,Object> totalMap = jdbcTemplate.queryForMap(sql);
|
|
|
DecimalFormat df = new DecimalFormat("#.##");
|
|
|
String amount ="";
|
|
|
if (totalMap!=null){
|
|
|
if (totalMap.get("amount")!=null){
|
|
|
amount = df.format(Double.parseDouble(totalMap.get("amount").toString()));
|
|
|
}else {
|
|
|
amount="0";
|
|
|
}
|
|
|
|
|
|
}
|
|
|
object.put("amount",amount);
|
|
|
String lineSql = "SELECT DATE_FORMAT(o.shipping_time, \"%Y-%m-%d\") as \"date\",SUM(o.order_amount) as \"amount\" FROM t_mediicine_order o WHERE o.sell_state=1 "+condition+ timeCondition +" GROUP BY DATE_FORMAT(o.shipping_time, \"%Y-%m-%d\") ";
|
|
|
List<Map<String,Object>> amountdateList = DateUtil.findDates(startDate,DateUtil.getNowDate());
|
|
|
List<Map<String,Object>> amountLine = jdbcTemplate.queryForList(lineSql);
|
|
|
for (Map<String,Object> map:amountdateList){
|
|
|
String date = map.get("date").toString();
|
|
|
for (Map<String,Object> objectMap:amountLine){
|
|
|
String date1 = objectMap.get("date").toString();
|
|
|
if (date1.equalsIgnoreCase(date)){
|
|
|
map.put("count",objectMap.get("amount"));
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
object.put("amountdateList",amountdateList);
|
|
|
return object;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 总览-取药情况统计
|
|
|
* @param level 1、市级、2、区级、3、社区
|
|
|
* @param area
|
|
|
* @return
|
|
|
*/
|
|
|
public JSONObject getShippingType(int level,String area,int day){
|
|
|
JSONObject object = new JSONObject();
|
|
|
String condition = "";
|
|
|
if (level==1){
|
|
|
condition = "";
|
|
|
}else if (level==2){
|
|
|
condition = " o.shipping_equ IN (select d.equ_num from t_mediicine_device d where d.belong_community IN (select h.code from dm_hospital h where h.town = '"+area+"')) ";
|
|
|
}else if (level==3){
|
|
|
condition = " o.shipping_equ IN (select d.equ_num from t_mediicine_device d where d.belong_community = '"+area+"') ";
|
|
|
}
|
|
|
Date startDate = null;
|
|
|
if (day==1){
|
|
|
startDate = DateUtil.strToDateLong(DateUtil.getStringDateShort()+" 00:00:00");
|
|
|
}else {
|
|
|
startDate = DateUtil.getPreDays(new Date(),-day);
|
|
|
}
|
|
|
|
|
|
String endTime = DateUtil.getStringDate();
|
|
|
String timeCondition = " and o.shipping_time >='"+DateUtil.dateToStrLong(startDate)+"' and o.shipping_time <= '"+endTime+"' ";
|
|
|
String sql = "SELECT count(1) as \"count\" FROM t_mediicine_order o WHERE o.sell_state=1 "+condition+ timeCondition;
|
|
|
Map<String,Object> totalMap = jdbcTemplate.queryForMap(sql);
|
|
|
int total =0;
|
|
|
if (totalMap!=null){
|
|
|
if (totalMap.get("count")!=null){
|
|
|
total = Integer.parseInt(totalMap.get("count").toString());
|
|
|
}
|
|
|
|
|
|
}
|
|
|
object.put("total",total);
|
|
|
//扫码次数
|
|
|
String saomaSql = sql + " and o.shipping_type =1 ";
|
|
|
Map<String,Object> saomaTotalMap = jdbcTemplate.queryForMap(saomaSql);
|
|
|
int saomaTotal =0;
|
|
|
if (saomaTotalMap!=null){
|
|
|
if (saomaTotalMap.get("count")!=null){
|
|
|
saomaTotal = Integer.parseInt(saomaTotalMap.get("count").toString());
|
|
|
}
|
|
|
|
|
|
}
|
|
|
//医保卡次数
|
|
|
String yibaoSql = sql + " and o.shipping_type =2 ";
|
|
|
Map<String,Object> yibaoTotalMap = jdbcTemplate.queryForMap(yibaoSql);
|
|
|
int yibaoTotal =0;
|
|
|
if (yibaoTotalMap!=null){
|
|
|
if (yibaoTotalMap.get("count")!=null){
|
|
|
yibaoTotal = Integer.parseInt(yibaoTotalMap.get("count").toString());
|
|
|
}
|
|
|
|
|
|
}
|
|
|
object.put("saomaTotal",saomaTotal);
|
|
|
object.put("yibaoTotal",yibaoTotal);
|
|
|
return object;
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 总览-处方订单情况统计
|
|
|
* @param level 1、市级、2、区级、3、社区
|
|
|
* @param area
|
|
|
* @return
|
|
|
*/
|
|
|
public JSONObject getPrescriptionStatics(int level,String area,int day){
|
|
|
JSONObject object = new JSONObject();
|
|
|
String condition = "";
|
|
|
if (level==1){
|
|
|
condition = "";
|
|
|
}else if (level==2){
|
|
|
condition = " o.belong_community IN (select h.code from dm_hospital h where h.town = '"+area+"') ";
|
|
|
}else if (level==3){
|
|
|
condition = " o.belong_community = '"+area+"' ";
|
|
|
}
|
|
|
Date startDate = null;
|
|
|
if (day==1){
|
|
|
startDate = DateUtil.strToDateLong(DateUtil.getStringDateShort()+" 00:00:00");
|
|
|
}else {
|
|
|
startDate = DateUtil.getPreDays(new Date(),-day);
|
|
|
}
|
|
|
|
|
|
String endTime = DateUtil.getStringDate();
|
|
|
String timeCondition = " and o.create_time >='"+DateUtil.dateToStrLong(startDate)+"' and o.create_time <= '"+endTime+"' ";
|
|
|
String sql = "SELECT count(1) as \"count\" FROM t_mediicine_order o WHERE 1=1 "+condition+ timeCondition;
|
|
|
Map<String,Object> totalMap = jdbcTemplate.queryForMap(sql);
|
|
|
int total =0;
|
|
|
if (totalMap!=null){
|
|
|
if (totalMap.get("count")!=null){
|
|
|
total = Integer.parseInt(totalMap.get("count").toString());
|
|
|
}
|
|
|
|
|
|
}
|
|
|
object.put("total",total);
|
|
|
String drugSql = "select sum(od.quantity) as quantity from t_mediicine_order_detail od where od.id_order IN (SELECT o.id as id FROM t_mediicine_order o WHERE 1=1 "+condition+ timeCondition+")";
|
|
|
Map<String,Object> drugTotalMap = jdbcTemplate.queryForMap(drugSql);
|
|
|
Double quantity =0.0;
|
|
|
if (drugTotalMap!=null){
|
|
|
if (drugTotalMap.get("quantity")!=null){
|
|
|
quantity = Double.parseDouble(drugTotalMap.get("quantity").toString());
|
|
|
}
|
|
|
}
|
|
|
object.put("drugTotal",quantity);
|
|
|
return object;
|
|
|
}
|
|
|
}
|