From 8dbbc5a22b4e7ac0d2576e1fbd0bee3b4dfd26b0 Mon Sep 17 00:00:00 2001 From: 叶松 <2217086471@qq.com> Date: 星期二, 28 十一月 2023 11:28:51 +0800 Subject: [PATCH] Merge branch 'master' of http://111.30.93.211:10101/r/supipe --- hd/pipe/secure/src/main/java/com/thhy/secure/modules/biz/integralAccount/service/impl/IntegralDetailServiceImpl.java | 92 ++++++++++++++++++++++++---------------------- 1 files changed, 48 insertions(+), 44 deletions(-) diff --git a/hd/pipe/secure/src/main/java/com/thhy/secure/modules/biz/integralAccount/service/impl/IntegralDetailServiceImpl.java b/hd/pipe/secure/src/main/java/com/thhy/secure/modules/biz/integralAccount/service/impl/IntegralDetailServiceImpl.java index b4df2b5..fdb0edc 100644 --- a/hd/pipe/secure/src/main/java/com/thhy/secure/modules/biz/integralAccount/service/impl/IntegralDetailServiceImpl.java +++ b/hd/pipe/secure/src/main/java/com/thhy/secure/modules/biz/integralAccount/service/impl/IntegralDetailServiceImpl.java @@ -33,6 +33,7 @@ @Autowired private IntegralDetailMapper integralDetailMapper; + private static final Object Lock= new Object(); /** * 积分超市新增和修改 * @param integralDetailEntity @@ -45,42 +46,44 @@ 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(); } @@ -121,16 +124,17 @@ 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(); } -- Gitblit v1.9.3