Pārlūkot izejas kodu

[物联网大屏统计接口]

wangzhinan 3 gadi atpakaļ
vecāks
revīzija
84718e3482

+ 5 - 0
common/common-request-mapping/src/main/java/com/yihu/jw/rm/base/BaseRequestMapping.java

@ -228,6 +228,11 @@ public class BaseRequestMapping {
        public static final String getDeviceList = "/getDeviceList";
        public static final String getDeviceInfo = "/getDeviceInfo";
        public static final String getDeviceStatistics = "/getDeviceStatistics";
        public static final String getDevicePriceStatistics = "/getDevicePriceStatistics";
        public static final String getShippingType = "/getShippingType";
        public static final String getPrescriptionStatics = "/getPrescriptionStatics";
    }
    /**

+ 28 - 0
common/common-util/src/main/java/com/yihu/jw/util/date/DateUtil.java

@ -1469,4 +1469,32 @@ public class DateUtil {
        return calendar.getTime();
    }
    public static List<String> findDates(String dBegin, String dEnd) throws ParseException, java.text.ParseException {
        //日期工具类准备
        DateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        //设置开始时间
        Calendar calBegin = Calendar.getInstance();
        calBegin.setTime(format.parse(dBegin));
        //设置结束时间
        Calendar calEnd = Calendar.getInstance();
        calEnd.setTime(format.parse(dEnd));
        //装返回的日期集合容器
        List<String> Datelist = new ArrayList<String>();
        //将第一个月添加里面去
        Datelist.add(format.format(calBegin.getTime()));
        // 每次循环给calBegin日期加一天,直到calBegin.getTime()时间等于dEnd
        while (format.parse(dEnd).after(calBegin.getTime()))  {
            // 根据日历的规则,为给定的日历字段添加或减去指定的时间量
            calBegin.add(Calendar.DAY_OF_MONTH, 1);
            Datelist.add(format.format(calBegin.getTime()));
        }
        System.out.println(Datelist);
        return Datelist;
    }
}

+ 51 - 0
svr/svr-base/src/main/java/com/yihu/jw/base/endpoint/a4endpoint/MedicineDeviceEndpoint.java

@ -659,4 +659,55 @@ public class MedicineDeviceEndpoint extends EnvelopRestEndpoint {
    }
    @GetMapping(value = BaseRequestMapping.BaseDevice.getDeviceStatistics)
    @ApiOperation(value = "总览-设备", notes = "总览-设备")
    public Envelop getDeviceStatistics(
            @ApiParam(name = "area", value = "对应级别code", required = true)
            @RequestParam(value = "area", required = true) String area,
            @ApiParam(name = "startTime", value = "开始时间", required = false)
            @RequestParam(value = "startTime", required = false) String startTime,
            @ApiParam(name = "endTime", value = "结束时间", required = false)
            @RequestParam(value = "endTime", required = false) String endTime,
            @ApiParam(name = "level", value = "1、市级、2、区级、3、社区", required = true)
            @RequestParam(value = "level", required = true) Integer level) throws Exception {
        return success(deviceService.getDeviceStatistics(level,area, startTime, endTime));
    }
    @GetMapping(value = BaseRequestMapping.BaseDevice.getDevicePriceStatistics)
    @ApiOperation(value = "总览-销量", notes = "总览-销量")
    public Envelop getDevicePriceStatistics(
            @ApiParam(name = "area", value = "对应级别code", required = true)
            @RequestParam(value = "area", required = true) String area,
            @ApiParam(name = "day", value = "天数", required = false)
            @RequestParam(value = "day", required = false) Integer day,
            @ApiParam(name = "level", value = "1、市级、2、区级、3、社区", required = true)
            @RequestParam(value = "level", required = true) Integer level) throws Exception {
        return success(deviceService.getDevicePriceStatistics(level,area, day));
    }
    @GetMapping(value = BaseRequestMapping.BaseDevice.getShippingType)
    @ApiOperation(value = "总览-取药情况统计", notes = "总览-取药情况统计")
    public Envelop getShippingType(
            @ApiParam(name = "area", value = "对应级别code", required = true)
            @RequestParam(value = "area", required = true) String area,
            @ApiParam(name = "day", value = "天数", required = false)
            @RequestParam(value = "day", required = false) Integer day,
            @ApiParam(name = "level", value = "1、市级、2、区级、3、社区", required = true)
            @RequestParam(value = "level", required = true) Integer level) throws Exception {
        return success(deviceService.getShippingType(level,area, day));
    }
    @GetMapping(value = BaseRequestMapping.BaseDevice.getPrescriptionStatics)
    @ApiOperation(value = "总览-处方订单情况统计", notes = "总览-处方订单情况统计")
    public Envelop getPrescriptionStatics(
            @ApiParam(name = "area", value = "对应级别code", required = true)
            @RequestParam(value = "area", required = true) String area,
            @ApiParam(name = "day", value = "天数", required = false)
            @RequestParam(value = "day", required = false) Integer day,
            @ApiParam(name = "level", value = "1、市级、2、区级、3、社区", required = true)
            @RequestParam(value = "level", required = true) Integer level) throws Exception {
        return success(deviceService.getPrescriptionStatics(level,area, day));
    }
}

+ 248 - 9
svr/svr-base/src/main/java/com/yihu/jw/base/service/a3service/MedicinedeviceService.java

@ -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;
    }
}