支付能力配置
diff --git a/src/main/java/com/supwisdom/dlpay/api/dao/PaytypeConfigDao.java b/src/main/java/com/supwisdom/dlpay/api/dao/PaytypeConfigDao.java
index 65f8e1a..021d398 100644
--- a/src/main/java/com/supwisdom/dlpay/api/dao/PaytypeConfigDao.java
+++ b/src/main/java/com/supwisdom/dlpay/api/dao/PaytypeConfigDao.java
@@ -13,4 +13,6 @@
@Repository
public interface PaytypeConfigDao extends JpaRepository<TPaytypeConfig, TPaytypeConfigPK> {
List<TPaytypeConfig> getByPaytype(String paytype);
+
+ TPaytypeConfig getByPaytypeAndAndConfigid(String paytype, String configid);
}
diff --git a/src/main/java/com/supwisdom/dlpay/system/controller/ParamController.java b/src/main/java/com/supwisdom/dlpay/system/controller/ParamController.java
index 0313df1..eb9f3f4 100644
--- a/src/main/java/com/supwisdom/dlpay/system/controller/ParamController.java
+++ b/src/main/java/com/supwisdom/dlpay/system/controller/ParamController.java
@@ -2,22 +2,23 @@
import com.supwisdom.dlpay.api.bean.JsonResult;
import com.supwisdom.dlpay.api.domain.TPaytype;
+import com.supwisdom.dlpay.api.domain.TPaytypeConfig;
import com.supwisdom.dlpay.framework.domain.TApiClient;
import com.supwisdom.dlpay.framework.domain.TBusinesspara;
import com.supwisdom.dlpay.framework.domain.TSyspara;
import com.supwisdom.dlpay.framework.service.SystemUtilService;
import com.supwisdom.dlpay.framework.util.*;
import com.supwisdom.dlpay.system.service.ParamService;
+import com.supwisdom.dlpay.util.ConstantUtil;
+import com.supwisdom.dlpay.util.WebCheckException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestParam;
-import org.springframework.web.bind.annotation.ResponseBody;
+import org.springframework.web.bind.annotation.*;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
@Controller
@@ -95,8 +96,8 @@
@PreAuthorize("hasPermission('/param/businesspara','')")
@ResponseBody
public PageResult<TBusinesspara> getBusinessDataList(@RequestParam("page") Integer pageNo,
- @RequestParam("limit") Integer pageSize,
- @RequestParam(value = "paraname", required = false) String paraname) {
+ @RequestParam("limit") Integer pageSize,
+ @RequestParam(value = "paraname", required = false) String paraname) {
try {
if (null == pageNo || pageNo < 1) pageNo = WebConstant.PAGENO_DEFAULT;
if (null == pageSize || pageSize < 1) pageSize = WebConstant.PAGESIZE_DEFAULT;
@@ -200,7 +201,7 @@
/**
* ====================================================
- * APPID应用权限参数管理
+ * APPID应用权限参数管理
* ====================================================
*/
@GetMapping("/param/apiclientpara")
@@ -291,8 +292,8 @@
@PreAuthorize("hasPermission('/param/updateapiclientpara','')")
@ResponseBody
public JsonResult updateApiclientSecret(@RequestParam("appid") String appid,
- @RequestParam(value = "secret", required = false) String secret,
- @RequestParam(value = "roles", required = false) String roles) {
+ @RequestParam(value = "secret", required = false) String secret,
+ @RequestParam(value = "roles", required = false) String roles) {
if (StringUtil.isEmpty(appid) || (StringUtil.isEmpty(secret) && StringUtil.isEmpty(roles))) {
return JsonResult.error("参数传递错误");
}
@@ -322,7 +323,7 @@
@PreAuthorize("hasPermission('/param/addapiclientpara','')")
@ResponseBody
public JsonResult addApiclientPara(@RequestParam("appid") String appid,
- @RequestParam("roles") String roles) {
+ @RequestParam("roles") String roles) {
if (StringUtil.isEmpty(appid) || StringUtil.isEmpty(roles)) {
return JsonResult.error("参数传递错误");
}
@@ -349,7 +350,7 @@
/**
* ====================================================
- * 支付能力配置
+ * 支付能力配置
* ====================================================
*/
@GetMapping("/param/paytype")
@@ -373,4 +374,181 @@
}
}
+ @GetMapping("/param/load4addpaytype")
+ @PreAuthorize("hasPermission('/param/load4addpaytype','')")
+ public String load4AddPaytype(Model model) {
+ return "system/param/paytypeform";
+ }
+
+ @PostMapping("/param/updatepaytypestate")
+ @PreAuthorize("hasPermission('/param/updatepaytypestate','')")
+ @ResponseBody
+ public JsonResult updatePaytypeState(@RequestParam("paytype") String paytype,
+ @RequestParam("state") String state,
+ @RequestParam(value = "optype", required = false) String optype) {
+ if (StringUtil.isEmpty(paytype) || (!ConstantUtil.ENABLE_YES.equals(state) && !ConstantUtil.ENABLE_NO.equals(state)) || (!StringUtil.isEmpty(optype) && !"charge".equals(optype) && !"consume".equals(optype) && !"anonymous".equals(optype))) {
+ return JsonResult.error("参数传递错误");
+ }
+ try {
+ TPaytype tPaytype = paramService.getPaytype(paytype);
+ if (null == tPaytype) {
+ return JsonResult.error("支付方式不存在!");
+ }
+ if ("charge".equals(optype)) {
+ if (state.equals(tPaytype.getChargeEnable())) {
+ return JsonResult.error("状态错误,请重新查询后操作");
+ }
+ tPaytype.setChargeEnable(state);
+ } else if ("consume".equals(optype)) {
+ if (state.equals(tPaytype.getConsumeEnable())) {
+ return JsonResult.error("状态错误,请重新查询后操作");
+ }
+ tPaytype.setConsumeEnable(state);
+ } else if ("anonymous".equals(optype)) {
+ if (state.equals(tPaytype.getAnonymousEnable())) {
+ return JsonResult.error("状态错误,请重新查询后操作");
+ }
+ tPaytype.setAnonymousEnable(state);
+ } else {
+ if (state.equals(tPaytype.getEnable())) {
+ return JsonResult.error("状态错误,请重新查询后操作");
+ }
+ tPaytype.setEnable(state); //默认切换主状态
+ }
+
+ if (paramService.saveOrUpdatePaytype(tPaytype)) {
+ return JsonResult.ok(ConstantUtil.ENABLE_YES.equals(state) ? "启用成功" : "关闭成功");
+ } else {
+ return JsonResult.error(ConstantUtil.ENABLE_YES.equals(state) ? "启用失败" : "关闭失败");
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ return JsonResult.error("系统处理异常").put("exception", e);
+ }
+ }
+
+ @PostMapping("/param/updatepaytypename")
+ @PreAuthorize("hasPermission('/param/updatepaytypename','')")
+ @ResponseBody
+ public JsonResult updatePaytypeName(@RequestParam("paytype") String paytype,
+ @RequestParam("paydesc") String paydesc) {
+ if (StringUtil.isEmpty(paytype) || StringUtil.isEmpty(paydesc)) {
+ return JsonResult.error("参数传递错误");
+ }
+ try {
+ TPaytype tPaytype = paramService.getPaytype(paytype);
+ if (null == tPaytype) {
+ return JsonResult.error("支付方式不存在!");
+ }
+ tPaytype.setPaydesc(paydesc.trim());
+ if (paramService.saveOrUpdatePaytype(tPaytype)) {
+ return JsonResult.ok("修改成功");
+ } else {
+ return JsonResult.error("修改失败");
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ return JsonResult.error("系统处理异常").put("exception", e);
+ }
+ }
+
+ @PostMapping("/param/deletepaytype")
+ @PreAuthorize("hasPermission('/param/deletepaytype','')")
+ @ResponseBody
+ public JsonResult deletePaytype(@RequestParam("paytype") String paytype) {
+ try {
+ TPaytype tPaytype = paramService.getPaytype(paytype);
+ if (null == tPaytype) {
+ return JsonResult.error("支付方式不存在!");
+ }
+ if (paramService.deletePaytype(tPaytype)) {
+ return JsonResult.ok("删除成功");
+ } else {
+ return JsonResult.error("删除失败");
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ return JsonResult.error("系统处理异常").put("exception", e);
+ }
+ }
+
+ @PostMapping("/param/addpaytype")
+ @PreAuthorize("hasPermission('/param/addpaytype','')")
+ @ResponseBody
+ public JsonResult addPaytype(@RequestParam("paytype") String paytype,
+ @RequestParam(value = "enable",required = false,defaultValue = "no") String enable,
+ @RequestParam(value = "chargeEnable",required = false,defaultValue = "no") String chargeEnable,
+ @RequestParam(value = "consumeEnable",required = false,defaultValue = "no") String consumeEnable,
+ @RequestParam(value = "anonymousEnable",required = false,defaultValue = "no") String anonymousEnable,
+ @RequestParam("paydesc") String paydesc) {
+ try {
+ TPaytype tPaytype = paramService.getPaytype(paytype);
+ if (null != tPaytype) {
+ return JsonResult.error("支付方式已经存在");
+ }
+ tPaytype = new TPaytype();
+ tPaytype.setPaytype(paytype.trim());
+ if (StringUtil.isEmpty(paydesc)) return JsonResult.error("支付名称不能为空!");
+ tPaytype.setPaydesc(paydesc.trim());
+ tPaytype.setEnable(ConstantUtil.ENABLE_YES.equalsIgnoreCase(enable) ? ConstantUtil.ENABLE_YES : ConstantUtil.ENABLE_NO);
+ tPaytype.setChargeEnable(ConstantUtil.ENABLE_YES.equalsIgnoreCase(chargeEnable) ? ConstantUtil.ENABLE_YES : ConstantUtil.ENABLE_NO);
+ tPaytype.setConsumeEnable(ConstantUtil.ENABLE_YES.equalsIgnoreCase(consumeEnable) ? ConstantUtil.ENABLE_YES : ConstantUtil.ENABLE_NO);
+ tPaytype.setAnonymousEnable(ConstantUtil.ENABLE_YES.equalsIgnoreCase(anonymousEnable) ? ConstantUtil.ENABLE_YES : ConstantUtil.ENABLE_NO);
+ if (paramService.saveOrUpdatePaytype(tPaytype)) {
+ return JsonResult.ok("新增成功");
+ } else {
+ return JsonResult.error("新增失败");
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ return JsonResult.error("系统处理异常").put("exception", e);
+ }
+ }
+
+ @GetMapping("/param/checkpaytype")
+ @ResponseBody
+ public JsonResult checkPaytype(@RequestParam("paytype") String paytype) {
+ TPaytype tPaytype = paramService.getPaytype(paytype);
+ if (null != tPaytype) {
+ return JsonResult.error("支付方式已经存在");
+ } else {
+ return JsonResult.ok("可以使用");
+ }
+ }
+
+ @GetMapping("/param/load4paytypeconfig")
+ @PreAuthorize("hasPermission('/param/load4paytypeconfig','')")
+ public String load4PaytypeConfig(@RequestParam("paytype") String paytype, Model model) {
+ List<TPaytypeConfig> configList = paramService.getPaytypeConfigList(paytype);
+ model.addAttribute("configlist", configList);
+ model.addAttribute("paytype", paytype);
+ return "system/param/paytypeconfig";
+ }
+
+ @PostMapping("/param/addpaytypeconfig")
+ @PreAuthorize("hasPermission('/param/addpaytypeconfig','')")
+ @ResponseBody
+ public JsonResult addPaytypeConfig(@RequestBody Map<String,String> param){
+ String paytypeHtmlKey = "hid_paytype"; //页面上传来paytype的KEY
+ if(null==param || StringUtil.isEmpty(param.get(paytypeHtmlKey))){
+ return JsonResult.error("参数传递错误");
+ }
+
+ try {
+ String paytype = param.get(paytypeHtmlKey).trim();
+ param.remove(paytypeHtmlKey);
+ if (paramService.savePaytypeConfig(paytype, param)) {
+ return JsonResult.ok("配置成功");
+ } else {
+ return JsonResult.error("配置失败");
+ }
+ } catch (WebCheckException ex) {
+ return JsonResult.error(ex.getMessage());
+ } catch (Exception e) {
+ e.printStackTrace();
+ return JsonResult.error("系统处理异常").put("exception", e);
+ }
+ }
+
+
}
diff --git a/src/main/java/com/supwisdom/dlpay/system/service/ParamService.java b/src/main/java/com/supwisdom/dlpay/system/service/ParamService.java
index aa5f7ea..4dedc44 100644
--- a/src/main/java/com/supwisdom/dlpay/system/service/ParamService.java
+++ b/src/main/java/com/supwisdom/dlpay/system/service/ParamService.java
@@ -1,13 +1,18 @@
package com.supwisdom.dlpay.system.service;
import com.supwisdom.dlpay.api.domain.TPaytype;
+import com.supwisdom.dlpay.api.domain.TPaytypeConfig;
import com.supwisdom.dlpay.framework.domain.TApiClient;
import com.supwisdom.dlpay.framework.domain.TBusinesspara;
import com.supwisdom.dlpay.framework.domain.TSyspara;
import com.supwisdom.dlpay.framework.util.PageResult;
+import com.supwisdom.dlpay.util.WebCheckException;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
+import java.util.List;
+import java.util.Map;
+
public interface ParamService {
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class, readOnly = true)
@@ -46,4 +51,21 @@
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class, readOnly = true)
PageResult<TPaytype> getPaytypePage(String paytype, int pageNo, int pageSize);
+ @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class, readOnly = true)
+ TPaytype getPaytype(String paytype);
+
+ @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
+ boolean saveOrUpdatePaytype(TPaytype paytype);
+
+ @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
+ boolean deletePaytype(TPaytype paytype);
+
+ @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class, readOnly = true)
+ List<TPaytypeConfig> getPaytypeConfigList(String paytype);
+
+ @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
+ boolean savePaytypeConfig(String paytype, Map<String, String> param) throws WebCheckException;
+
+
+
}
diff --git a/src/main/java/com/supwisdom/dlpay/system/service/impl/ParamServiceImpl.java b/src/main/java/com/supwisdom/dlpay/system/service/impl/ParamServiceImpl.java
index 5ed8ca9..4fff8ce 100644
--- a/src/main/java/com/supwisdom/dlpay/system/service/impl/ParamServiceImpl.java
+++ b/src/main/java/com/supwisdom/dlpay/system/service/impl/ParamServiceImpl.java
@@ -1,7 +1,9 @@
package com.supwisdom.dlpay.system.service.impl;
+import com.supwisdom.dlpay.api.dao.PaytypeConfigDao;
import com.supwisdom.dlpay.api.dao.PaytypeDao;
import com.supwisdom.dlpay.api.domain.TPaytype;
+import com.supwisdom.dlpay.api.domain.TPaytypeConfig;
import com.supwisdom.dlpay.framework.dao.ApiClientDao;
import com.supwisdom.dlpay.framework.dao.BusinessparaDao;
import com.supwisdom.dlpay.framework.dao.SysparaDao;
@@ -12,6 +14,7 @@
import com.supwisdom.dlpay.framework.util.StringUtil;
import com.supwisdom.dlpay.system.service.ParamService;
import com.supwisdom.dlpay.util.ConstantUtil;
+import com.supwisdom.dlpay.util.WebCheckException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
@@ -26,6 +29,7 @@
import javax.persistence.criteria.Root;
import java.util.ArrayList;
import java.util.List;
+import java.util.Map;
@Service
@@ -38,6 +42,8 @@
private ApiClientDao apiClientDao;
@Autowired
private PaytypeDao paytypeDao;
+ @Autowired
+ private PaytypeConfigDao paytypeConfigDao;
@Override
public PageResult<TSyspara> getSysparaPage(Integer paraid, String paraname, int pageNo, int pageSize) {
@@ -152,4 +158,56 @@
return new PageResult<>(paytypeDao.findAll(pageable));
}
+ @Override
+ public TPaytype getPaytype(String paytype) {
+ if (!StringUtil.isEmpty(paytype)) {
+ return paytypeDao.getByPaytype(paytype.trim());
+ }
+ return null;
+ }
+
+ @Override
+ public boolean saveOrUpdatePaytype(TPaytype paytype){
+ if(null!=paytype){
+ paytypeDao.save(paytype);
+ return true;
+ }
+ return false;
+ }
+
+ @Override
+ public boolean deletePaytype(TPaytype paytype){
+ if(null!=paytype){
+ paytypeDao.delete(paytype);
+ return true;
+ }
+ return false;
+ }
+
+ @Override
+ public List<TPaytypeConfig> getPaytypeConfigList(String paytype) {
+ if (!StringUtil.isEmpty(paytype)) {
+ List<TPaytypeConfig> list = paytypeConfigDao.getByPaytype(paytype.trim());
+ if (!StringUtil.isEmpty(list))
+ return list;
+ }
+ return new ArrayList<>(0);
+ }
+
+ @Override
+ public boolean savePaytypeConfig(String paytype, Map<String, String> param) throws WebCheckException {
+ TPaytype tPaytype = getPaytype(paytype);
+ if (null == tPaytype) throw new WebCheckException("支付能力[" + paytype + "]不存在");
+ for (String key : param.keySet()) {
+ String value = param.get(key);
+ TPaytypeConfig config = paytypeConfigDao.getByPaytypeAndAndConfigid(tPaytype.getPaytype(), key);
+ if (null == config) throw new WebCheckException("支付能力[" + tPaytype.getPaytype() + "]不存在配置项[" + key + "],请重新查询");
+ config.setConfigValue(StringUtil.isEmpty(value) ? null : value.trim());
+ paytypeConfigDao.save(config);
+ }
+ return true;
+ }
+
+
+
}
diff --git a/src/main/java/com/supwisdom/dlpay/util/WebCheckException.java b/src/main/java/com/supwisdom/dlpay/util/WebCheckException.java
new file mode 100644
index 0000000..42e72d4
--- /dev/null
+++ b/src/main/java/com/supwisdom/dlpay/util/WebCheckException.java
@@ -0,0 +1,7 @@
+package com.supwisdom.dlpay.util;
+
+public class WebCheckException extends Exception {
+ public WebCheckException(String message) {
+ super(message);
+ }
+}