更新,扣减代理商余额
This commit is contained in:
parent
a2dfc8f1a7
commit
e2b8f3142d
|
@ -1,6 +1,26 @@
|
|||
package com.ruoyi.web.controller.system;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import java.math.BigDecimal;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.ruoyi.common.annotation.Log;
|
||||
|
@ -18,18 +38,8 @@ import com.ruoyi.system.mapper.EtOperatingAreaMapper;
|
|||
import com.ruoyi.system.mapper.EtOrderMapper;
|
||||
import com.ruoyi.system.service.IEtOperatingAreaService;
|
||||
import com.ruoyi.system.service.ISysDeptService;
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.math.BigDecimal;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
|
||||
/**
|
||||
* 运营商信息
|
||||
|
@ -304,4 +314,10 @@ public class SysDeptController extends BaseController
|
|||
return value != null ? value : defaultValue;
|
||||
}
|
||||
|
||||
@Log(title = "增减运营商余额", businessType = BusinessType.UPDATE)
|
||||
@PutMapping("/changeBalance")
|
||||
public AjaxResult changeBalance(Long deptId, BigDecimal amount, String reason)
|
||||
{
|
||||
return toAjax(deptService.changeBalance(deptId, amount, reason));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ spring:
|
|||
# url: jdbc:mysql://47.120.68.19:3306/electripper?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
|
||||
url: jdbc:mysql://47.120.68.19:3306/electripper?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
|
||||
username: root
|
||||
password: 123456
|
||||
password: d0dbe100b71c1d09
|
||||
# url: jdbc:mysql://117.26.179.22:61110/electripper?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
|
||||
# username: root
|
||||
# password: d0dbe100b71c1d09
|
||||
|
|
|
@ -1,105 +0,0 @@
|
|||
import com.ruoyi.RuoYiApplication;
|
||||
import com.ruoyi.common.constant.IotConstants;
|
||||
import com.ruoyi.common.constant.ServiceConstants;
|
||||
import com.ruoyi.common.utils.map.GeoUtils;
|
||||
import com.ruoyi.common.utils.onenet.Token;
|
||||
import com.ruoyi.system.domain.AsDevice;
|
||||
import com.ruoyi.system.domain.EtOperatingArea;
|
||||
import com.ruoyi.system.service.IAsDeviceService;
|
||||
import com.ruoyi.system.service.IEtOperatingAreaService;
|
||||
import com.ruoyi.system.service.ISysConfigService;
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.locationtech.jts.geom.Geometry;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
|
||||
@Slf4j
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = RuoYiApplication.class,webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
||||
public class MainTests {
|
||||
|
||||
@Resource
|
||||
private IAsDeviceService asDeviceService;
|
||||
|
||||
@Autowired
|
||||
private ISysConfigService sysConfigService;
|
||||
|
||||
@Resource
|
||||
private IEtOperatingAreaService etOperatingAreaService;
|
||||
|
||||
@Test
|
||||
@SneakyThrows
|
||||
public void testSelectActivityById() {
|
||||
// 记录开始时间
|
||||
long startTime = System.nanoTime();
|
||||
|
||||
// AsDevice device = asDeviceService.selectAsDeviceByMac("75D30EA71454");
|
||||
// BigDecimal lon = new BigDecimal("120.25709");
|
||||
// BigDecimal lat = new BigDecimal("27.105487");
|
||||
//
|
||||
// EtOperatingArea area = etOperatingAreaService.selectEtOperatingAreaByAreaId(device.getAreaId());
|
||||
// String isAdminUnlocking = device.getIsAdminUnlocking();// 是否是管理员开锁:0-否;1-是
|
||||
//
|
||||
// String nearBoundaryDistanceConfig = sysConfigService.selectConfigByKey("near.boundary.distance");// 靠近运营区边界时的播报距离
|
||||
// log.info("靠近运营区边界时的播报距离==================:" + nearBoundaryDistanceConfig);
|
||||
// double nearBoundaryDistance = Double.parseDouble(nearBoundaryDistanceConfig);
|
||||
// String exceedArea = sysConfigService.selectConfigByKey("exceed.area.distance");// 超出运营区外断电距离
|
||||
// log.info("超出运营区外断电距离================:" + exceedArea);
|
||||
// int exceedDistance = Integer.parseInt(exceedArea);
|
||||
//
|
||||
//
|
||||
// // 创建多边形对象
|
||||
// Geometry polygon = GeoUtils.fromWkt(area.getBoundary());
|
||||
// // 是否在缩短后的运营区边界内
|
||||
// boolean inPolygonWithTolerance = GeoUtils.isInPolygonWithShorten(lon.toString(), lat.toString(), polygon, nearBoundaryDistance);
|
||||
// if(!inPolygonWithTolerance && !isAdminUnlocking.equals("1")){//没有在缩短后的运营区边界内
|
||||
// boolean inPolygonWithTolerance1 = GeoUtils.isInPolygonWithTolerance(lon.toString(), lat.toString(), polygon, 0);// 是否在运营区内
|
||||
// boolean isNearBoundary = GeoUtils.isInPolygonWithTolerance(lon.toString(), lat.toString(), polygon, exceedDistance );
|
||||
// if(inPolygonWithTolerance1){//是否在运营区边界内
|
||||
// // 在靠近运营区边界时发警报
|
||||
// log.info("靠近运营区边界发警告命令--SN:" + device.getSn());
|
||||
// asDeviceService.sendCommand(device.getMac(), Token.getToken(), IotConstants.COMMAND_PLAY2, "靠近运营区边界", null, null);
|
||||
// }else if(isNearBoundary){ // 是否在超出运营区边界多少米内
|
||||
// //在20米范围内,发报警
|
||||
// log.info("超出运营区"+exceedDistance+"米内发送警告命令--SN:" + device.getSn());
|
||||
// asDeviceService.sendCommand(device.getMac(), Token.getToken(), IotConstants.COMMAND_PLAY3, "超出运营区"+exceedDistance+"米内",null,null);
|
||||
// }else{
|
||||
// // 超出运营区外断电
|
||||
// String areaOutOutage = area.getAreaOutOutage();
|
||||
// if (areaOutOutage.equals("1")) { // 超出营运区断电
|
||||
// log.info("超出营运区断电命令--SN:" + device.getSn());
|
||||
// asDeviceService.sendCommand(device.getMac(), Token.getToken(), IotConstants.COMMAND_QLOSE+IotConstants.COMMAND_FREQUENCY_5, "超出营运区断电",null,null);
|
||||
// device.setLockStatus(ServiceConstants.LOCK_STATUS_CLOSE);
|
||||
// int updateAsDevice = asDeviceService.updateAsDevice(device);
|
||||
// if (updateAsDevice > 0) {
|
||||
// log.info("禁行区内断电--更新设备锁状态成功SN:" + device.getSn());
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }else{
|
||||
// log.info("在运营区域内");
|
||||
// }
|
||||
//
|
||||
// // 记录结束时间
|
||||
// long endTime = System.nanoTime();
|
||||
//
|
||||
// // 计算执行时间(以毫秒为单位)
|
||||
// long duration = (endTime - startTime) / 1_000_000;
|
||||
//
|
||||
// // 输出执行时间
|
||||
// System.out.println("Execution time: " + duration + " milliseconds");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -2,7 +2,9 @@ package com.ruoyi.system.mapper;
|
|||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import com.ruoyi.common.core.domain.entity.SysDept;
|
||||
|
||||
/**
|
||||
|
@ -134,7 +136,7 @@ public interface SysDeptMapper
|
|||
*/
|
||||
SysDept selectEtOperatingAreaBySerialNumber(String wechatpaySerial);
|
||||
|
||||
void changeDeptBalance(@Param("amount")BigDecimal amount,@Param("deptId")Long deptId);
|
||||
int changeDeptBalance(@Param("amount")BigDecimal amount,@Param("deptId")Long deptId);
|
||||
|
||||
/**
|
||||
* 获取所有运营商数
|
||||
|
@ -163,4 +165,12 @@ public interface SysDeptMapper
|
|||
*/
|
||||
public int checkDeptExistFeeRule(Long deptId);
|
||||
|
||||
/**
|
||||
* 查询部门余额
|
||||
*
|
||||
* @param deptId 部门ID
|
||||
* @return 结果
|
||||
*/
|
||||
public BigDecimal selectDeptBalanceForUpdate(Long deptId);
|
||||
|
||||
}
|
||||
|
|
|
@ -2,9 +2,9 @@ package com.ruoyi.system.service;
|
|||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
|
||||
import com.ruoyi.common.core.domain.TreeSelect;
|
||||
import com.ruoyi.common.core.domain.entity.SysDept;
|
||||
import com.ruoyi.common.core.domain.entity.SysUser;
|
||||
|
||||
/**
|
||||
* 部门管理 服务层
|
||||
|
@ -200,4 +200,9 @@ public interface ISysDeptService
|
|||
* 所有余额
|
||||
*/
|
||||
BigDecimal selectAllBalance();
|
||||
|
||||
/**
|
||||
* 增减运营商余额
|
||||
*/
|
||||
int changeBalance(Long deptId, BigDecimal amount, String reason);
|
||||
}
|
||||
|
|
|
@ -1,8 +1,21 @@
|
|||
package com.ruoyi.system.service.impl;
|
||||
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.transaction.support.TransactionTemplate;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse;
|
||||
|
@ -17,30 +30,43 @@ import com.ruoyi.common.core.domain.entity.SysRole;
|
|||
import com.ruoyi.common.core.domain.entity.SysUser;
|
||||
import com.ruoyi.common.core.text.Convert;
|
||||
import com.ruoyi.common.exception.ServiceException;
|
||||
import com.ruoyi.common.utils.*;
|
||||
import com.ruoyi.common.utils.DateUtils;
|
||||
import com.ruoyi.common.utils.SecurityUtils;
|
||||
import com.ruoyi.common.utils.SendAliSmsUtil;
|
||||
import com.ruoyi.common.utils.SendSmsVo;
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
import com.ruoyi.common.utils.spring.SpringUtils;
|
||||
import com.ruoyi.common.utils.uuid.IdUtils;
|
||||
import com.ruoyi.system.domain.*;
|
||||
import com.ruoyi.system.mapper.*;
|
||||
import com.ruoyi.system.service.*;
|
||||
import com.wechat.pay.java.service.profitsharing.model.AddReceiverResponse;
|
||||
import com.wechat.pay.java.service.profitsharing.model.DeleteReceiverResponse;
|
||||
import com.ruoyi.system.domain.EtAreaDept;
|
||||
import com.ruoyi.system.domain.EtCapitalFlow;
|
||||
import com.ruoyi.system.domain.EtFeeRule;
|
||||
import com.ruoyi.system.domain.EtModel;
|
||||
import com.ruoyi.system.domain.EtMsgLog;
|
||||
import com.ruoyi.system.domain.EtOperatingArea;
|
||||
import com.ruoyi.system.domain.EtOrder;
|
||||
import com.ruoyi.system.domain.SysUserRole;
|
||||
import com.ruoyi.system.mapper.AsUserMapper;
|
||||
import com.ruoyi.system.mapper.EtAreaDeptMapper;
|
||||
import com.ruoyi.system.mapper.EtCapitalFlowMapper;
|
||||
import com.ruoyi.system.mapper.EtMsgLogMapper;
|
||||
import com.ruoyi.system.mapper.EtOrderMapper;
|
||||
import com.ruoyi.system.mapper.SysDeptMapper;
|
||||
import com.ruoyi.system.mapper.SysRoleMapper;
|
||||
import com.ruoyi.system.mapper.SysUserMapper;
|
||||
import com.ruoyi.system.mapper.SysUserRoleMapper;
|
||||
import com.ruoyi.system.service.CallbackService;
|
||||
import com.ruoyi.system.service.IAsUserService;
|
||||
import com.ruoyi.system.service.IEtFeeRuleService;
|
||||
import com.ruoyi.system.service.IEtModelService;
|
||||
import com.ruoyi.system.service.IEtOperatingAreaService;
|
||||
import com.ruoyi.system.service.ISysConfigService;
|
||||
import com.ruoyi.system.service.ISysDeptService;
|
||||
import com.ruoyi.system.service.IWxPayService;
|
||||
import com.wechat.pay.java.service.transferbatch.model.TransferDetailInput;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.transaction.support.TransactionTemplate;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Collectors;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* 部门管理 服务实现
|
||||
|
@ -117,6 +143,9 @@ public class SysDeptServiceImpl implements ISysDeptService
|
|||
@Resource
|
||||
private EtMsgLogMapper etMsgLogMapper;
|
||||
|
||||
@Autowired
|
||||
private EtOrderMapper etOrderMapper;
|
||||
|
||||
/**
|
||||
* 查询部门管理数据
|
||||
*
|
||||
|
@ -830,4 +859,61 @@ public class SysDeptServiceImpl implements ISysDeptService
|
|||
public int bandAppUser(SysDept dept) {
|
||||
return deptMapper.updateDept(dept);
|
||||
}
|
||||
|
||||
/**
|
||||
* 增减运营商余额
|
||||
*/
|
||||
@Override
|
||||
public int changeBalance(Long deptId, BigDecimal amount, String reason) {
|
||||
if (deptId == null || amount == null) {
|
||||
throw new ServiceException("参数不能为空");
|
||||
}
|
||||
|
||||
SysDept dept = selectDeptById(deptId);
|
||||
if (dept == null) {
|
||||
throw new ServiceException("代理商不存在");
|
||||
}
|
||||
|
||||
EtOrder order = etOrderMapper.selectEtOrderByOrderNo(reason);
|
||||
if (order == null) {
|
||||
throw new ServiceException("订单号为" + reason + "的订单不存在");
|
||||
}
|
||||
|
||||
Integer result = transactionTemplate.execute(status -> {
|
||||
|
||||
// 获取当前余额
|
||||
BigDecimal currentBalance = deptMapper.selectDeptBalanceForUpdate(deptId);
|
||||
if (currentBalance == null) {
|
||||
throw new ServiceException("当前代理商余额为空");
|
||||
}
|
||||
|
||||
// 计算新的余额
|
||||
BigDecimal newBalance = currentBalance.add(amount);
|
||||
|
||||
int rows = deptMapper.changeDeptBalance(amount, deptId);
|
||||
|
||||
if (rows > 0) {
|
||||
EtCapitalFlow etCapitalFlow = new EtCapitalFlow();
|
||||
etCapitalFlow.setOwnerId(deptId);
|
||||
etCapitalFlow.setBusType("a"); // 账变修正
|
||||
etCapitalFlow.setOwner(dept.getDeptName());
|
||||
etCapitalFlow.setOwnerPhone(dept.getPhone());
|
||||
etCapitalFlow.setType(amount.compareTo(BigDecimal.ZERO) > 0 ? ServiceConstants.FLOW_TYPE_INCOME : ServiceConstants.FLOW_TYPE_DISBURSE);
|
||||
etCapitalFlow.setOwnerType(ServiceConstants.OWNER_TYPE_OPERATOR);
|
||||
etCapitalFlow.setStatus(ServiceConstants.FLOW_STATUS_COMPLETE);
|
||||
etCapitalFlow.setHandlingCharge(new BigDecimal(0));
|
||||
etCapitalFlow.setCreateBy(SecurityUtils.getUsername());
|
||||
etCapitalFlow.setCreateTime(DateUtils.getNowDate());
|
||||
etCapitalFlow.setOperatorBalance(newBalance);
|
||||
etCapitalFlow.setOrderNo(reason);
|
||||
etCapitalFlow.setOperatorDividend(amount);
|
||||
etCapitalFlow.setAreaId(order.getAreaId());
|
||||
etCapitalFlowMapper.insertEtCapitalFlow(etCapitalFlow);
|
||||
}
|
||||
|
||||
return rows;
|
||||
});
|
||||
|
||||
return result == null ? 0 : result;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -275,4 +275,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
select COALESCE(SUM(balance), 0) from sys_dept where del_flag = '0'
|
||||
</select>
|
||||
|
||||
<!-- selectDeptBalanceForUpdate -->
|
||||
|
||||
<select id="selectDeptBalanceForUpdate" resultType="java.math.BigDecimal">
|
||||
select balance from sys_dept where dept_id = #{deptId} for update
|
||||
</select>
|
||||
</mapper>
|
||||
|
|
Loading…
Reference in New Issue
Block a user