|  | @ -0,0 +1,124 @@
 | 
	
		
			
				|  |  | package com.yihu.jw.care.service.message;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | import com.yihu.jw.care.dao.message.BaseServiceNewsDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.care.message.BaseServiceNews;
 | 
	
		
			
				|  |  | import com.yihu.jw.util.common.IdCardUtil;
 | 
	
		
			
				|  |  | import org.springframework.beans.factory.annotation.Autowired;
 | 
	
		
			
				|  |  | import org.springframework.data.domain.PageRequest;
 | 
	
		
			
				|  |  | import org.springframework.data.domain.Sort;
 | 
	
		
			
				|  |  | import org.springframework.data.domain.Sort.Direction;
 | 
	
		
			
				|  |  | import org.springframework.jdbc.core.JdbcTemplate;
 | 
	
		
			
				|  |  | import org.springframework.stereotype.Service;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | import java.util.List;
 | 
	
		
			
				|  |  | import java.util.Map;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | /**
 | 
	
		
			
				|  |  |  * Created with IntelliJ IDEA.
 | 
	
		
			
				|  |  |  *
 | 
	
		
			
				|  |  |  * @Author: yeshijie
 | 
	
		
			
				|  |  |  * @Date: 2021/6/18
 | 
	
		
			
				|  |  |  * @Description:
 | 
	
		
			
				|  |  |  */
 | 
	
		
			
				|  |  | @Service
 | 
	
		
			
				|  |  | public class BaseServiceNewsService {
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private BaseServiceNewsDao baseServiceNewsDao;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private JdbcTemplate jdbcTemplate;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 查找机构坐标
 | 
	
		
			
				|  |  |      * @return
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public List<Map<String,Object>> findOrgLocations(){
 | 
	
		
			
				|  |  |         String sql = "SELECT code,name,brief,address,photo,mobile,longitude,latitude from base_org WHERE type in ('3','4') and del =1";
 | 
	
		
			
				|  |  |         List<Map<String,Object>> list = jdbcTemplate.queryForList(sql);
 | 
	
		
			
				|  |  |         return list;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 按名字查找居民坐标
 | 
	
		
			
				|  |  |      * @return
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public List<Map<String,Object>> findPatinetByName(String name){
 | 
	
		
			
				|  |  |         String sql = "SELECT p.id,p.`name`,p.address,p.photo,p.mobile,p.lat_lon latLon,sex,idcard,CAST(archive_type AS char) type from base_patient p\n" +
 | 
	
		
			
				|  |  |                 "WHERE p.del = 1 and p.name like '%"+name+"%'";
 | 
	
		
			
				|  |  |         List<Map<String,Object>> list = jdbcTemplate.queryForList(sql);
 | 
	
		
			
				|  |  |         for (Map<String,Object> map:list){
 | 
	
		
			
				|  |  |             String idcard = map.get("idcard").toString();
 | 
	
		
			
				|  |  |             map.put("age", IdCardUtil.getAgeForIdcard(idcard));
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         return list;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 查找所有居民坐标
 | 
	
		
			
				|  |  |      * 已入学儿童+ 已签约老人
 | 
	
		
			
				|  |  |      * @return
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public List<Map<String,Object>> findPatinetLocations(){
 | 
	
		
			
				|  |  |         String sql = "SELECT p.id,p.`name`,p.address,p.photo,p.mobile,p.lat_lon latLon,sex,idcard,archive_type type from base_doctor_patient_tmp t,base_patient p " +
 | 
	
		
			
				|  |  |                 "WHERE t.patient = p.id and t.del=1 and t.`status`=1 and p.del =1 " +
 | 
	
		
			
				|  |  |                 "UNION  " +
 | 
	
		
			
				|  |  |                 "SELECT p.id,p.`name`,p.address,p.photo,p.mobile,p.lat_lon latLon,sex,idcard,archive_type type from base_service_package_sign_record t,base_patient p " +
 | 
	
		
			
				|  |  |                 "WHERE t.patient = p.id and t.`status`=1 and p.del =1";
 | 
	
		
			
				|  |  |         List<Map<String,Object>> list = jdbcTemplate.queryForList(sql);
 | 
	
		
			
				|  |  |         for (Map<String,Object> map:list){
 | 
	
		
			
				|  |  |             String idcard = map.get("idcard").toString();
 | 
	
		
			
				|  |  |             map.put("age", IdCardUtil.getAgeForIdcard(idcard));
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         return list;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 服务动态
 | 
	
		
			
				|  |  |      * @param size
 | 
	
		
			
				|  |  |      * @return
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public List<BaseServiceNews> findNews(Integer size){
 | 
	
		
			
				|  |  |         if(size==null||size<1){
 | 
	
		
			
				|  |  |             size = 9;
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         Sort sort = new Sort(Direction.DESC, "createTime");
 | 
	
		
			
				|  |  |         PageRequest pageRequest = new PageRequest(0, size, sort);
 | 
	
		
			
				|  |  |         List<BaseServiceNews> list = baseServiceNewsDao.findNews(pageRequest);
 | 
	
		
			
				|  |  |         return list;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 添加服务动态信息-大屏展示用
 | 
	
		
			
				|  |  |      * @param name
 | 
	
		
			
				|  |  |      * @param code
 | 
	
		
			
				|  |  |      * @param type 类型 1上门辅导、2发起咨询、3发起生活照料、4代预约
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public void addServiceNews(String name,String code,String type,String patientName){
 | 
	
		
			
				|  |  |         BaseServiceNews serviceNews = new BaseServiceNews();
 | 
	
		
			
				|  |  |         serviceNews.setName(name);
 | 
	
		
			
				|  |  |         serviceNews.setCode(code);
 | 
	
		
			
				|  |  |         serviceNews.setType(type);
 | 
	
		
			
				|  |  |         String content = "";
 | 
	
		
			
				|  |  |         switch (type){
 | 
	
		
			
				|  |  |             case "1":
 | 
	
		
			
				|  |  |                 content = "发起上门辅导";
 | 
	
		
			
				|  |  |                 break;
 | 
	
		
			
				|  |  |             case "2":
 | 
	
		
			
				|  |  |                 content = "发起咨询";
 | 
	
		
			
				|  |  |                 break;
 | 
	
		
			
				|  |  |             case "3":
 | 
	
		
			
				|  |  |                 content = "发起生活照料";
 | 
	
		
			
				|  |  |                 break;
 | 
	
		
			
				|  |  |             case "4":
 | 
	
		
			
				|  |  |                 content = "为"+patientName+"代预约";
 | 
	
		
			
				|  |  |                 break;
 | 
	
		
			
				|  |  |             default:
 | 
	
		
			
				|  |  |                 content = "";
 | 
	
		
			
				|  |  |                 break;
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         serviceNews.setContent(content);
 | 
	
		
			
				|  |  |         baseServiceNewsDao.save(serviceNews);
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | }
 |