anderx 4 years ago
parent
commit
1a4b358216

+ 20 - 7
src/main/java/com/goafanti/admin/service/impl/PublicReleaseServiceImpl.java

@@ -11,6 +11,7 @@ import java.util.UUID;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import com.alibaba.fastjson.JSONObject;
 import com.goafanti.admin.bo.InputPublicDtails;
 import com.goafanti.admin.bo.InputPublicRelease;
 import com.goafanti.admin.bo.InputPublicReleaseList;
@@ -31,6 +32,8 @@ import com.goafanti.common.model.PublicRelease;
 import com.goafanti.common.model.PublicReleaseLog;
 import com.goafanti.common.utils.AsyncUtils;
 import com.goafanti.common.utils.DateUtils;
+import com.goafanti.common.utils.HttpUtils;
+import com.goafanti.common.utils.WeChatUtils;
 import com.goafanti.core.mybatis.BaseMybatisDao;
 import com.goafanti.core.mybatis.page.Pagination;
 import com.goafanti.core.shiro.token.TokenManager;
@@ -46,7 +49,7 @@ public class PublicReleaseServiceImpl extends BaseMybatisDao<PublicReleaseMapper
 	@Autowired
 	private CustomerService customerService;
 	@Autowired
-	private AsyncUtils asyncUtils;
+	private WeChatUtils weChatUtils;
 	@Autowired
 	private AdminMapper adminMapper;
 	
@@ -54,6 +57,7 @@ public class PublicReleaseServiceImpl extends BaseMybatisDao<PublicReleaseMapper
 	public int addPublicRelease(InputPublicRelease in) {
 		Date date =new Date();
 		in.setCreateTime(date);
+		in.setStatus(1);
 		in.setAid(TokenManager.getAdminId());
 		try {
 			in.setReleaseStart(DateUtils.parseDate(in.getReleaseStarts(), AFTConstants.YYYYMMDDHHMMSS));
@@ -63,18 +67,20 @@ public class PublicReleaseServiceImpl extends BaseMybatisDao<PublicReleaseMapper
 			throw new BusinessException("转换异常");
 		}
 		publicReleaseMapper.insertSelectiveGetId(in);
-		Admin a=adminMapper.selectByPrimaryKey(TokenManager.getAdminId());
+		Admin my=adminMapper.selectByPrimaryKey(TokenManager.getAdminId());
+		Admin a=adminMapper.selectGetSuper(my.getSuperiorId());
 		String openid=a.getOpenId();
-		openid="ogXpy5RoYqThnr-a8_2e0W7dZuF0";
 		if (openid!=null) {
-			asyncUtils.addWechatNotice(openid, 0,date,a.getName());
-			return 1;
+			return weChatUtils.addNotice(openid, in.getStatus(),date,a.getName(),"["+my.getName()+"]发起外出审核");
 		}else {
 			//成功但是对方收不到消息
 			return 2;
 		}
 	}
 	
+	
+	
+	
 
 
 	
@@ -104,16 +110,23 @@ public class PublicReleaseServiceImpl extends BaseMybatisDao<PublicReleaseMapper
 	@Override
 	public int pushExaminePublicRelease(Integer id, Integer status, String remarks,Double duration) {
 		PublicRelease p=new PublicRelease();
+		Date date =new Date();
 		p.setId(id);
 		p.setStatus(status);
 		if (status==2) {
-			PublicRelease use=publicReleaseMapper.selectByPrimaryKey(id);
 			p.setDuration(duration);
 		}
+		PublicRelease use=publicReleaseMapper.selectByPrimaryKey(id);
 		publicReleaseMapper.updateByPrimaryKeySelective(p);
 		PublicReleaseLog log=new PublicReleaseLog(id,TokenManager.getAdminId(),status,remarks,new Date());
 		publicReleaseLogMapper.insertSelective(log);
-		return 1;
+		Admin my=adminMapper.selectByPrimaryKey(TokenManager.getAdminId());
+		Admin s=adminMapper.selectByPrimaryKey(use.getAid());
+		if (my.getOpenId()!=null) {
+			return weChatUtils.addNotice(s.getOpenId(),p.getStatus(),date,my.getName(),
+					"["+my.getName()+"]"+(p.getStatus()==0?"驳回":"同意")+"了您的外出申请。");
+		}
+			return 1;
 	}
 	
 	@Override

+ 2 - 0
src/main/java/com/goafanti/common/dao/AdminMapper.java

@@ -203,5 +203,7 @@ public interface AdminMapper {
 	List<String> getAdminRoleListByAid(String id);
 
 	String selectByOpeid(String aid);
+
+	Admin selectGetSuper(String aid);
 	
 }

+ 7 - 0
src/main/java/com/goafanti/common/mapper/AdminMapper.xml

@@ -1216,6 +1216,13 @@ select a.id,a.nickname as name,a.source,c.name contacts,c.mobile as contactMobil
   <select id="selectBySuperId" resultType="java.lang.String">
   	select id from admin where superior_id= #{aid}
   </select>
+  
+   <select id="selectGetSuper" parameterType="java.lang.String" resultMap="BaseResultMap">
+    select 
+    <include refid="Base_Column_List" />
+    from admin
+    where  superior_id= #{aid}
+  </select>
   <select id="selectFinanceAdminByOrderDep" resultType="com.goafanti.common.model.Admin">
  	 select a.finance_id id,b.name from department a left join admin b on a.finance_id=b.id
 	where a.id= #{orderDep}

+ 1 - 80
src/main/java/com/goafanti/common/utils/AsyncUtils.java

@@ -28,15 +28,7 @@ import com.goafanti.core.shiro.token.TokenManager;
 public class AsyncUtils {
 	@Autowired
 	private NoticeMapper noticeMapper;
-	@Value(value = "${wx.appId}")
-	private String appId;
-	@Value(value = "${wx.appSecret}")
-	private String appSecret;
-	//待审核通知
-	private static final String sptz="j7WH3EwQnxGxwuV2HwmJhryxySPE8vOiV5cVOpp-42I";
-	//审核结通知
-	private static final String jgtz="pWia-KJPFwDM8ReDu_BOa2_42G7W2hXB16sUDbSxpcM";
-	private static  String send_url="https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token=ACCESS_TOKEN";
+	
 
 	
 	public void patentSend(EmailBo bo) throws UnsupportedEncodingException, MessagingException {
@@ -62,75 +54,4 @@ public class AsyncUtils {
 		
 	}
 
-
-	/**
-	 * 
-	 * @param openid
-	 * @param type 0申请 1通过 2驳回
-	 * @param string 
-	 * @param date 
-	 */
-	public void addWechatNotice(String openid ,Integer type, Date date, String aname) {
-		Map<String, Object> map=new HashMap<String, Object>();
-		String accessToken=getAccessToken();
-		String url=send_url.replace("ACCESS_TOKEN", accessToken);
-		System.out.println(url);
-		map.put("access_token", accessToken);
-		map.put("touser", openid);
-		Map<String, Object> we=new HashMap<String, Object>();
-		if (type==0) {
-			map.put("template_id", sptz);
-			Map<String, Object> v1=new HashMap<String, Object>();
-			String str=DateUtils.formatDate(date, AFTConstants.YMDHMS_CHINESE);
-			v1.put("value",str);
-			we.put("time5", v1);
-			Map<String, Object> v2=new HashMap<String, Object>();
-			v2.put("value", aname);
-			we.put("name3", v2);
-			Map<String, Object> v3=new HashMap<String, Object>();
-			v3.put("value", "我是一个备注");
-			we.put("thing10", v3);
-		}else if (type==1){
-			map.put("template_id", jgtz);
-			we.put("thing17", new HashMap<>().put("value", "通过"));
-			we.put("thing25", new HashMap<>().put("value", "您申请的外出已通过!"));
-		}else if (type==2){
-			map.put("template_id", jgtz);
-			we.put("thing17", new HashMap<>().put("value", "通过"));
-			we.put("thing25", new HashMap<>().put("value", "您申请的外出已驳回!"));
-		}
-		map.put("data", we);
-		System.out.println(JSONObject.toJSON(map));
-		JSONObject json=HttpUtils.httpPost(url, map);
-		System.out.println(JSONObject.toJSONString(json));
-		
-	}
-	
-
-	
-	  public  String getAccessToken() {
-	    	String access_token=(String) TokenManager.getVal2Session("access_token");
-	    	String expires_in= (String) TokenManager.getVal2Session("expires_in");
-	    	if (access_token!=null&&expires_in!=null) {
-	    		expires_in=expires_in+7200;
-	    		if (new Date().getTime()<Long.valueOf(expires_in)) {
-	    			return access_token;
-				}
-			}
-				String url = String.format(
-						"https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=%s&secret=%s", appId,
-						appSecret);
-				JSONObject js = HttpUtils.httpGet(url);
-				String errcode =js.getString("errcode");
-				if (errcode!=null) {
-					throw new  BusinessException("获取AccessToken失败!");
-				}else {
-					LoggerUtils.debug(AsyncUtils.class,"获取AccessToken成功,accesstoken="+js.getString("access_token"));
-				}
-				access_token = js.getString("access_token");
-				expires_in = js.getString("expires_in");
-				TokenManager.setVal2Session("access_token", access_token);
-				TokenManager.setVal2Session("expires_in", expires_in);
-			return access_token;
-	    }
 }

+ 144 - 0
src/main/java/com/goafanti/common/utils/WeChatUtils.java

@@ -0,0 +1,144 @@
+package com.goafanti.common.utils;
+
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Component;
+
+import com.alibaba.fastjson.JSONObject;
+import com.goafanti.common.constant.AFTConstants;
+import com.goafanti.common.error.BusinessException;
+import com.goafanti.core.shiro.token.TokenManager;
+
+@Component
+public class WeChatUtils {
+	
+	
+	@Value(value = "${wx.appId}")
+	private String appId;
+	@Value(value = "${wx.appSecret}")
+	private String appSecret;
+	//待审核通知
+	private static final String sptz="j7WH3EwQnxGxwuV2HwmJhryxySPE8vOiV5cVOpp-42I";
+	//审核结通知
+	private static final String jgtz="pWia-KJPFwDM8ReDu_BOa9FJn31VFc81bp3yxfBmIRI";
+	private static  String send_url="https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token=ACCESS_TOKEN";
+
+
+	
+
+	/**
+	 * 
+	 * @param openid
+	 * @param type 状态 0驳回 1发起 2同意
+	 * @param string 
+	 * @param date 
+	 */
+	public Integer addNotice(String openid ,Integer type, Date date, String aname,String remarks) {
+		Map<String, Object> map=new HashMap<String, Object>();
+		String accessToken=getAccessToken();
+		String url=send_url.replace("ACCESS_TOKEN", accessToken);
+		map.put("access_token", accessToken);
+		map.put("touser", openid);
+		String str=DateUtils.formatDate(date, AFTConstants.YMDHMS_CHINESE);
+		System.out.println(str);
+		if (type==1) {
+			map.put("template_id", sptz);
+			map.put("data",getData(type,date, aname,remarks));
+		}else {
+			map.put("template_id", jgtz);
+			map.put("data",getData(type,date, aname,remarks));
+		}
+		System.out.println("inupt="+JSONObject.toJSONString(map));
+		JSONObject res=HttpUtils.httpPost(url, map);
+		System.out.println("res="+JSONObject.toJSONString(res));
+		if (res.get("errcode")!=null) {
+			return res.getInteger("errcode");
+		}else {
+			return 1;
+		}
+		
+	}
+	private Map<String, Object> getData(Integer type,Date date, String aname, String remarks) {
+		Map<String, Object> we=new HashMap<String, Object>();
+		String strDate=DateUtils.formatDate(date, AFTConstants.YMDHMS_CHINESE);
+		if (type==0) {
+			Map<String, Object> v1=new HashMap<String, Object>();
+			v1.put("value",strDate);
+			we.put("time5", v1);
+			Map<String, Object> v2=new HashMap<String, Object>();
+			v2.put("value", aname);
+			we.put("name3", v2);
+			Map<String, Object> v3=new HashMap<String, Object>();
+			v3.put("value", remarks);
+			we.put("thing10", v3);
+		}else {
+			String thing2="";
+			if (type==1){
+				thing2="通过";
+			}else if (type==2){
+				thing2="通过";
+			}
+			Map<String, Object> v1=new HashMap<String, Object>();
+			v1.put("value",strDate);
+			we.put("date3", v1);
+			Map<String, Object> v2=new HashMap<String, Object>();
+			v2.put("value", thing2);
+			we.put("thing2", v2);
+			Map<String, Object> v3=new HashMap<String, Object>();
+			v3.put("value", remarks);
+			we.put("thing6", v3);
+		} 
+		return we;
+	}
+	
+	
+
+	
+	  public  String getAccessToken() {
+	    	String access_token=(String) TokenManager.getVal2Session("access_token");
+	    	Long expires_in= (Long) TokenManager.getVal2Session("expires_in");
+	    	Date date=new Date();
+	    	if (access_token!=null&&expires_in!=null) {
+	    		LoggerUtils.debug(getClass(), "\n"
+	    				+ "access_token="+access_token+"\n "
+	    						+ "expires_in="+expires_in+"\n "
+	    								+ "now="+DateUtils.formatDate(date, AFTConstants.YYYYMMDDHHMMSS));
+	    		if (new Date().getTime()<Long.valueOf(expires_in)) {
+	    			LoggerUtils.debug(getClass(), "session中获取accestoken");
+	    			return access_token;
+				}else {
+					TokenManager.deleteSession("access_token");
+					TokenManager.deleteSession("expires_in");
+					return setSessionAccessToken(date); 
+				}
+			}else {
+				return setSessionAccessToken(date);
+			}
+				
+			
+	    }
+
+
+	private String setSessionAccessToken(Date date) {
+		String url = String.format(
+				"https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=%s&secret=%s", appId,
+				appSecret);
+		JSONObject js = HttpUtils.httpGet(url);
+		String errcode =js.getString("errcode");
+		if (errcode!=null) {
+			throw new  BusinessException("获取AccessToken失败!");
+		}else {
+			LoggerUtils.debug(AsyncUtils.class,"获取AccessToken成功,accesstoken="+js.getString("access_token"));
+		}
+		String access_token = js.getString("access_token");
+		Long expires_in = js.getLong("expires_in");
+		expires_in+=date.getTime();
+		TokenManager.setVal2Session("access_token", access_token);
+		TokenManager.setVal2Session("expires_in", expires_in);
+		return access_token;
+	}
+
+}

+ 5 - 1
src/main/java/com/goafanti/core/shiro/token/TokenManager.java

@@ -19,7 +19,7 @@ public class TokenManager {
 	/**
 	 * 获取当前登录的用户User对象
 	 * 
-	 * @return
+	 * @return
 	 */
 	public static AftUser getToken() {
 		return (AftUser) SecurityUtils.getSubject().getPrincipal();
@@ -51,6 +51,10 @@ public class TokenManager {
 	public static Session getSession() {
 		return SecurityUtils.getSubject().getSession();
 	}
+	
+	public static  void deleteSession(String str) {
+		getSession().removeAttribute(str);
+	}
 
 	/**
 	 * 获取当前用户ID