| | |
| | | import com.thhy.general.utils.UUIDUtils; |
| | | import com.thhy.general.utils.UserInfoUtils; |
| | | import com.thhy.secure.modules.biz.integralAccount.entity.IntegralAccountEntity; |
| | | import com.thhy.secure.modules.biz.integralAccount.entity.IntegralDetailDto; |
| | | import com.thhy.secure.modules.biz.integralAccount.entity.IntegralDetailEntity; |
| | | import com.thhy.secure.modules.biz.integralAccount.mapper.IntegralDetailMapper; |
| | | import com.thhy.secure.modules.biz.integralAccount.service.IntegralDetailService; |
| | |
| | | @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(); |
| | | } |
| | | |
| | |
| | | public BasicResult delete(String id){ |
| | | Map map =new HashMap(); |
| | | map.put("id",id); |
| | | IntegralDetailEntity integralDetailEntity = integralDetailMapper.selectSafeIntegralInfo(map).get(0); |
| | | IntegralDetailDto integralDetailEntity = integralDetailMapper.selectSafeIntegralInfo(map).get(0); |
| | | Double integralWater = integralDetailEntity.getIntegralWater();//获取消耗积分 |
| | | Map account = new HashMap(); |
| | | account.put("userId",integralDetailEntity.getUserId()); |
| | |
| | | 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(); |
| | | } |
| | | |
| | |
| | | int pageSize = (int) map.get("pageSize"); |
| | | PageHelper.startPage(pageNum,pageSize); |
| | | map.put("companyId",companyId); |
| | | List<IntegralDetailEntity> integralDetailEntities = integralDetailMapper.selectSafeIntegralInfo(map); |
| | | List<IntegralDetailDto> integralDetailEntities = integralDetailMapper.selectSafeIntegralInfo(map); |
| | | map.put("data",new PageInfo<>(integralDetailEntities)); |
| | | return BasicResult.success(map); |
| | | } |
| | |
| | | map.put("companyId",companyId); |
| | | List<IntegralDetailEntity> integralDetailEntities = integralDetailMapper.selectPageList(map); |
| | | |
| | | integralDetailEntities.forEach(obj->{ |
| | | if(obj.getUserType() ==1){ |
| | | obj.setUserTypeName("管服人员"); |
| | | } |
| | | if(obj.getUserType() ==2){ |
| | | obj.setUserTypeName("劳务人员"); |
| | | } |
| | | }); |
| | | ExcelUtils.downExcel(integralDetailEntities,IntegralDetailEntity.class,rsp,"班组列表"); |
| | | } |
| | | |
| | |
| | | public void exportSafeIntegralInfo(Map map, HttpServletResponse rsp) { |
| | | SysUserInfo sysUserInfo = UserInfoUtils.getInstance().getUserInfo(); |
| | | String companyId = sysUserInfo.getCompanyId(); |
| | | |
| | | IntegralAccountEntity integralAccountEntity = integralDetailMapper.selectByOne(map); |
| | | map.put("integral",integralAccountEntity.getTotalIntegral()); |
| | | map.put("companyId",companyId); |
| | | List<IntegralDetailEntity> integralDetailEntities = integralDetailMapper.selectSafeIntegralInfo(map); |
| | | ExcelUtils.downExcel(integralDetailEntities,IntegralDetailEntity.class,rsp,"班组列表"); |
| | | List<IntegralDetailDto> integralDetailEntities = integralDetailMapper.selectSafeIntegralInfo(map); |
| | | integralDetailEntities.forEach(obj->{ |
| | | if(obj.getUserType() ==1){ |
| | | obj.setUserTypeName("管服人员"); |
| | | } |
| | | if(obj.getUserType() ==2){ |
| | | obj.setUserTypeName("劳务人员"); |
| | | } |
| | | if(obj.getType() == 1){ |
| | | obj.setTypeName("获取"); |
| | | } |
| | | if(obj.getType() == 2){ |
| | | obj.setTypeName("消耗"); |
| | | } |
| | | }); |
| | | ExcelUtils.downExcel(integralDetailEntities,IntegralDetailDto.class,rsp,"班组列表"); |
| | | } |
| | | |
| | | } |