Browse Source

Merge branch 'master' of http://git.dayaedu.com/yonge/mec

zouxuan 4 years ago
parent
commit
390c6a8d54

+ 1 - 0
mec-biz/src/main/java/com/ym/mec/biz/service/impl/CoursesGroupServiceImpl.java

@@ -210,6 +210,7 @@ public class CoursesGroupServiceImpl extends BaseServiceImpl<Long, CoursesGroup>
         try {
             courseScheduleService.checkNewCourseSchedules(newCourses, false);
         } catch (Exception e) {
+            LOGGER.error("检查课程冲突出现异常",e);
             TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
             String errMessage;
             String courseName = e.getMessage().substring(e.getMessage().indexOf(")-") + 2);

+ 5 - 5
mec-biz/src/main/java/com/ym/mec/biz/service/impl/SubjectChangeServiceImpl.java

@@ -180,17 +180,17 @@ public class SubjectChangeServiceImpl extends BaseServiceImpl<Integer, SubjectCh
                 .subtract(subjectChange.getOriginalMusicalPrice()).subtract(subjectChange.getOriginalAccessoriesPrice());
         subjectChange.setGoodsMargin(goodsMargin);
         subjectChange.setCostMargin(subjectChange.getChangeCost().subtract(subjectChange.getOriginalCost()));
+        subjectChange.setCostMargin(subjectChange.getChangeCost().subtract(subjectChange.getOriginalCost()));
         //差价 <= 0
-        if (subjectChange.getGoodsMargin().add(subjectChange.getCourseMargin()).compareTo(BigDecimal.ZERO) <= 0) {
+        BigDecimal amountMargin = subjectChange.getGoodsMargin().add(subjectChange.getCourseMargin());
+        if (amountMargin.compareTo(BigDecimal.ZERO) <= 0) {
             subjectChange.setStatus(SubjectChangeStatusEnum.SUCCESSED);
             subjectChange.setSellAmount(BigDecimal.ZERO);
             subjectChange.setSellTime(nowDate);
         }
         //差价小于0退到余额
-        if (subjectChange.getGoodsMargin().add(subjectChange.getCourseMargin()).compareTo(BigDecimal.ZERO) < 0) {
-            subjectChange.setStatus(SubjectChangeStatusEnum.SUCCESSED);
-            subjectChange.setSellAmount(BigDecimal.ZERO);
-            subjectChange.setSellTime(nowDate);
+        if (amountMargin.compareTo(BigDecimal.ZERO) <= 0) {
+            sysUserCashAccountService.updateBalance(subjectChange.getStudentId(), amountMargin.negate(), PlatformCashAccountDetailTypeEnum.REFUNDS, "声部更换退还");
         }
         subjectChange.setCreateTime(nowDate);
         subjectChange.setUpdateTime(nowDate);

+ 1 - 1
mec-thirdparty/src/main/java/com/ym/mec/thirdparty/eseal/ESealPluginContext.java

@@ -38,7 +38,7 @@ public class ESealPluginContext implements ApplicationContextAware, Initializing
 	@Override
 	public void afterPropertiesSet() throws Exception {
 		if (StringUtils.isBlank(eSealPluginName)) {
-			throw new ThirdpartyException("存储插件变量thirdparty.storagePlugName不能为空");
+			throw new ThirdpartyException("存储插件变量thirdparty.eSealPluginName不能为空");
 		}
 
 		eSealPlugin = getStoragePlugin(eSealPluginName);

+ 18 - 0
mec-thirdparty/src/main/java/com/ym/mec/thirdparty/user/realname/RealnameAuthenticationPlugin.java

@@ -0,0 +1,18 @@
+package com.ym.mec.thirdparty.user.realname;
+
+import org.springframework.beans.factory.DisposableBean;
+import org.springframework.beans.factory.InitializingBean;
+
+/**
+ * 实名认证
+ */
+public interface RealnameAuthenticationPlugin extends InitializingBean, DisposableBean {
+
+	/**
+	 * 验证
+	 * @param realname 真实姓名
+	 * @param idcardNo 身份证号码
+	 * @return true,匹配成功;否则,匹配失败
+	 */
+	public boolean verify(String realname, String idcardNo);
+}

+ 66 - 0
mec-thirdparty/src/main/java/com/ym/mec/thirdparty/user/realname/RealnameAuthenticationPluginContext.java

@@ -0,0 +1,66 @@
+package com.ym.mec.thirdparty.user.realname;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.BeansException;
+import org.springframework.beans.factory.InitializingBean;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.ApplicationContextAware;
+import org.springframework.stereotype.Component;
+
+import com.ym.mec.thirdparty.exception.ThirdpartyException;
+import com.ym.mec.thirdparty.user.realname.provider.LinkfaceRealnameAuthenticationPlugin;
+
+@Component
+public class RealnameAuthenticationPluginContext implements ApplicationContextAware, InitializingBean {
+
+	@Value("${thirdparty.realnameAuthenticationPluginName:linkface}")
+	private String pluginName;
+
+	private ApplicationContext applicationContext;
+
+	private final Map<String, String> mapper = new HashMap<String, String>() {
+
+		/**
+		 * 
+		 */
+		private static final long serialVersionUID = -7516427405929382747L;
+
+		{
+			put(LinkfaceRealnameAuthenticationPlugin.getName(), StringUtils.uncapitalize(LinkfaceRealnameAuthenticationPlugin.class.getSimpleName()));
+		}
+	};
+
+	private RealnameAuthenticationPlugin realnameAuthenticationPlugin;
+
+	@Override
+	public void afterPropertiesSet() throws Exception {
+		if (StringUtils.isBlank(pluginName)) {
+			throw new ThirdpartyException("存储插件变量thirdparty.storagePlugName不能为空");
+		}
+
+		realnameAuthenticationPlugin = getStoragePlugin(pluginName);
+
+		if (realnameAuthenticationPlugin == null) {
+			throw new ThirdpartyException("实名认证插件{}不存在", pluginName);
+		}
+	}
+
+	@Override
+	public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
+		this.applicationContext = applicationContext;
+	}
+
+	private RealnameAuthenticationPlugin getStoragePlugin(String vendors) {
+		String beanId = mapper.get(vendors);
+
+		if (StringUtils.isBlank(beanId)) {
+			throw new ThirdpartyException("实名认证提供商不存在");
+		}
+
+		return applicationContext.getBean(beanId, RealnameAuthenticationPlugin.class);
+	}
+}

+ 121 - 0
mec-thirdparty/src/main/java/com/ym/mec/thirdparty/user/realname/provider/LinkfaceRealnameAuthenticationPlugin.java

@@ -0,0 +1,121 @@
+package com.ym.mec.thirdparty.user.realname.provider;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Service;
+
+import com.alibaba.fastjson.JSONObject;
+import com.ym.mec.thirdparty.exception.ThirdpartyException;
+import com.ym.mec.thirdparty.user.realname.RealnameAuthenticationPlugin;
+import com.ym.mec.util.http.HttpUtil;
+
+@Service
+public class LinkfaceRealnameAuthenticationPlugin implements RealnameAuthenticationPlugin {
+
+	@Value("${realnameAuthentication.linkface.projectid:2cd4937c8dbd4f6a9c70c6d3122df5f4}")
+	public String appId;
+
+	@Value("${realnameAuthentication.linkface.projectSecret:3f809f3800654780beff1ce09b780297}")
+	public String appSecret;
+
+	@Value("${realnameAuthentication.linkface.apisUrl:https://cloudapi.linkface.cn/data/verify_id_name}")
+	public String apisUrl;
+
+	private Map<String, String> reason = new HashMap<String, String>() {
+		/**
+		 * 
+		 */
+		private static final long serialVersionUID = -5123335186604042998L;
+
+		{
+			// 定义错误原因
+			put("ENCODING_ERROR", "参数非 UTF-8 编码");
+			put("INVALID_ARGUMENT", "姓名或者身份证号填写错误");
+			put("UNAUTHORIZED", "账号或密钥错误");
+			put("KEY_EXPIRED", "账号过期");
+			put("RATE_LIMIT_EXCEEDED", "调用频率过高");
+			put("OUT_OF_QUOTA", "调用次数超出限额");
+			put("NO_PERMISSION", "无调用权限");
+			put("NOT_FOUND", "请求路径错误");
+			put("DATA_SERVER_ERROR", "数据服务异常");
+			put("INTERNAL_ERROR", "内部服务异常");
+		}
+	};
+
+	public static String getName() {
+		return "linkface";
+	}
+
+	@Override
+	public void destroy() throws Exception {
+
+	}
+
+	@Override
+	public void afterPropertiesSet() throws Exception {
+		if (StringUtils.isBlank(appId) || StringUtils.isBlank(appSecret) || StringUtils.isBlank(apisUrl)) {
+			throw new ThirdpartyException("实名认证插件 - Linkface 系统参数缺失,请检查");
+		}
+
+	}
+
+	@Override
+	public boolean verify(String realname, String idcardNo) {
+		String respJson = "";
+		HashMap<String, Object> params = new HashMap<String, Object>();
+		params.put("api_id", appId);
+		params.put("api_secret", appSecret);
+		params.put("name", realname);
+		params.put("id_number", idcardNo);
+		try {
+			respJson = HttpUtil.postForHttps(this.apisUrl, params);
+		} catch (Exception e) {
+			throw new ThirdpartyException("HttpUtil Connection Exception", e);
+		}
+		JSONObject json = JSONObject.parseObject(respJson);
+
+		String status = json.get("status").toString();
+		Integer result = json.get("result") == null ? null : Integer.parseInt(json.get("result").toString());
+
+		// 获取返回码
+		if (StringUtils.equals("OK", status) && (result != null && result == 1)) {
+			return true;
+		} else {
+			String msg = "";
+			if (result != null) {
+				if (result == 2) {
+					msg = "身份证号和姓名不⼀致";
+				} else if (result == 3) {
+					msg = "查无此身份证号";
+				}
+			} else {
+				msg = reason.get(status);
+			}
+			throw new ThirdpartyException("实名认证失败,原因:{}", msg);
+		}
+	}
+
+	public void setAppId(String appId) {
+		this.appId = appId;
+	}
+
+	public void setAppSecret(String appSecret) {
+		this.appSecret = appSecret;
+	}
+
+	public void setApisUrl(String apisUrl) {
+		this.apisUrl = apisUrl;
+	}
+
+	public static void main(String[] args) {
+		LinkfaceRealnameAuthenticationPlugin plugin = new LinkfaceRealnameAuthenticationPlugin();
+		plugin.setAppId("2cd4937c8dbd4f6a9c70c6d3122df5f4");
+		plugin.setAppSecret("3f809f3800654780beff1ce09b780297");
+		plugin.setApisUrl("https://cloudapi.linkface.cn/data/verify_id_name");
+
+		System.out.println(plugin.verify("王武", "411526199706013217"));
+	}
+}