anderx лет назад: 2
Родитель
Сommit
25b25f1e81

+ 8 - 36
src/main/java/com/goafanti/admin/controller/AdminApiController.java

@@ -12,6 +12,7 @@ import javax.validation.Valid;
 
 import com.goafanti.ambSystem.service.AmbPaymentService;
 import com.goafanti.common.model.*;
+import com.goafanti.common.utils.*;
 import com.goafanti.order.enums.OrderImgEnums;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -90,11 +91,6 @@ import com.goafanti.common.enums.UserFields;
 import com.goafanti.common.enums.UserIdentityFields;
 import com.goafanti.common.enums.UserLevel;
 import com.goafanti.common.enums.UserType;
-import com.goafanti.common.utils.DateUtils;
-import com.goafanti.common.utils.HttpUtils;
-import com.goafanti.common.utils.LoggerUtils;
-import com.goafanti.common.utils.PasswordUtil;
-import com.goafanti.common.utils.StringUtils;
 import com.goafanti.copyright.bo.CopyrightInfoDetail;
 import com.goafanti.copyright.service.CopyrightInfoService;
 import com.goafanti.core.shiro.token.TokenManager;
@@ -163,18 +159,12 @@ public class AdminApiController extends CertifyApiController {
 	private OrgCognizanceProportionService	orgCognizanceProportionService;
 	@Autowired
 	private AmbPaymentService ambPaymentService;
+	@Autowired
+	private WeChatUtils weChatUtils;
 
 
 
-	@Value(value = "${wx.appId}")
-	private String appId;
-	@Value(value = "${wx.appSecret}")
-	private String appSecret;
 
-	@Value(value = "${wx.expense.appId}")
-	private String expenseAppId;
-	@Value(value = "${wx.expense.appSecret}")
-	private String expenseAppSecret;
 
 
 	/**
@@ -3038,30 +3028,12 @@ public class AdminApiController extends CertifyApiController {
 	@RequestMapping(value ="/setOpenId" , method = RequestMethod.POST)
 	public Result setOpenId(String code,Integer type) {
 		Result res =new Result();
-		if(type==null)type=0;
-		String url = "https://api.weixin.qq.com/sns/jscode2session?";
-		if (type==1){
-			url=url+"appid="+expenseAppId+"&secret="+expenseAppSecret+"&js_code="+code+"&grant_type=authorization_code";
-		}else{
-			url=url+"appid="+appId+"&secret="+appSecret+"&js_code="+code+"&grant_type=authorization_code";
-		}
-		JSONObject json= HttpUtils.httpGet(url);
-		System.out.println(json.toJSONString());
-		String openid=json.getString("openid");
-		if (StringUtils.isNotBlank(openid)) {
-			LoggerUtils.debug(getClass(), "获取"+(type==1?"报销":"公出")+"openid:"+openid);
-			Admin a=new Admin();
-			if (type!=null&&type==1){
-				a.setExpenseOpenId(openid);
-			}else {
-				a.setOpenId(openid);
-			}
-			a.setId(TokenManager.getAdminId());
-			adminService.updateByPrimaryKey(a);
-			res.data(1);
-		}else {
-			res.getError().add(buildError("openid绑定失败"));
+		Integer integer = weChatUtils.setOpenId(code, type);
+		if (integer==-1){
+			res.getError().add(buildError("openId绑定异常"));
+			return res;
 		}
+		res.setData(integer);
 		return res;
 	}
 

+ 94 - 0
src/main/java/com/goafanti/common/bo/AdminNoticeBo.java

@@ -0,0 +1,94 @@
+package com.goafanti.common.bo;
+
+public class AdminNoticeBo {
+    private String id;
+    private String name;
+    private String email;
+    private String openId;
+    private String expenseOpenId;
+    private String superId;
+    private String superName;
+    private String superEmail;
+    private String superOpenId;
+    private String superExpenseOpenId;
+
+    public String getId() {
+        return id;
+    }
+
+    public void setId(String id) {
+        this.id = id;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public String getEmail() {
+        return email;
+    }
+
+    public void setEmail(String email) {
+        this.email = email;
+    }
+
+    public String getOpenId() {
+        return openId;
+    }
+
+    public void setOpenId(String openId) {
+        this.openId = openId;
+    }
+
+    public String getExpenseOpenId() {
+        return expenseOpenId;
+    }
+
+    public void setExpenseOpenId(String expenseOpenId) {
+        this.expenseOpenId = expenseOpenId;
+    }
+
+    public String getSuperId() {
+        return superId;
+    }
+
+    public void setSuperId(String superId) {
+        this.superId = superId;
+    }
+
+    public String getSuperName() {
+        return superName;
+    }
+
+    public void setSuperName(String superName) {
+        this.superName = superName;
+    }
+
+    public String getSuperEmail() {
+        return superEmail;
+    }
+
+    public void setSuperEmail(String superEmail) {
+        this.superEmail = superEmail;
+    }
+
+    public String getSuperOpenId() {
+        return superOpenId;
+    }
+
+    public void setSuperOpenId(String superOpenId) {
+        this.superOpenId = superOpenId;
+    }
+
+    public String getSuperExpenseOpenId() {
+        return superExpenseOpenId;
+    }
+
+    public void setSuperExpenseOpenId(String superExpenseOpenId) {
+        this.superExpenseOpenId = superExpenseOpenId;
+    }
+}

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

@@ -3,6 +3,7 @@ package com.goafanti.common.dao;
 import com.goafanti.admin.bo.AdminContacts;
 import com.goafanti.admin.bo.AdminCustomerBo;
 import com.goafanti.admin.bo.AdminListBo;
+import com.goafanti.common.bo.AdminNoticeBo;
 import com.goafanti.common.model.Admin;
 import com.goafanti.common.model.Department;
 import com.goafanti.common.model.Role;
@@ -153,7 +154,7 @@ public interface AdminMapper {
 
     Admin selectByOpeid(String openid);
 
-    Admin selectGetSuper(String aid);
+    AdminNoticeBo selectMyAndSuperBySuperId(String id);
 
     List<String> getFinanceDep(String aid);
 

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

@@ -1151,11 +1151,12 @@
     select id from admin where superior_id= #{aid}
   </select>
 
-  <select id="selectGetSuper" parameterType="java.lang.String" resultMap="BaseResultMap">
+  <select id="selectMyAndSuperBySuperId" parameterType="java.lang.String" resultType="com.goafanti.common.bo.AdminNoticeBo">
     select
-    <include refid="Base_Column_List" />
-    from admin
-    where  superior_id= #{aid}
+    a.id,a.name,a.email,a.open_id openId,a.expense_open_id expenseOpenId,
+    b.id superId,b.name superName,b.email superEmail,b.open_id superOpenId,b.expense_open_id superExpenseOpenId
+    from admin a left join admin b on a.superior_id=b.id
+    where  a.id=#{id}
   </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

+ 88 - 10
src/main/java/com/goafanti/common/utils/WeChatUtils.java

@@ -5,6 +5,10 @@ import java.util.HashMap;
 import java.util.Map;
 
 
+import com.goafanti.common.bo.Result;
+import com.goafanti.common.dao.AdminMapper;
+import com.goafanti.common.model.Admin;
+import com.goafanti.core.shiro.token.TokenManager;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Component;
@@ -22,10 +26,17 @@ public class WeChatUtils {
 	private String appId;
 	@Value(value = "${wx.appSecret}")
 	private String appSecret;
+	@Value(value = "${wx.expense.appId}")
+	private String expenseAppId;
+	@Value(value = "${wx.expense.appSecret}")
+	private String expenseAppSecret;
 	@Value(value = "${wx.state}")
 	private String wxState;
 	@Autowired
 	private RedisUtil redisUtil;
+	@Autowired
+	private AdminMapper adminMapper;
+
 
 	/**
 	 * 公出待审核通知
@@ -83,7 +94,7 @@ public class WeChatUtils {
 	private Integer SendHttpPost(Map<String, Object> map, String url) {
 		JSONObject res=HttpUtils.httpPost(url, map);
 		if (res.get("errcode")!=null) {
-			LoggerUtils.debug(this.getClass(),res.getInteger("errcode").toString());
+			LoggerUtils.debug(this.getClass(),"errcode={%s},url={%s}",res.getInteger("errcode").toString(),url);
 			return res.getInteger("errcode");
 		}else {
 			return 1;
@@ -100,7 +111,7 @@ public class WeChatUtils {
 	 */
 	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 accessToken=getExpenseAccountAccessToken();
 		String url=send_url.replace("ACCESS_TOKEN", accessToken);
 		map.put("access_token", accessToken);
 		map.put("touser", openid);
@@ -217,22 +228,57 @@ public class WeChatUtils {
 				LoggerUtils.debug(getClass(), "accestoken超时重新获取");
 				redisUtil.deleteString("access_token");
 				redisUtil.deleteString("expires_in");
-				return setSessionAccessToken(date);
+				return setSessionAccessToken(date,0);
 			}
 
 		} else {
-			return setSessionAccessToken(date);
+			return setSessionAccessToken(date,0);
 		}
 
 
 	}
 
+	public String getExpenseAccountAccessToken() {
+		Date date = new Date();
+		if (redisUtil.presence("expense_access_token")||redisUtil.presence("expense_expires_in")) {
+			String access_token=redisUtil.getString("expense_access_token");
+			String expires_in=redisUtil.getString("expense_expires_in");
+			if (date.getTime() < Long.valueOf(expires_in)) {
+				LoggerUtils.debug(getClass(), "redis中获取accestoken");
+				return access_token;
+			} else {
+				LoggerUtils.debug(getClass(), "accestoken超时重新获取");
+				redisUtil.deleteString("expense_access_token");
+				redisUtil.deleteString("expense_expires_in");
+				return setSessionAccessToken(date,1);
+			}
 
+		} else {
+			return setSessionAccessToken(date,1);
+		}
+
+
+	}
+
+
+	/**
+	 *
+	 * @param date 参数
+	 * @param type 0公出小程序 1报销小程序
+	 * @return
+	 */
+	private String setSessionAccessToken(Date date,Integer type) {
+		String url =null;
+		if (type==0){
+			url=String.format(
+					"https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=%s&secret=%s", appId,
+					appSecret);
+		}else if(type==1){
+			url=String.format(
+					"https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=%s&secret=%s", expenseAppId,
+					expenseAppSecret);
+		}
 
-	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) {
@@ -245,9 +291,41 @@ public class WeChatUtils {
 		//返回时间为秒需要计算换成毫秒
 		expires_in=expires_in*1000;
 		expires_in+=date.getTime();
-		redisUtil.setString("access_token", access_token);
-		redisUtil.setString("expires_in", expires_in.toString());
+		if (type==0){
+			redisUtil.setString("access_token", access_token);
+			redisUtil.setString("expires_in", expires_in.toString());
+		}else if (type==1){
+			redisUtil.setString("expense_access_token", access_token);
+			redisUtil.setString("expense_expires_in", expires_in.toString());
+		}
+
 		return access_token;
 	}
 
+	public Integer setOpenId(String code, Integer type) {
+		if(type==null)type=0;
+		String url = "https://api.weixin.qq.com/sns/jscode2session?";
+		if (type==1){
+			url=url+"appid="+expenseAppId+"&secret="+expenseAppSecret+"&js_code="+code+"&grant_type=authorization_code";
+		}else{
+			url=url+"appid="+appId+"&secret="+appSecret+"&js_code="+code+"&grant_type=authorization_code";
+		}
+		JSONObject json= HttpUtils.httpGet(url);
+		System.out.println(json.toJSONString());
+		String openid=json.getString("openid");
+		if (StringUtils.isNotBlank(openid)) {
+			LoggerUtils.debug(getClass(), "获取"+(type==1?"报销":"公出")+"openid:"+openid);
+			Admin a=new Admin();
+			if (type!=null&&type==1){
+				a.setExpenseOpenId(openid);
+			}else {
+				a.setOpenId(openid);
+			}
+			a.setId(TokenManager.getAdminId());
+			adminMapper.updateByPrimaryKeySelective(a);
+			return 1;
+		}else {
+			return -1;
+		}
+	}
 }

+ 1 - 1
src/main/java/com/goafanti/expenseAccount/service/ExpenseAccountPrivateService.java

@@ -5,7 +5,7 @@ import com.goafanti.expenseAccount.bo.InputExpenseAccountPrivate;
 import com.goafanti.expenseAccount.bo.OutExpenseAccountPrivate;
 
 public interface ExpenseAccountPrivateService {
-    int add(InputExpenseAccountPrivate in);
+    ExpenseAccountPrivate add(InputExpenseAccountPrivate in);
 
     Object selectList(Integer pageSize, Integer pageNo);
 

+ 4 - 2
src/main/java/com/goafanti/expenseAccount/service/impl/ExpenseAccountPrivateServiceImpl.java

@@ -21,9 +21,11 @@ public class ExpenseAccountPrivateServiceImpl extends BaseMybatisDao<ExpenseAcco
     private ExpenseAccountPrivateMapper expenseAccountPrivateMapper;
 
     @Override
-    public int add(InputExpenseAccountPrivate in) {
+    public ExpenseAccountPrivate add(InputExpenseAccountPrivate in) {
         updateStatus(in);
-        return expenseAccountPrivateMapper.insertSelective(in);
+        expenseAccountPrivateMapper.insertSelective(in);
+        ExpenseAccountPrivate res=in;
+        return res;
     }
 
     private void updateStatus(InputExpenseAccountPrivate in) {

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

@@ -2,6 +2,7 @@ package com.goafanti.expenseAccount.service.impl;
 
 import com.goafanti.admin.bo.AdminListBo;
 import com.goafanti.admin.bo.NoticeBo;
+import com.goafanti.common.bo.AdminNoticeBo;
 import com.goafanti.common.bo.EmailBo;
 import com.goafanti.common.constant.AFTConstants;
 import com.goafanti.common.dao.*;
@@ -82,16 +83,15 @@ public class ExpenseAccountServiceImpl extends BaseMybatisDao<ExpenseAccountMapp
         eaLog.setStatus(status);
         eaLog.setRemarks(str);
         eaLog.setAuditor(aid);
-        Admin admin = adminMapper.selectByPrimaryKey(aid);
+        //日志写入用操作人,邮箱、微信订阅与站内信要的是发送方消息,即收件人
+
+        AdminNoticeBo an = adminMapper.selectMyAndSuperBySuperId(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.getExpenseOpenId(), 1, eaid, date, admin.getName(),sb.toString());
+            sb=sb.append("[").append(an.getName()).append("]").append(str).append(",请及时审核。");
+            asyncUtils.addNoticAndEmail(NoticeStatus.EXPENSE_NOTICE.getCode(), an.getSuperId(),sb.toString());
+            weChatUtils.addExpenseAccountWeChatNotice(an.getExpenseOpenId(), 1, eaid, date, an.getName(),sb.toString());
         }
         expenseAccountLogMapper.insertSelective(eaLog);
     }
@@ -113,7 +113,7 @@ public class ExpenseAccountServiceImpl extends BaseMybatisDao<ExpenseAccountMapp
         if (useEA.getStatus()==0){
             addExpenseAccountLog(useEA.getId(),1,"发起报销审核");
         }else if (useEA.getStatus()==3){
-            addExpenseAccountLog(useEA.getId(),4,"修改重新发起审核");
+            addExpenseAccountLog(useEA.getId(),4,"修改发起审核");
         }
         return expenseAccountMapper.updateByPrimaryKeySelective(in);
     }
@@ -190,7 +190,7 @@ public class ExpenseAccountServiceImpl extends BaseMybatisDao<ExpenseAccountMapp
     }
 
     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();
         if (status==2){
@@ -210,7 +210,7 @@ public class ExpenseAccountServiceImpl extends BaseMybatisDao<ExpenseAccountMapp
                 list.add(notice);
                 EmailBo emailBo=new EmailBo(NoticeStatus.getValueByCode(noticeStatus),a.getEmail(),str);
                 asyncUtils.send(emailBo);
-                weChatUtils.addNotice(a.getExpenseOpenId(),status,in.getId(),date,aname,str);
+                weChatUtils.addExpenseAccountWeChatNotice(a.getExpenseOpenId(),status,in.getId(),date,aname,str);
             }
         asyncUtils.addNoticeBatch(list);
         }