Browse Source

调整分配比例逻辑验证

master
xyiege 4 years ago
parent
commit
f2d07dd744
  1. 5
      src/main/java/cn/chjyj/szwh/controller/BaseController.java
  2. 15
      src/main/java/cn/chjyj/szwh/controller/admin/AdminAccountCloseController.java
  3. 2
      src/main/java/cn/chjyj/szwh/service/AccountCloseService.java
  4. 25
      src/main/java/cn/chjyj/szwh/service/impl/AccountCloseServiceImpl.java

5
src/main/java/cn/chjyj/szwh/controller/BaseController.java

@ -10,6 +10,7 @@ import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.context.request.RequestAttributes; import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder; import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes; import org.springframework.web.context.request.ServletRequestAttributes;
@ -22,7 +23,8 @@ import java.util.Objects;
/** /**
* 基础控制器 * 基础控制器
*/ */
public abstract class BaseController { @Controller
public class BaseController {
public static Log log = LogFactory.getLog(BaseController.class); public static Log log = LogFactory.getLog(BaseController.class);
// jsonobject 全局 // jsonobject 全局
protected JSONObject jsonObject=new JSONObject(); protected JSONObject jsonObject=new JSONObject();
@ -42,6 +44,7 @@ public abstract class BaseController {
HttpServletRequest request = sra.getRequest(); HttpServletRequest request = sra.getRequest();
// 查询请求头中的token // 查询请求头中的token
String token=request.getHeader("token"); String token=request.getHeader("token");
log.info("requet token:"+token);
// 查询头部中的模块 // 查询头部中的模块
final String url=request.getHeader("url"); final String url=request.getHeader("url");
// 提取用户信息 // 提取用户信息

15
src/main/java/cn/chjyj/szwh/controller/admin/AdminAccountCloseController.java

@ -1,9 +1,12 @@
package cn.chjyj.szwh.controller.admin; package cn.chjyj.szwh.controller.admin;
import cn.chjyj.szwh.bean.AccountRatioDetail; import cn.chjyj.szwh.bean.AccountRatioDetail;
import cn.chjyj.szwh.bean.Admin;
import cn.chjyj.szwh.controller.BaseController; import cn.chjyj.szwh.controller.BaseController;
import cn.chjyj.szwh.service.AccountCloseService; import cn.chjyj.szwh.service.AccountCloseService;
import cn.chjyj.szwh.service.AdminService;
import cn.chjyj.szwh.service.UserService; import cn.chjyj.szwh.service.UserService;
import cn.chjyj.szwh.service.impl.AdminServiceImpl;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
@ -25,6 +28,8 @@ public class AdminAccountCloseController extends BaseController {
private AccountCloseService accountCloseService; private AccountCloseService accountCloseService;
@Autowired @Autowired
private UserService userService; private UserService userService;
@Autowired
private AdminService adminService;
/** /**
* 资金结算对账账单列表 * 资金结算对账账单列表
@ -224,9 +229,15 @@ public class AdminAccountCloseController extends BaseController {
JSONObject request = JSONObject.parseObject(sstr); JSONObject request = JSONObject.parseObject(sstr);
//规则名称 //规则名称
String ruleName=request.getString("rule_name"); String ruleName=request.getString("rule_name");
JSONArray ratio = request.getJSONArray("ratio"); JSONArray jsarr = request.getJSONArray("ratio");
List<String> jslist =jsarr.toJavaList(String.class);
// 执行结果 // 执行结果
Map rmap =accountCloseService.setRatio(ruleName,ratio,userid); //查询系统用户编号
String accountId="admin";
Admin admin = adminService.getAdminByAccountId(accountId);
Integer userid=admin.getId();
Map rmap =accountCloseService.doSettRatio(ruleName,jslist,userid);
jsonObject.put("msg",rmap.get("msg")); jsonObject.put("msg",rmap.get("msg"));
jsonObject.put("code",rmap.get("code")); jsonObject.put("code",rmap.get("code"));

2
src/main/java/cn/chjyj/szwh/service/AccountCloseService.java

@ -73,5 +73,5 @@ public interface AccountCloseService {
* @param adminId * @param adminId
* @return * @return
*/ */
Map<String,Object> setRatio(String ruleName, JSONArray jsonArray,int adminId); Map<String,Object> doSettRatio(String ruleName, List<String> jslist,int adminId);
} }

25
src/main/java/cn/chjyj/szwh/service/impl/AccountCloseServiceImpl.java

@ -5,6 +5,7 @@ import cn.chjyj.szwh.bean.*;
import cn.chjyj.szwh.mapper.*; import cn.chjyj.szwh.mapper.*;
import cn.chjyj.szwh.service.AccountCloseService; import cn.chjyj.szwh.service.AccountCloseService;
import cn.chjyj.szwh.vo.SettleVo; import cn.chjyj.szwh.vo.SettleVo;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
@ -282,30 +283,31 @@ public class AccountCloseServiceImpl implements AccountCloseService {
} }
@Override @Override
public Map<String, Object> setRatio(String ruleName, JSONArray jsonArray, int adminId) { public Map<String, Object> doSettRatio(String ruleName, List<String>jslist, int adminId) {
String msg="成功"; String msg="成功";
int code=200; int code=200;
//组装ratioSetting //组装ratioSetting
AccountRatioSetting act = new AccountRatioSetting(); AccountRatioSetting act = new AccountRatioSetting();
// Calendar calendar = Calendar.getInstance();
// Date now = calendar.getTime();
// ? 保存格式是否需要调整
// act.setCreatetime(now);
act.setUserId(adminId); act.setUserId(adminId);
act.setRuleName(ruleName); act.setRuleName(ruleName);
// 保存成功,并返回自编号 // 保存成功,并返回自编号
int actId=accountRatioSettingMapper.addAcrSetting(act); accountRatioSettingMapper.addAcrSetting(act);
// accountRatioDetail // accountRatioDetail
int sumRation=0;// 统计平台放和委托方的结算比例 int sumRation=0;// 统计平台放和委托方的结算比例
for(int i=0;i<jsonArray.size();i++){ if(sumRation!=100){
code=400;
msg="委托方与平台方比例之和未等于100,创建失败";
}
for(int i=0;i<jslist.size();i++){
AccountRatioDetail acrd = new AccountRatioDetail(); AccountRatioDetail acrd = new AccountRatioDetail();
// setting id由上面的返回 // setting id由上面的返回
acrd.setSettingId(act.getId()); acrd.setSettingId(act.getId());
JSONObject tmpjson = (JSONObject) jsonArray.get(i); JSONObject tmpjson = JSON.parseObject(jslist.get(i));
Integer roleType=tmpjson.getInteger("role_type"); Integer roleType=tmpjson.getInteger("role_type");
acrd.setRoleType(roleType); acrd.setRoleType(roleType);
@ -317,18 +319,13 @@ public class AccountCloseServiceImpl implements AccountCloseService {
BigDecimal ratio = new BigDecimal(sratio); BigDecimal ratio = new BigDecimal(sratio);
acrd.setRatio(ratio); acrd.setRatio(ratio);
// 判断处理 // 判断处理
if((roleType==1 || costType==3) && sumRation!=100){ if(roleType==1 || costType==3){
// 仅作整数部分计算 // 仅作整数部分计算
sumRation+=ratio.intValue(); sumRation+=ratio.intValue();
}else{
code=400;
msg="委托方与平台方比例之和未等于100,创建失败";
break; //跳出循环
} }
} }
Integer calculate =tmpjson.getInteger("calculate"); Integer calculate =tmpjson.getInteger("calculate");
acrd.setCalculate(calculate); acrd.setCalculate(calculate);
//金额 //金额

Loading…
Cancel
Save