| 
					
				 | 
			
			
				@ -1,17 +1,11 @@ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				package com.yihu.jw.service.device; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.alibaba.fastjson.JSONObject; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.entity.iot.device.IotDeviceDO; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.entity.iot.device.IotDeviceSimDO; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.entity.iot.device.IotPatientDeviceDO; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.entity.iot.dict.IotSystemDictDO; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.repository.device.IotDeviceDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.repository.device.IotDeviceSimDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.repository.device.IotPatientDeviceDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.repository.dict.IotSystemDictDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.restmodel.iot.device.IotOrderVO; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.restmodel.web.MixEnvelop; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.rm.iot.IotRequestMapping; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.util.http.HttpClientUtil; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.mysql.query.BaseJpaService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.apache.commons.lang.StringUtils; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -23,7 +17,6 @@ import org.springframework.transaction.annotation.Transactional; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import java.util.ArrayList; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import java.util.List; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import java.util.Map; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				/** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 * @author HZY 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -72,96 +65,7 @@ public class IotDeviceSimService extends BaseJpaService<IotDeviceSimDO, IotDevic 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        iotDeviceSimDao.save(simDO); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     *新增SIM卡 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param json 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public MixEnvelop<IotOrderVO, IotOrderVO> addSIM(String json) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        IotDeviceSimDO sim = JSONObject.parseObject(json, IotDeviceSimDO.class); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        IotDeviceSimDO deviceSimDaoBySim = iotDeviceSimDao.findBySim(sim.getSim()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if(deviceSimDaoBySim!=null){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            return MixEnvelop.getError("SIM已存在"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        IotPatientDeviceDO patientSim = iotPatientDeviceDao.findBySim(sim.getSim()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (patientSim!=null){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            sim.setDeviceName(patientSim.getDeviceName()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            sim.setDeviceSn(patientSim.getDeviceSn()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            sim.setContactsName(patientSim.getPatientName()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            sim.setContactsMobile(patientSim.getMobile()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            IotDeviceDO deviceSim = iotDeviceDao.findBySimNo(sim.getSim()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if (deviceSim!=null){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                sim.setDeviceName(deviceSim.getName()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                sim.setDeviceSn(deviceSim.getDeviceSn()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        sim.setRemainingBalance(sim.getAdvancePayment()-sim.getPayment()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        sim.setStatus(1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        sim.setDel("0"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        iotDeviceSimDao.save(sim); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return MixEnvelop.getSuccess(IotRequestMapping.DeviceSim.message_success_add); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 条件分页查找 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param page 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param size 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param status 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param sim 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param sn 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @return 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public MixEnvelop<IotDeviceSimDO, IotDeviceSimDO> conditionQueryPage(Integer page, Integer size, String status, String sim, String sn){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        StringBuffer sql = new StringBuffer("SELECT c.* from iot_device_sim c WHERE 1=1 "); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        StringBuffer sqlCount = new StringBuffer("SELECT COUNT(c.id) count from iot_device_sim c  WHERE 1=1 "); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        List<Object> args = new ArrayList<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if(StringUtils.isNotBlank(status)){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            sql.append(" and c.status=? "); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            sqlCount.append("and c.status='").append(status).append("' "); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            args.add(status); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if(StringUtils.isNotBlank(sim)){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            sql.append(" and (c.sim like '%").append(sim).append("%')"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            sqlCount.append(" and (c.sim like '%").append(sim).append("%')"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if(StringUtils.isNotBlank(sn)){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            sql.append(" and (c.device_sn like '%").append(sn).append("%')"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            sqlCount.append(" and (c.device_sn like '%").append(sn).append("%')"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        sql.append("order by c.update_time desc limit ").append((page-1)*size).append(",").append(size); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        List<IotDeviceSimDO> list = jdbcTemplate.query(sql.toString(),args.toArray(),new BeanPropertyRowMapper(IotDeviceSimDO.class)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        List<Map<String,Object>> countList = jdbcTemplate.queryForList(sqlCount.toString()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        long count = Long.valueOf(countList.get(0).get("count").toString()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return MixEnvelop.getSuccessListWithPage(IotRequestMapping.DeviceSim.message_success_find,list, page, size,count); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 分页查找所有应用SIM卡信息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param page 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param size 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @return 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public MixEnvelop<IotDeviceSimDO, IotDeviceSimDO> findAllSim(Integer page, Integer size) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        StringBuffer sql= new StringBuffer("SELECT DISTINCT * FROM iot_device_sim "); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        sql.append(" limit ").append((page-1)*size).append(",").append(size); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        List<IotDeviceSimDO> list = jdbcTemplate.query(sql.toString(),new BeanPropertyRowMapper(IotDeviceSimDO.class)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //获取总数 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        long count = list.size(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return MixEnvelop.getSuccessListWithPage(IotRequestMapping.DeviceSim.message_success_find,list,page, size,count); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    /** 
			 |