|  | @@ -1,254 +0,0 @@
 | 
	
		
			
				|  |  | -package nc.bs.hr.gy_zsgl.workplugin;
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -import java.text.SimpleDateFormat;
 | 
	
		
			
				|  |  | -import java.util.ArrayList;
 | 
	
		
			
				|  |  | -import java.util.Calendar;
 | 
	
		
			
				|  |  | -import java.util.Date;
 | 
	
		
			
				|  |  | -import java.util.List;
 | 
	
		
			
				|  |  | -import java.util.Map;
 | 
	
		
			
				|  |  | -import java.net.URL;
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -import nc.bs.framework.common.NCLocator;
 | 
	
		
			
				|  |  | -import nc.bs.hr.gy_zsgl.plugin.Base64Util;
 | 
	
		
			
				|  |  | -import nc.bs.hr.gy_zsgl.plugin.MD5Util;
 | 
	
		
			
				|  |  | -import nc.bs.hr.gy_zsgl.plugin.SmsRequest;
 | 
	
		
			
				|  |  | -import nc.bs.hr.gy_zsgl.plugin.SmsResponse;
 | 
	
		
			
				|  |  | -import nc.bs.pub.pa.PreAlertObject;
 | 
	
		
			
				|  |  | -import nc.bs.pub.taskcenter.BgWorkingContext;
 | 
	
		
			
				|  |  | -import nc.bs.pub.taskcenter.IBackgroundWorkPlugin;
 | 
	
		
			
				|  |  | -import nc.itf.uap.IUAPQueryBS;
 | 
	
		
			
				|  |  | -import nc.jdbc.framework.processor.BeanListProcessor;
 | 
	
		
			
				|  |  | -import nc.vo.hr.gy_zsgl.Gy_certificatesVO;
 | 
	
		
			
				|  |  | -import nc.vo.pub.BusinessException;
 | 
	
		
			
				|  |  | -import nc.vo.pub.format.DateFormat;
 | 
	
		
			
				|  |  | -import nc.vo.pub.lang.UFDate;
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -import java.net.HttpURLConnection;
 | 
	
		
			
				|  |  | -import java.io.BufferedReader;
 | 
	
		
			
				|  |  | -import java.io.InputStreamReader;
 | 
	
		
			
				|  |  | -import java.io.OutputStream;
 | 
	
		
			
				|  |  | -import org.apache.commons.lang.StringUtils;
 | 
	
		
			
				|  |  | -/**
 | 
	
		
			
				|  |  | - * 证书临期发送短信给部门领导
 | 
	
		
			
				|  |  | - * @author Administrator
 | 
	
		
			
				|  |  | - *
 | 
	
		
			
				|  |  | - */
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -public class CopyOfCertificatesPlugin implements IBackgroundWorkPlugin{
 | 
	
		
			
				|  |  | -	private IUAPQueryBS iuap = null;
 | 
	
		
			
				|  |  | -	
 | 
	
		
			
				|  |  | -	public IUAPQueryBS getIuapBs(){
 | 
	
		
			
				|  |  | -		if(null==iuap){
 | 
	
		
			
				|  |  | -			iuap = (IUAPQueryBS) NCLocator.getInstance().lookup(IUAPQueryBS.class.getName());
 | 
	
		
			
				|  |  | -		}
 | 
	
		
			
				|  |  | -		
 | 
	
		
			
				|  |  | -		return iuap;
 | 
	
		
			
				|  |  | -		
 | 
	
		
			
				|  |  | -	}
 | 
	
		
			
				|  |  | -	//移动发送短信模板接口
 | 
	
		
			
				|  |  | -	final String  API_URL="http://112.35.1.155:1992/sms/tmpsubmit";
 | 
	
		
			
				|  |  | -	@Override
 | 
	
		
			
				|  |  | -	public PreAlertObject executeTask(BgWorkingContext context)
 | 
	
		
			
				|  |  | -			throws BusinessException {
 | 
	
		
			
				|  |  | -		// TODO 自动生成的方法存根
 | 
	
		
			
				|  |  | -		Map csmap=context.getKeyMap();
 | 
	
		
			
				|  |  | -		String mobilewh=(String) csmap.get("手机号码");
 | 
	
		
			
				|  |  | -		
 | 
	
		
			
				|  |  | -		
 | 
	
		
			
				|  |  | -		Calendar calendar = Calendar.getInstance();
 | 
	
		
			
				|  |  | -        int currentYear = calendar.get(Calendar.YEAR);
 | 
	
		
			
				|  |  | -        //获取当年到期的证书
 | 
	
		
			
				|  |  | -        String cert = "select ex_date,bd_psndoc.name srcbilltype,(select mobile from  bd_psndoc where name=a.vdef4 and nvl (dr,0) = 0 and enablestate ='2' ) srcbillid "
 | 
	
		
			
				|  |  | -        		+ "from gy_certificates a "
 | 
	
		
			
				|  |  | -        		+ "inner join bd_psndoc on a.vdef1=bd_psndoc.pk_psndoc  "
 | 
	
		
			
				|  |  | -        		+ "and ex_date like '"+currentYear+"%' and   nvl (a.dr,0) = 0 "
 | 
	
		
			
				|  |  | -        		+ "and bd_psndoc.enablestate ='2'  and  nvl (bd_psndoc.dr,0) = 0";
 | 
	
		
			
				|  |  | -        List<Gy_certificatesVO> certListVO = (List<Gy_certificatesVO>) getIuapBs().executeQuery(cert, new BeanListProcessor(Gy_certificatesVO.class));
 | 
	
		
			
				|  |  | -              
 | 
	
		
			
				|  |  | -       if(null!=certListVO &&  certListVO.size()>0){
 | 
	
		
			
				|  |  | -    	   
 | 
	
		
			
				|  |  | -    	   for(Gy_certificatesVO vo:certListVO){
 | 
	
		
			
				|  |  | -    	//	   String name=vo.getAttributeValue("vdef1").toString(); //姓名  
 | 
	
		
			
				|  |  | -    		   String name=vo.getSrcbilltype(); //姓名  
 | 
	
		
			
				|  |  | -    		   UFDate ex_date=vo.getEx_date(); //失效日期    
 | 
	
		
			
				|  |  | -    		   String mobile=vo.getSrcbillid();//主管手机号码
 | 
	
		
			
				|  |  | -    		   if(StringUtils.isNotEmpty(mobilewh)){
 | 
	
		
			
				|  |  | -    			   mobile=mobilewh;
 | 
	
		
			
				|  |  | -    				
 | 
	
		
			
				|  |  | -    			}
 | 
	
		
			
				|  |  | -    		   
 | 
	
		
			
				|  |  | -    		    // 准备请求参数
 | 
	
		
			
				|  |  | -    	        SmsRequest request = new SmsRequest();
 | 
	
		
			
				|  |  | -    	        request.setEcName("南通大众燃气有限公司");//集团客户名称
 | 
	
		
			
				|  |  | -    	        request.setApId("yecai");//用户名
 | 
	
		
			
				|  |  | -    	        request.setSecretKey("Nt_cw968007");//密码
 | 
	
		
			
				|  |  | -    	        request.setTemplateId("14a445aa78c14f0bb528b61d39c3e666");//模版ID
 | 
	
		
			
				|  |  | -    	        request.setMobiles(mobile);//手机号码,主管手机号码
 | 
	
		
			
				|  |  | -    	       
 | 
	
		
			
				|  |  | -    	        List<String> params = new ArrayList<String>();
 | 
	
		
			
				|  |  | -    	        params.add(name+"的燃气从业资格证");
 | 
	
		
			
				|  |  | -    	        params.add(convertToChineseDate(ex_date.toString().substring(0, 10)));
 | 
	
		
			
				|  |  | -    	        request.setParams(params);//["参数一","参数二"] 格式
 | 
	
		
			
				|  |  | -    	        
 | 
	
		
			
				|  |  | -    	        //用于Mac,MD5加密
 | 
	
		
			
				|  |  | -    	        List<String> macparamslis = new ArrayList<String>();
 | 
	
		
			
				|  |  | -    	        String exdate=convertToChineseDate(ex_date.toString().substring(0, 10));
 | 
	
		
			
				|  |  | -    	        macparamslis.add("\"" + name + "的燃气从业资格证\"");
 | 
	
		
			
				|  |  | -    	        macparamslis.add("\"" + exdate + "\"");
 | 
	
		
			
				|  |  | -    	        
 | 
	
		
			
				|  |  | -    	        // 自定义输出,去掉逗号后的空格
 | 
	
		
			
				|  |  | -    	        StringBuilder sb = new StringBuilder();
 | 
	
		
			
				|  |  | -    	        sb.append("[");
 | 
	
		
			
				|  |  | -    	        for (int i = 0; i < macparamslis.size(); i++) {
 | 
	
		
			
				|  |  | -    	            if (i > 0) {
 | 
	
		
			
				|  |  | -    	                sb.append(","); // 只加逗号,不加空格
 | 
	
		
			
				|  |  | -    	            }
 | 
	
		
			
				|  |  | -    	            sb.append(macparamslis.get(i));
 | 
	
		
			
				|  |  | -    	        }
 | 
	
		
			
				|  |  | -    	        sb.append("]");
 | 
	
		
			
				|  |  | -    	        
 | 
	
		
			
				|  |  | -    	        request.setMacparams(sb.toString());//["参数一","参数二"] 格式
 | 
	
		
			
				|  |  | -    	        request.setSign("gF211Wxv6");//网关签名编码
 | 
	
		
			
				|  |  | -    	        request.setAddSerial("");//扩展码
 | 
	
		
			
				|  |  | -    	        
 | 
	
		
			
				|  |  | -    	        StringBuffer  stringBuffer=new StringBuffer();
 | 
	
		
			
				|  |  | -    	        stringBuffer.append(request.getEcName());
 | 
	
		
			
				|  |  | -    	        stringBuffer.append(request.getApId());
 | 
	
		
			
				|  |  | -    	        stringBuffer.append(request.getSecretKey());
 | 
	
		
			
				|  |  | -    	        stringBuffer.append(request.getTemplateId());
 | 
	
		
			
				|  |  | -    	        stringBuffer.append(request.getMobiles());
 | 
	
		
			
				|  |  | -    	        stringBuffer.append(request.getMacparams());
 | 
	
		
			
				|  |  | -    	        stringBuffer.append(request.getSign());
 | 
	
		
			
				|  |  | -    	        //stringBuffer.append(request.getAddSerial());
 | 
	
		
			
				|  |  | -    	        
 | 
	
		
			
				|  |  | -    	        // 使用MD5哈希值作为mac字段
 | 
	
		
			
				|  |  | -    	        request.setMac(MD5Util.md5(stringBuffer.toString()));//API输入参数签名结果,签名算法:将ecName,apId,secretKey,templateId,mobiles,params,sign,addSerial按照顺序拼接,然后通过md5(32位小写)计算后得出的值
 | 
	
		
			
				|  |  | -    	       
 | 
	
		
			
				|  |  | -    	        
 | 
	
		
			
				|  |  | -    	        // 发送短信
 | 
	
		
			
				|  |  | -    	        SmsResponse response = sendSms(request);
 | 
	
		
			
				|  |  | -    	        
 | 
	
		
			
				|  |  | -    	        // 处理响应
 | 
	
		
			
				|  |  | -    	      //  System.out.println("响应结果: " + response.toString());
 | 
	
		
			
				|  |  | -    	        
 | 
	
		
			
				|  |  | -    	        if (response.isSuccess()) {
 | 
	
		
			
				|  |  | -    	          //  System.out.println("短信发送成功");
 | 
	
		
			
				|  |  | -    	        } else {
 | 
	
		
			
				|  |  | -    	        	 // 处理特定错误码
 | 
	
		
			
				|  |  | -    	            if ("NOT_WHITE_IP".equals(response.getRspcod())) {
 | 
	
		
			
				|  |  | -    	            	throw new BusinessException("错误原因: IP地址未在白名单中,请联系管理员添加IP白名单");
 | 
	
		
			
				|  |  | -    	            }
 | 
	
		
			
				|  |  | -    	            
 | 
	
		
			
				|  |  | -    	             throw new BusinessException("短信发送失败,错误码: " + response.getRspcod());
 | 
	
		
			
				|  |  | -    	        }
 | 
	
		
			
				|  |  | -    
 | 
	
		
			
				|  |  | -    	        
 | 
	
		
			
				|  |  | -           }
 | 
	
		
			
				|  |  | -    	   
 | 
	
		
			
				|  |  | -       }
 | 
	
		
			
				|  |  | -       
 | 
	
		
			
				|  |  | - 
 | 
	
		
			
				|  |  | -		
 | 
	
		
			
				|  |  | -		return null;
 | 
	
		
			
				|  |  | -	}
 | 
	
		
			
				|  |  | -	
 | 
	
		
			
				|  |  | -	
 | 
	
		
			
				|  |  | -	
 | 
	
		
			
				|  |  | -	
 | 
	
		
			
				|  |  | -	 public static String convertToChineseDate(String dateStr) {
 | 
	
		
			
				|  |  | -        try {
 | 
	
		
			
				|  |  | -            SimpleDateFormat inputFormat = new SimpleDateFormat("yyyy-MM-dd");
 | 
	
		
			
				|  |  | -            SimpleDateFormat outputFormat = new SimpleDateFormat("yyyy年MM月dd日");
 | 
	
		
			
				|  |  | -            Date date = inputFormat.parse(dateStr);
 | 
	
		
			
				|  |  | -            return outputFormat.format(date);
 | 
	
		
			
				|  |  | -        } catch (Exception e) {
 | 
	
		
			
				|  |  | -            return dateStr; // 如果转换失败,返回原字符串
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | -    }
 | 
	
		
			
				|  |  | -	
 | 
	
		
			
				|  |  | -	
 | 
	
		
			
				|  |  | -	
 | 
	
		
			
				|  |  | -	/**
 | 
	
		
			
				|  |  | -     * 发送短信
 | 
	
		
			
				|  |  | -     * @param request 短信请求对象
 | 
	
		
			
				|  |  | -     * @return 发送结果
 | 
	
		
			
				|  |  | -     */
 | 
	
		
			
				|  |  | -    public  SmsResponse sendSms(SmsRequest request) {
 | 
	
		
			
				|  |  | -    	 HttpURLConnection connection = null;
 | 
	
		
			
				|  |  | -    	  try {
 | 
	
		
			
				|  |  | -              // 1. 创建URL对象
 | 
	
		
			
				|  |  | -              URL url = new URL(API_URL);
 | 
	
		
			
				|  |  | -              
 | 
	
		
			
				|  |  | -              // 2. 创建连接
 | 
	
		
			
				|  |  | -              connection = (HttpURLConnection) url.openConnection();
 | 
	
		
			
				|  |  | -              connection.setRequestMethod("POST");
 | 
	
		
			
				|  |  | -              connection.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
 | 
	
		
			
				|  |  | -              connection.setRequestProperty("Accept", "application/json");
 | 
	
		
			
				|  |  | -              connection.setDoOutput(true);
 | 
	
		
			
				|  |  | -              connection.setConnectTimeout(5000);
 | 
	
		
			
				|  |  | -              connection.setReadTimeout(10000);
 | 
	
		
			
				|  |  | -              
 | 
	
		
			
				|  |  | -              // 3. 将请求对象转换为JSON字符串
 | 
	
		
			
				|  |  | -              String jsonInputString = request.toJsonString();
 | 
	
		
			
				|  |  | -              
 | 
	
		
			
				|  |  | -              // 4. Base64编码
 | 
	
		
			
				|  |  | -              String base64Encoded = Base64Util.encode(jsonInputString);
 | 
	
		
			
				|  |  | -              
 | 
	
		
			
				|  |  | -              // 5. 发送请求数据
 | 
	
		
			
				|  |  | -              OutputStream os = connection.getOutputStream();
 | 
	
		
			
				|  |  | -              try {
 | 
	
		
			
				|  |  | -                  byte[] input = base64Encoded.getBytes("UTF-8");
 | 
	
		
			
				|  |  | -                  os.write(input, 0, input.length);
 | 
	
		
			
				|  |  | -              } finally {
 | 
	
		
			
				|  |  | -                  if (os != null) {
 | 
	
		
			
				|  |  | -                      os.close();
 | 
	
		
			
				|  |  | -                  }
 | 
	
		
			
				|  |  | -              }
 | 
	
		
			
				|  |  | -              
 | 
	
		
			
				|  |  | -              // 6. 获取响应
 | 
	
		
			
				|  |  | -              int responseCode = connection.getResponseCode();
 | 
	
		
			
				|  |  | -              
 | 
	
		
			
				|  |  | -              if (responseCode == HttpURLConnection.HTTP_OK) {
 | 
	
		
			
				|  |  | -                  // 读取响应内容
 | 
	
		
			
				|  |  | -                  BufferedReader br = new BufferedReader(
 | 
	
		
			
				|  |  | -                      new InputStreamReader(connection.getInputStream(), "UTF-8"));
 | 
	
		
			
				|  |  | -                  try {
 | 
	
		
			
				|  |  | -                      StringBuilder response = new StringBuilder();
 | 
	
		
			
				|  |  | -                      String responseLine;
 | 
	
		
			
				|  |  | -                      while ((responseLine = br.readLine()) != null) {
 | 
	
		
			
				|  |  | -                          response.append(responseLine.trim());
 | 
	
		
			
				|  |  | -                      }
 | 
	
		
			
				|  |  | -                      
 | 
	
		
			
				|  |  | -                      // 解析响应JSON
 | 
	
		
			
				|  |  | -                      return SmsResponse.fromJson(response.toString());
 | 
	
		
			
				|  |  | -                  } finally {
 | 
	
		
			
				|  |  | -                      if (br != null) {
 | 
	
		
			
				|  |  | -                          br.close();
 | 
	
		
			
				|  |  | -                      }
 | 
	
		
			
				|  |  | -                  }
 | 
	
		
			
				|  |  | -              } else {
 | 
	
		
			
				|  |  | -                  // 处理错误响应
 | 
	
		
			
				|  |  | -                  SmsResponse errorResponse = new SmsResponse();
 | 
	
		
			
				|  |  | -                  errorResponse.setSuccess(false);
 | 
	
		
			
				|  |  | -                  errorResponse.setRspcod(String.valueOf(responseCode));
 | 
	
		
			
				|  |  | -                  errorResponse.setMsgGroup("");
 | 
	
		
			
				|  |  | -                  return errorResponse;
 | 
	
		
			
				|  |  | -              }
 | 
	
		
			
				|  |  | -              
 | 
	
		
			
				|  |  | -          } catch (Exception e) {
 | 
	
		
			
				|  |  | -              SmsResponse errorResponse = new SmsResponse();
 | 
	
		
			
				|  |  | -              errorResponse.setSuccess(false);
 | 
	
		
			
				|  |  | -              errorResponse.setRspcod("EXCEPTION");
 | 
	
		
			
				|  |  | -              errorResponse.setMsgGroup("");
 | 
	
		
			
				|  |  | -              return errorResponse;
 | 
	
		
			
				|  |  | -          } finally {
 | 
	
		
			
				|  |  | -              if (connection != null) {
 | 
	
		
			
				|  |  | -                  connection.disconnect();
 | 
	
		
			
				|  |  | -              }
 | 
	
		
			
				|  |  | -          }
 | 
	
		
			
				|  |  | -    	
 | 
	
		
			
				|  |  | -    }
 | 
	
		
			
				|  |  | -	
 | 
	
		
			
				|  |  | -	
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -}
 |