| | |
| | | @Autowired |
| | | private IntegralDetailMapper integralDetailMapper; |
| | | |
| | | private static final Object Lock= new Object(); |
| | | /** |
| | | * 积分超市新增和修改 |
| | | * @param integralDetailEntity |
| | |
| | | String sysUserId = sysUserInfo.getUserId(); |
| | | String companyId = sysUserInfo.getCompanyId(); |
| | | //扣积分逻辑 |
| | | IntegralAccountEntity integralAccountEntity = IntegralAccountEntity |
| | | .builder() |
| | | .userId(integralDetailEntity.getUserId()) |
| | | .updateUser(sysUserId) |
| | | .updateTime(new Date()) |
| | | .id(UUIDUtils.create()) |
| | | .build(); |
| | | Map map = new HashMap(); |
| | | map.put("userId",integralDetailEntity.getUserId()); |
| | | //查询账户 |
| | | IntegralAccountEntity queryAccount = integralDetailMapper.selectByOne(map); |
| | | if(queryAccount == null || queryAccount.getTotalIntegral()<integralDetailEntity.getIntegralWater()){//无账户 |
| | | return BasicResult.faild("500","积分不足,无法扣除积分",null); |
| | | } |
| | | //有账户 |
| | | Double totalConsumption = queryAccount.getTotalConsumption();//总消耗 |
| | | Double accumulateIntegral = queryAccount.getAccumulateIntegral();//累计积分 |
| | | Double totalIntegral = queryAccount.getTotalIntegral();//当前余额 |
| | | synchronized (Lock){ |
| | | IntegralAccountEntity integralAccountEntity = IntegralAccountEntity |
| | | .builder() |
| | | .userId(integralDetailEntity.getUserId()) |
| | | .updateUser(sysUserId) |
| | | .updateTime(new Date()) |
| | | .id(UUIDUtils.create()) |
| | | .build(); |
| | | Map map = new HashMap(); |
| | | map.put("userId",integralDetailEntity.getUserId()); |
| | | //查询账户 |
| | | IntegralAccountEntity queryAccount = integralDetailMapper.selectByOne(map); |
| | | if(queryAccount == null || queryAccount.getTotalIntegral()<integralDetailEntity.getIntegralWater()){//无账户 |
| | | return BasicResult.faild("500","积分不足,无法扣除积分",null); |
| | | } |
| | | //有账户 |
| | | Double totalConsumption = queryAccount.getTotalConsumption();//总消耗 |
| | | Double accumulateIntegral = queryAccount.getAccumulateIntegral();//累计积分 |
| | | Double totalIntegral = queryAccount.getTotalIntegral();//当前余额 |
| | | |
| | | integralAccountEntity.setTotalIntegral(totalIntegral-integralDetailEntity.getIntegralWater()); |
| | | integralAccountEntity.setAccumulateIntegral(accumulateIntegral); |
| | | integralAccountEntity.setTotalConsumption(totalConsumption+integralDetailEntity.getIntegralWater()); |
| | | //修改账户 |
| | | integralDetailMapper.insertAndUpdateAccount(integralAccountEntity); |
| | | if(id == null){ |
| | | integralDetailEntity.setCompanyId(companyId); |
| | | integralDetailEntity.setId(UUIDUtils.create()); |
| | | integralDetailEntity.setCreateTime(new Date()); |
| | | integralDetailEntity.setCreateUser(sysUserId); |
| | | } |
| | | integralDetailEntity.setBalanc(totalIntegral-integralDetailEntity.getIntegralWater());//拿到当前余额 |
| | | integralAccountEntity.setTotalIntegral(totalIntegral-integralDetailEntity.getIntegralWater()); |
| | | integralAccountEntity.setAccumulateIntegral(accumulateIntegral); |
| | | integralAccountEntity.setTotalConsumption(totalConsumption+integralDetailEntity.getIntegralWater()); |
| | | //修改账户 |
| | | integralDetailMapper.insertAndUpdateAccount(integralAccountEntity); |
| | | if(id == null){ |
| | | integralDetailEntity.setCompanyId(companyId); |
| | | integralDetailEntity.setId(UUIDUtils.create()); |
| | | integralDetailEntity.setCreateTime(new Date()); |
| | | integralDetailEntity.setCreateUser(sysUserId); |
| | | } |
| | | integralDetailEntity.setBalanc(totalIntegral-integralDetailEntity.getIntegralWater());//拿到当前余额 |
| | | |
| | | integralDetailEntity.setType(2); |
| | | integralDetailEntity.setIntegralSource("积分超市"); |
| | | //添加或修改明细 |
| | | integralDetailMapper.insertDetailAndUpdate(integralDetailEntity); |
| | | integralDetailEntity.setType(2); |
| | | integralDetailEntity.setIntegralSource("积分超市"); |
| | | //添加或修改明细 |
| | | integralDetailMapper.insertDetailAndUpdate(integralDetailEntity); |
| | | } |
| | | return BasicResult.success(); |
| | | } |
| | | |
| | |
| | | Double totalConsumption = queryAccount.getTotalConsumption();//总消耗 |
| | | Double accumulateIntegral = queryAccount.getAccumulateIntegral();//累计积分 |
| | | Double totalIntegral = queryAccount.getTotalIntegral();//当前余额 |
| | | |
| | | IntegralAccountEntity integralAccountEntity = IntegralAccountEntity |
| | | .builder() |
| | | .userId(integralDetailEntity.getUserId()) |
| | | .totalConsumption(totalConsumption - integralWater) |
| | | .accumulateIntegral(accumulateIntegral + integralWater) |
| | | .totalIntegral(totalIntegral + integralWater) |
| | | .build(); |
| | | integralDetailMapper.insertAndUpdateAccount(integralAccountEntity); |
| | | integralDetailMapper.delete(id); |
| | | synchronized (Lock){ |
| | | IntegralAccountEntity integralAccountEntity = IntegralAccountEntity |
| | | .builder() |
| | | .userId(integralDetailEntity.getUserId()) |
| | | .totalConsumption(totalConsumption - integralWater) |
| | | .accumulateIntegral(accumulateIntegral + integralWater) |
| | | .totalIntegral(totalIntegral + integralWater) |
| | | .build(); |
| | | integralDetailMapper.insertAndUpdateAccount(integralAccountEntity); |
| | | integralDetailMapper.delete(id); |
| | | } |
| | | return BasicResult.success(); |
| | | } |
| | | |