Browse Source

报销小程序发起、审核、修改站内+微信订阅消息+邮件+日志开发

anderx 2 years ago
parent
commit
9115a9ed4b

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

@@ -1133,8 +1133,8 @@
 
 
   <select id="listAdminBydepIdAndRoleType" resultType="com.goafanti.common.model.Admin">
-    select a.id,a.name,a.email  from admin a left join user_role b on a.id =b.uid
-                                             left join `role` c on b.rid=c.id
+    select a.id,a.name,a.email ,a.open_id openId
+    from admin a left join user_role b on a.id =b.uid left join `role` c on b.rid=c.id
     where a.status='0'
       and a.department_id= #{depId}
       and c.role_type= #{roleType}
@@ -1186,7 +1186,7 @@
     SELECT count(*) from admin where amb_id= #{ambId}
   </select>
   <select id="selectAdminByRoleType" parameterType="java.lang.String" resultType="com.goafanti.common.model.Admin">
-    SELECT a.id,a.name ,a.mobile ,a.email,a.department_id departmentId
+    SELECT a.id,a.name ,a.mobile ,a.email,a.department_id departmentId,a.open_id openId
     FROM admin a left join user_role b on a.id=b.uid
     left join `role` c on b.rid =c.id
     where a.status='0'

+ 16 - 0
src/main/java/com/goafanti/common/utils/AsyncUtils.java

@@ -93,6 +93,22 @@ public class AsyncUtils {
 		addNotice(n);
 	}
 
+	/**
+	 *
+	 * @param type NoticeStatus的类型
+	 * @param aid 接受者编号
+	 * @param str 推送信息
+	 */
+	public void addNoticAndEmail(Integer type, String  aid,String str) {
+		Notice n =new Notice();
+		n.setId(UUID.randomUUID().toString());
+		n.setAid(aid);
+		n.setNoticeType(type);
+		n.setContent(str);
+		n.setReaded(0);//未读
+		addNoticAndEmail(n);
+	}
+
 	public void addNoticAndEmail(Notice n) {
 		n.setType(NoticeTypes.getType(n.getNoticeType()));
 		AdminListBo a = adminMapper.getDeptNameByAid(n.getAid());

+ 116 - 12
src/main/java/com/goafanti/common/utils/WeChatUtils.java

@@ -27,20 +27,39 @@ public class WeChatUtils {
 	@Autowired
 	private RedisUtil redisUtil;
 
-	//待审核通知
-	private static final String sptz="j7WH3EwQnxGxwuV2HwmJhryxySPE8vOiV5cVOpp-42I";
-	//审核结通知
-	private static final String jgtz="pWia-KJPFwDM8ReDu_BOa9FJn31VFc81bp3yxfBmIRI";
+	/**
+	 * 公出待审核通知
+	 */
+	private static final String PUBLIC_RELEASE_EXAMINE ="j7WH3EwQnxGxwuV2HwmJhryxySPE8vOiV5cVOpp-42I";
+	/**
+	 * 公出审核结果通知
+	 */
+	private static final String PUBLIC_RELEASE_EXAMINE_RESULT="pWia-KJPFwDM8ReDu_BOa9FJn31VFc81bp3yxfBmIRI";
+	/**
+	 * 公出待审核通知
+	 */
+	private static final String EXPENSE_RELEASE_EXAMINE ="0e2Te3WUa0fDPQnyE8TLmN_K06WLsB4fqm5qpo6npNo";
+	/**
+	 * 公出审核结果通知
+	 */
+	private static final String EXPENSE_RELEASE_EXAMINE_RESULT="rRPWzRcGY8BGwlk0xyjwR1RKdv3iRFXaU3bcK1300gw";
+
+
+	/**
+	 * 推送地址
+	 */
 	private static  String send_url="https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token=ACCESS_TOKEN";
 
 
 
 
 	/**
-	 *
-	 * @param openid
+	 * 推送微信订阅信息,跳转为公出信息
+	 * @param openid 发送对象微信openid
 	 * @param type 状态 0驳回 1发起 2同意
-	 * @param date
+	 * @param date 日期
+	 * @param aname 发送者名称
+	 * @param remarks 发送信息,不能大于十五个字
 	 */
 	public Integer addNotice(String openid ,Integer type,Integer id, Date date, String aname,String remarks) {
 		Map<String, Object> map=new HashMap<String, Object>();
@@ -51,11 +70,43 @@ public class WeChatUtils {
 		map.put("page", "pages/egressDetails/index?id="+id);
 		map.put("miniprogram_state", wxState);
 		if (type==1) {
-			map.put("template_id", sptz);
-			map.put("data",getData(type,date, aname,remarks));
+			map.put("template_id", PUBLIC_RELEASE_EXAMINE);
+			map.put("data",getPublicData(type,date, aname,remarks));
+		}else {
+			map.put("template_id", PUBLIC_RELEASE_EXAMINE_RESULT);
+			map.put("data",getPublicData(type,date, aname,remarks));
+		}
+		JSONObject res=HttpUtils.httpPost(url, map);
+		if (res.get("errcode")!=null) {
+			return res.getInteger("errcode");
+		}else {
+			return 1;
+		}
+
+	}
+	/**
+	 * 推送微信订阅信息,跳转为报销信息
+	 * @param openid 发送对象微信openid
+	 * @param type 状态 0驳回 1发起 2同意
+	 * @param date 日期
+	 * @param aname 发送者名称
+	 * @param remarks 发送信息,不能大于十五个字
+	 */
+	public Integer addExpenseAccountWeChatNotice(String openid ,Integer type,Integer id, 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);
+		//这里要替换成当前的
+		map.put("page", "pages/egressDetails/index?id="+id);
+		map.put("miniprogram_state", wxState);
+		if (type==1) {
+			map.put("template_id", EXPENSE_RELEASE_EXAMINE);
+			map.put("data",getExpenseData(type,date, aname,remarks));
 		}else {
-			map.put("template_id", jgtz);
-			map.put("data",getData(type,date, aname,remarks));
+			map.put("template_id", EXPENSE_RELEASE_EXAMINE_RESULT);
+			map.put("data",getExpenseData(type,date, aname,remarks));
 		}
 		JSONObject res=HttpUtils.httpPost(url, map);
 		if (res.get("errcode")!=null) {
@@ -65,9 +116,19 @@ public class WeChatUtils {
 		}
 
 	}
-	private Map<String, Object> getData(Integer type,Date date, String aname, String remarks) {
+
+	/**
+	 * 公出订阅消息组装
+	 * @param type
+	 * @param date
+	 * @param aname
+	 * @param remarks
+	 * @return
+	 */
+	private Map<String, Object> getPublicData(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 (remarks.length()>20)remarks=remarks.substring(0,17)+"...";
 		if (type==1) {
 			Map<String, Object> v1=new HashMap<String, Object>();
 			v1.put("value",strDate);
@@ -99,6 +160,49 @@ public class WeChatUtils {
 	}
 
 
+	/**
+	 * 报销订阅消息组装
+	 * @param type
+	 * @param date
+	 * @param aname
+	 * @param remarks
+	 * @return
+	 */
+	private Map<String, Object> getExpenseData(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 (remarks.length()>20)remarks=remarks.substring(0,17)+"...";
+		if (type==1) {
+			Map<String, Object> v2=new HashMap<String, Object>();
+			we.put("thing4", v2);
+			v2.put("value", aname);
+			Map<String, Object> v1=new HashMap<String, Object>();
+			we.put("time6", v1);
+			v1.put("value",strDate);
+			Map<String, Object> v3=new HashMap<String, Object>();
+			we.put("thing2", v3);
+			v3.put("value", remarks);
+		}else {
+			String thing5="";
+			if (type==0){
+				thing5="报销驳回";
+			}else if (type==2){
+				thing5="报销通过";
+			}
+			Map<String, Object> v1=new HashMap<String, Object>();
+			we.put("time3", v1);
+			v1.put("value",strDate);
+			Map<String, Object> v2=new HashMap<String, Object>();
+			we.put("thing5", v2);
+			v2.put("value", thing5);
+			Map<String, Object> v3=new HashMap<String, Object>();
+			we.put("thing4", v3);
+			v3.put("value", remarks);
+		}
+		return we;
+	}
+
+
 
 
 	public String getAccessToken() {

+ 22 - 4
src/main/java/com/goafanti/expenseAccount/service/impl/ExpenseAccountServiceImpl.java

@@ -11,6 +11,7 @@ import com.goafanti.common.error.BusinessException;
 import com.goafanti.common.model.*;
 import com.goafanti.common.utils.AsyncUtils;
 import com.goafanti.common.utils.DateUtils;
+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;
@@ -36,6 +37,9 @@ public class ExpenseAccountServiceImpl extends BaseMybatisDao<ExpenseAccountMapp
     @Autowired
     private AsyncUtils asyncUtils;
     @Autowired
+    private WeChatUtils weChatUtils;
+
+    @Autowired
     private ExpenseAccountDetailsMapper expenseAccountDetailsMapper;
 
 
@@ -68,11 +72,24 @@ public class ExpenseAccountServiceImpl extends BaseMybatisDao<ExpenseAccountMapp
      * @param str 备注
      */
     private void addExpenseAccountLog(Integer eaid, Integer status, String str) {
+        String aid=TokenManager.getAdminId();
+        Date date=new Date();
         ExpenseAccountLog eaLog=new ExpenseAccountLog();
         eaLog.setEaid(eaid);
         eaLog.setStatus(status);
         eaLog.setRemarks(str);
-        eaLog.setAuditor(TokenManager.getAdminId());
+        eaLog.setAuditor(aid);
+        Admin admin = adminMapper.selectByPrimaryKey(aid);
+        StringBuffer sb =new StringBuffer();
+        if (status>0){
+            if (status==1){
+                sb.append(str).append("[").append(admin.getName()).append("]").append("发起报销申请,请及时审核。");
+            }else if (status==4){
+                sb.append(str).append("[").append(admin.getName()).append("]").append("修改并重新发起,请重新审核。");
+            }
+            asyncUtils.addNoticAndEmail(NoticeStatus.EXPENSE_NOTICE.getCode(), aid,sb.toString());
+            weChatUtils.addExpenseAccountWeChatNotice(admin.getOpenId(), 1, eaid, date, admin.getName(),sb.toString());
+        }
         expenseAccountLogMapper.insertSelective(eaLog);
     }
 
@@ -164,12 +181,12 @@ public class ExpenseAccountServiceImpl extends BaseMybatisDao<ExpenseAccountMapp
             newEa.setStatus(status);
             str=new StringBuffer("您的报销审核已通过,请注意查看。");
         }
-        addLogAndNoticeAndEmail(in,useEa,status,str.toString(),aids);
+        addLogAndNoticeAndEmail(in,useEa,status,str.toString(),admin.getName(),aids);
         expenseAccountMapper.updateByPrimaryKeySelective(newEa);
         return 1;
     }
 
-    private void addLogAndNoticeAndEmail(InputExpenseAccount in, ExpenseAccount useEa, Integer status, String str, List<Admin> aids) {
+    private void addLogAndNoticeAndEmail(InputExpenseAccount in, ExpenseAccount useEa, Integer status, String str,String aname, List<Admin> aids) {
         addExpenseAccountLog(useEa.getId(),status,in.getReason());
         Date date= new Date();
         Integer noticeStatus=NoticeStatus.EXPENSE_NOTICE.getCode();
@@ -184,12 +201,13 @@ public class ExpenseAccountServiceImpl extends BaseMybatisDao<ExpenseAccountMapp
                 notice.setNoticeType(noticeStatus);
                 notice.setType(NoticeTypes.getType(noticeStatus));
                 notice.setAid(a.getId());
-                notice.setCreateTime(new Date());
+                notice.setCreateTime(date);
                 notice.setContent(str);
                 notice.setReaded(0);
                 list.add(notice);
                 EmailBo emailBo=new EmailBo(NoticeStatus.getValueByCode(noticeStatus),a.getEmail(),str);
                 asyncUtils.send(emailBo);
+                weChatUtils.addNotice(a.getOpenId(),status,in.getId(),date,aname,str);
             }
         asyncUtils.addNoticeBatch(list);
         }

+ 5 - 0
src/main/resources/props/config_local.properties

@@ -58,11 +58,16 @@ rd.static.host=//static.jishutao.com/RD/1.0.00
 #static.host=//172.16.0.255:3000/1.2.62
 #static.host=http://172.16.1.187/prod/1.2.66
 
+#\u5FAE\u4FE1\u6253\u5361\u5C0F\u7A0B\u5E8F
 wx.appId=wxff2f5720ed7d7f63
 wx.appSecret=081744369d42405be58fe37f892631f7
 #developer\u4E3A\u5F00\u53D1\u7248\uFF1Btrial\u4E3A\u4F53\u9A8C\u7248\uFF1Bformal\u4E3A\u6B63\u5F0F\u7248\uFF1B
 wx.state=trial
 wx.clockInRange=1000
+#\u5FAE\u4FE1\u62A5\u9500\u5C0F\u7A0B\u5E8F
+wx.expense.appId=wx4f6bec93d9863623
+wx.expense.appSecret=081744369d42405be58fe37f892631f7
+
 
 portal.host=//sf.jishutao.com/portal/2.0.6
 avatar.upload.host=//sb.jishutao.com/upload