|  | @ -13,15 +13,24 @@ import com.yihu.jw.entity.base.role.RoleDO;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.base.user.UserDO;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.hospital.DmHospitalDO;
 | 
	
		
			
				|  |  | import com.yihu.jw.hospital.HospitalDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.restmodel.web.Envelop;
 | 
	
		
			
				|  |  | import com.yihu.jw.restmodel.web.MixEnvelop;
 | 
	
		
			
				|  |  | import com.yihu.jw.rm.hospital.BaseHospitalRequestMapping;
 | 
	
		
			
				|  |  | import com.yihu.jw.util.date.DateUtil;
 | 
	
		
			
				|  |  | import com.yihu.jw.utils.hibernate.HibenateUtils;
 | 
	
		
			
				|  |  | import com.yihu.mysql.query.BaseJpaService;
 | 
	
		
			
				|  |  | import jxl.format.VerticalAlignment;
 | 
	
		
			
				|  |  | import jxl.write.*;
 | 
	
		
			
				|  |  | import org.apache.commons.collections4.IterableUtils;
 | 
	
		
			
				|  |  | import org.springframework.beans.factory.annotation.Autowired;
 | 
	
		
			
				|  |  | import org.springframework.stereotype.Service;
 | 
	
		
			
				|  |  | import org.springframework.transaction.annotation.Transactional;
 | 
	
		
			
				|  |  | import org.springframework.util.StringUtils;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | import java.awt.print.Pageable;
 | 
	
		
			
				|  |  | import java.io.IOException;
 | 
	
		
			
				|  |  | import java.io.OutputStream;
 | 
	
		
			
				|  |  | import java.lang.Boolean;
 | 
	
		
			
				|  |  | import java.util.*;
 | 
	
		
			
				|  |  | import java.util.logging.Logger;
 | 
	
		
			
				|  |  | import java.util.stream.Collectors;
 | 
	
	
		
			
				|  | @ -1480,4 +1489,246 @@ public class MedicineOrderService extends BaseJpaService<Mediicineorder, Mediici
 | 
	
		
			
				|  |  |         result.put("msg", jsonObject);
 | 
	
		
			
				|  |  |         return result;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     public MixEnvelop getSumAmountExcel(String belongCommunity, String equNum, String startTime, String endTime,int page,int size) {
 | 
	
		
			
				|  |  |         List<Map<String,Object>> mapList=new ArrayList<>();
 | 
	
		
			
				|  |  |         Map<String,Object> countMap = new HashMap<>();
 | 
	
		
			
				|  |  |         //第几页
 | 
	
		
			
				|  |  |         countMap.put("page",page);
 | 
	
		
			
				|  |  |         //多少条
 | 
	
		
			
				|  |  |         countMap.put("size",size);
 | 
	
		
			
				|  |  |         page = (page - 1) * size;
 | 
	
		
			
				|  |  |         //查询出所有的设备
 | 
	
		
			
				|  |  |         Iterable <Mediicinedevice> mediicinedevices = deviceDao.findDeviceAll(page,size);
 | 
	
		
			
				|  |  |         List<Mediicinedevice> mediicinedeviceList= IterableUtils.toList(mediicinedevices);
 | 
	
		
			
				|  |  |         String countSql = " select " +
 | 
	
		
			
				|  |  |                 "     COUNT(DISTINCT (t.id)) as count " +
 | 
	
		
			
				|  |  |                 "   from " +
 | 
	
		
			
				|  |  |                 "     t_mediicine_device as t " +
 | 
	
		
			
				|  |  |                 "  where " +
 | 
	
		
			
				|  |  |                 "  1=1   " ;
 | 
	
		
			
				|  |  |         Logger.getAnonymousLogger().info("finalCountSql="+countSql);
 | 
	
		
			
				|  |  |         int decCount = jdbcTemplate.queryForObject(countSql,Integer.class);
 | 
	
		
			
				|  |  |         //总页数
 | 
	
		
			
				|  |  |         int total=decCount/size+(decCount%size>0?1:0);
 | 
	
		
			
				|  |  |         countMap.put("total",total);
 | 
	
		
			
				|  |  |         //总条数
 | 
	
		
			
				|  |  |         countMap.put("count",decCount);
 | 
	
		
			
				|  |  |         mapList.add(countMap);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         //将同一个设备的社区/名称/设备编码/历史记录/总金额放到一个Map中,并将这些Map放到同一个list中返回
 | 
	
		
			
				|  |  |         for (Mediicinedevice mediicinedevice:mediicinedeviceList){
 | 
	
		
			
				|  |  |             Map<String,Object> map=new HashMap<>();
 | 
	
		
			
				|  |  |             map.put("community",mediicinedevice.getCommunity());
 | 
	
		
			
				|  |  |             map.put("equName",mediicinedevice.getEquNum()+(mediicinedevice.getEquName()==null?"":"/"+mediicinedevice.getEquName()));
 | 
	
		
			
				|  |  |             String oneSql="SELECT SUM(t.amount) AS sumAmount,\n" +
 | 
	
		
			
				|  |  |                     "                COUNT(*) AS count,\n" +
 | 
	
		
			
				|  |  |                     "                t.shipping_equ AS equNum\n" +
 | 
	
		
			
				|  |  |                     "                FROM t_mediicine_order  t WHERE t.sell_state = 1 AND t.shipping_equ = '" + mediicinedevice.getEquNum()+"'";
 | 
	
		
			
				|  |  |             String conditionSql="";
 | 
	
		
			
				|  |  |             if (org.apache.commons.lang3.StringUtils.isNoneBlank(belongCommunity)){
 | 
	
		
			
				|  |  |                 conditionSql += "AND t.belong_community ='"+belongCommunity+"'";
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             if (org.apache.commons.lang3.StringUtils.isNoneBlank(equNum)){
 | 
	
		
			
				|  |  |                 conditionSql += "AND t.shipping_equ = '" + equNum + "'";
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             if (org.apache.commons.lang3.StringUtils.isNoneBlank(startTime)){
 | 
	
		
			
				|  |  |                 conditionSql += "AND t.shipping_time >= "+ startTime  ;
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             if (org.apache.commons.lang3.StringUtils.isNoneBlank(endTime)){
 | 
	
		
			
				|  |  |                 conditionSql += "AND t.shipping_time <= "+ endTime ;
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             oneSql=oneSql+conditionSql;
 | 
	
		
			
				|  |  |             List<Map<String,Object>> list = hibenateUtils.createSQLQuery(oneSql);
 | 
	
		
			
				|  |  |             for (Map<String,Object> oneMap:list){
 | 
	
		
			
				|  |  |                 String count = oneMap.get("count")==null?"0":oneMap.get("count").toString();
 | 
	
		
			
				|  |  |                 String sumAmount=oneMap.get("sumAmount")==null?"0":oneMap.get("sumAmount").toString();
 | 
	
		
			
				|  |  |                 map.put("ordercount",count);
 | 
	
		
			
				|  |  |                 map.put("sumAmount",sumAmount);
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             mapList.add(map);
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         return MixEnvelop.getSuccessListWithPage2(BaseHospitalRequestMapping.Prescription.api_success,mapList);
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     public List<Map<String,Object>> getSumAmount(String belongCommunity, String equNum, String startTime, String endTime,int page,int size) {
 | 
	
		
			
				|  |  |         List<Map<String,Object>> mapList=new ArrayList<>();
 | 
	
		
			
				|  |  |         page = (page - 1) * size;
 | 
	
		
			
				|  |  |         //查询出所有的设备
 | 
	
		
			
				|  |  |         Iterable <Mediicinedevice> mediicinedevices = deviceDao.findDeviceAll(page,size);
 | 
	
		
			
				|  |  |         List<Mediicinedevice> mediicinedeviceList= IterableUtils.toList(mediicinedevices);
 | 
	
		
			
				|  |  |         String countSql = " select " +
 | 
	
		
			
				|  |  |                 "     COUNT(DISTINCT (t.id)) as count " +
 | 
	
		
			
				|  |  |                 "   from " +
 | 
	
		
			
				|  |  |                 "     t_mediicine_device as t " +
 | 
	
		
			
				|  |  |                 "  where " +
 | 
	
		
			
				|  |  |                 "  1=1   " ;
 | 
	
		
			
				|  |  |         Logger.getAnonymousLogger().info("finalCountSql="+countSql);
 | 
	
		
			
				|  |  |         int decCount = jdbcTemplate.queryForObject(countSql,Integer.class);
 | 
	
		
			
				|  |  |         Map<String,Object> countMap = new HashMap<>();
 | 
	
		
			
				|  |  |         countMap.put("count",decCount);
 | 
	
		
			
				|  |  |         mapList.add(countMap);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         //将同一个设备的社区/名称/设备编码/历史记录/总金额放到一个Map中,并将这些Map放到同一个list中返回
 | 
	
		
			
				|  |  |         for (Mediicinedevice mediicinedevice:mediicinedeviceList){
 | 
	
		
			
				|  |  |             Map<String,Object> map=new HashMap<>();
 | 
	
		
			
				|  |  |             map.put("community",mediicinedevice.getCommunity());
 | 
	
		
			
				|  |  |             map.put("equName",mediicinedevice.getEquNum()+(mediicinedevice.getEquName()==null?"":"/"+mediicinedevice.getEquName()));
 | 
	
		
			
				|  |  |             String oneSql="SELECT SUM(t.amount) AS sumAmount,\n" +
 | 
	
		
			
				|  |  |                     "                COUNT(*) AS count,\n" +
 | 
	
		
			
				|  |  |                     "                t.shipping_equ AS equNum\n" +
 | 
	
		
			
				|  |  |                     "                FROM t_mediicine_order  t WHERE t.sell_state = 1 AND t.shipping_equ = '" + mediicinedevice.getEquNum()+"'";
 | 
	
		
			
				|  |  |             if (org.apache.commons.lang3.StringUtils.isNoneBlank(belongCommunity)){
 | 
	
		
			
				|  |  |                 oneSql += "AND t.belong_community ='"+belongCommunity+"'";
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             if (org.apache.commons.lang3.StringUtils.isNoneBlank(equNum)){
 | 
	
		
			
				|  |  |                 oneSql += "AND t.shipping_equ = '" + equNum + "'";
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             if (org.apache.commons.lang3.StringUtils.isNoneBlank(startTime)){
 | 
	
		
			
				|  |  |                 oneSql += "AND t.shipping_time >= "+ startTime  ;
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             if (org.apache.commons.lang3.StringUtils.isNoneBlank(endTime)){
 | 
	
		
			
				|  |  |                 oneSql += "AND t.shipping_time <= "+ endTime ;
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             List<Map<String,Object>> list = hibenateUtils.createSQLQuery(oneSql);
 | 
	
		
			
				|  |  |             for (Map<String,Object> oneMap:list){
 | 
	
		
			
				|  |  |                 String count = oneMap.get("count")==null?"0":oneMap.get("count").toString();
 | 
	
		
			
				|  |  |                 String sumAmount=oneMap.get("sumAmount")==null?"0":oneMap.get("sumAmount").toString();
 | 
	
		
			
				|  |  |                 map.put("ordercount",count);
 | 
	
		
			
				|  |  |                 map.put("sumAmount",sumAmount);
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             mapList.add(map);
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         return mapList;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     public void pushListWrite(OutputStream os, List<Map<String, Object>> list)throws Exception {
 | 
	
		
			
				|  |  |         WritableWorkbook wwb = jxl.Workbook.createWorkbook(os);
 | 
	
		
			
				|  |  |         try {
 | 
	
		
			
				|  |  |             WritableSheet sheet;
 | 
	
		
			
				|  |  |             sheet = wwb.createSheet("sheet", 1);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             String header[] = {"社区", "设备编号/设备名", "历史订单", "总销售额"};
 | 
	
		
			
				|  |  |             int i = 0;
 | 
	
		
			
				|  |  |             for (String h : header) {
 | 
	
		
			
				|  |  |                 addCell(sheet, 0, i, h);
 | 
	
		
			
				|  |  |                 i++;
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             int j = 1;
 | 
	
		
			
				|  |  |             for (Map<String, Object> tmp : list) {
 | 
	
		
			
				|  |  |                 addCell(sheet, j, 0, tmp.get("community")==null ? "" : tmp.get("community").toString());
 | 
	
		
			
				|  |  |                 addCell(sheet, j, 1, tmp.get("equName") == null? "" : tmp.get("equName").toString());
 | 
	
		
			
				|  |  |                 addCell(sheet, j, 2, tmp.get("ordercount") == null ? "" : tmp.get("ordercount").toString());
 | 
	
		
			
				|  |  |                 addCell(sheet, j, 3, tmp.get("sumAmount") == null ? "" :tmp.get("sumAmount").toString());
 | 
	
		
			
				|  |  |                 j++;
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             wwb.write();
 | 
	
		
			
				|  |  |             wwb.close();
 | 
	
		
			
				|  |  |         } catch (IOException e) {
 | 
	
		
			
				|  |  |             e.printStackTrace();
 | 
	
		
			
				|  |  |             if (wwb != null) wwb.close();
 | 
	
		
			
				|  |  |             throw e;
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  |     public void addCell(WritableSheet ws, int row, int column, String data) throws WriteException {
 | 
	
		
			
				|  |  |         Label label = new Label(column, row, data);
 | 
	
		
			
				|  |  |         WritableCellFormat cellFormat = new WritableCellFormat();
 | 
	
		
			
				|  |  |         cellFormat.setAlignment(jxl.format.Alignment.CENTRE);
 | 
	
		
			
				|  |  |         cellFormat.setVerticalAlignment(VerticalAlignment.CENTRE);
 | 
	
		
			
				|  |  |         label.setCellFormat(cellFormat);
 | 
	
		
			
				|  |  |         ws.addCell(label);
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     public List<Map<String,Object>> getDeviceInfo(String prescribeNum, String amount, String startTime, String endTime, String deviceId,int page,int size) {
 | 
	
		
			
				|  |  |         String sql="SELECT\n" +
 | 
	
		
			
				|  |  |                 "       t.prescribe_time AS 'prescribeTime',\n" +
 | 
	
		
			
				|  |  |                 "       t.prescribe_num AS 'prescribeNum',\n" +
 | 
	
		
			
				|  |  |                 "       t.amount AS 'amount',\n" +
 | 
	
		
			
				|  |  |                 "       t.socialinsur_payment AS 'socialinsurPayment',\n" +
 | 
	
		
			
				|  |  |                 "       t.amount AS 'sumAmount'" +
 | 
	
		
			
				|  |  |                 "FROM t_mediicine_order t\n" +
 | 
	
		
			
				|  |  |                 "WHERE " +
 | 
	
		
			
				|  |  |                 "t.shipping_equ='"+deviceId+"'";
 | 
	
		
			
				|  |  |         if (org.apache.commons.lang3.StringUtils.isNoneBlank(prescribeNum)){
 | 
	
		
			
				|  |  |             sql += " AND t.prescribe_num='"+prescribeNum+"'";
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         if (org.apache.commons.lang3.StringUtils.isNoneBlank(amount)){
 | 
	
		
			
				|  |  |             sql += " AND t.amount='"+amount+"'";
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         if(org.apache.commons.lang3.StringUtils.isNoneBlank(startTime)){
 | 
	
		
			
				|  |  |             sql += " AND t.prescribe_time>='"+startTime+"'";
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         if(org.apache.commons.lang3.StringUtils.isNoneBlank(endTime)){
 | 
	
		
			
				|  |  |             sql += " AND t.prescribe_time<='"+endTime+"'";
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         List<Map<String,Object>> list = hibenateUtils.createSQLQuery(sql,page,size);
 | 
	
		
			
				|  |  |         return list;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     public MixEnvelop getDeviceInfoExcel(String prescribeNum, String amount, String startTime, String endTime, String deviceId,int page,int size) {
 | 
	
		
			
				|  |  |         String sql="SELECT\n" +
 | 
	
		
			
				|  |  |                 "       t.prescribe_time AS 'prescribeTime',\n" +
 | 
	
		
			
				|  |  |                 "       t.prescribe_num AS 'prescribeNum',\n" +
 | 
	
		
			
				|  |  |                 "       t.amount AS 'amount',\n" +
 | 
	
		
			
				|  |  |                 "       t.socialinsur_payment AS 'socialinsurPayment',\n" +
 | 
	
		
			
				|  |  |                 "       t.amount AS 'sumAmount'" +
 | 
	
		
			
				|  |  |                 "FROM t_mediicine_order t\n" +
 | 
	
		
			
				|  |  |                 "WHERE " +
 | 
	
		
			
				|  |  |                 "t.shipping_equ='"+deviceId+"'";
 | 
	
		
			
				|  |  |         if (org.apache.commons.lang3.StringUtils.isNoneBlank(prescribeNum)){
 | 
	
		
			
				|  |  |             sql += " AND t.prescribe_num='"+prescribeNum+"'";
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         if (org.apache.commons.lang3.StringUtils.isNoneBlank(amount)){
 | 
	
		
			
				|  |  |             sql += " AND t.amount='"+amount+"'";
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         if(org.apache.commons.lang3.StringUtils.isNoneBlank(startTime)){
 | 
	
		
			
				|  |  |             sql += " AND t.prescribe_time>='"+startTime+"'";
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         if(org.apache.commons.lang3.StringUtils.isNoneBlank(endTime)){
 | 
	
		
			
				|  |  |             sql += " AND t.prescribe_time<='"+endTime+"'";
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         List<Map<String,Object>> list = hibenateUtils.createSQLQuery(sql,page,size);
 | 
	
		
			
				|  |  |         return MixEnvelop.getSuccessListWithPage2(BaseHospitalRequestMapping.Prescription.api_success,list);
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     public void deviceInfoExcel(OutputStream os, List<Map<String, Object>> list)throws Exception {
 | 
	
		
			
				|  |  |         WritableWorkbook wwb = jxl.Workbook.createWorkbook(os);
 | 
	
		
			
				|  |  |         try {
 | 
	
		
			
				|  |  |             WritableSheet sheet;
 | 
	
		
			
				|  |  |             sheet = wwb.createSheet("sheet", 1);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             String header[] = {"开方时间", "处方号", "交易金额", "社保抵扣","合计"};
 | 
	
		
			
				|  |  |             int i = 0;
 | 
	
		
			
				|  |  |             for (String h : header) {
 | 
	
		
			
				|  |  |                 addCell(sheet, 0, i, h);
 | 
	
		
			
				|  |  |                 i++;
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             int j = 1;
 | 
	
		
			
				|  |  |             for (Map<String, Object> tmp : list) {
 | 
	
		
			
				|  |  |                 addCell(sheet, j, 0, tmp.get("prescribeTime")==null ? "" : tmp.get("prescribeTime").toString());
 | 
	
		
			
				|  |  |                 addCell(sheet, j, 1, tmp.get("prescribeNum") == null? "" : tmp.get("prescribeNum").toString());
 | 
	
		
			
				|  |  |                 addCell(sheet, j, 2, tmp.get("amount") == null ? "0" : tmp.get("amount").toString());
 | 
	
		
			
				|  |  |                 addCell(sheet, j, 3, tmp.get("socialinsurPayment") == null ? "" :tmp.get("socialinsurPayment").toString());
 | 
	
		
			
				|  |  |                 addCell(sheet, j, 4, tmp.get("sumAmount") == null ? "" :tmp.get("sumAmount").toString());
 | 
	
		
			
				|  |  |                 j++;
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             wwb.write();
 | 
	
		
			
				|  |  |             wwb.close();
 | 
	
		
			
				|  |  |         } catch (IOException e) {
 | 
	
		
			
				|  |  |             e.printStackTrace();
 | 
	
		
			
				|  |  |             if (wwb != null) wwb.close();
 | 
	
		
			
				|  |  |             throw e;
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     public List<Map<String,Object>> getAllAmount() {
 | 
	
		
			
				|  |  |         String sql="SELECT sum(t.amount) AS 'sumAmount' " +
 | 
	
		
			
				|  |  |                 "from t_mediicine_order t ," +
 | 
	
		
			
				|  |  |                 "t_mediicine_device a " +
 | 
	
		
			
				|  |  |                 "where " +
 | 
	
		
			
				|  |  |                 "a.equ_num=t.shipping_equ " +
 | 
	
		
			
				|  |  |                 "and t.sell_state='1' ";
 | 
	
		
			
				|  |  |         List<Map<String,Object>> list = hibenateUtils.createSQLQuery(sql);
 | 
	
		
			
				|  |  |         return list;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | }
 |