叶松
2023-11-28 22cc779aff6d1ff2174e2cd4cfcb64ebe22f698f
hd/pipe/secure/src/main/java/com/thhy/secure/modules/biz/hiddenDanger/service/impl/HiddenDangerServiceImpl.java
@@ -10,15 +10,17 @@
import com.thhy.secure.modules.biz.hiddenDanger.entity.HiddenDangerEntity;
import com.thhy.secure.modules.biz.hiddenDanger.mapper.HiddenDangerMapper;
import com.thhy.secure.modules.biz.hiddenDanger.service.HiddenDangerService;
import com.thhy.secure.modules.biz.integralAccount.entity.IntegralAccountEntity;
import com.thhy.secure.modules.biz.integralAccount.entity.IntegralDetailEntity;
import com.thhy.secure.modules.biz.integralAccount.mapper.IntegralDetailMapper;
import com.thhy.secure.modules.biz.regionInspection.mapper.RegionInspectionRecordMapper;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.*;
/**
 * @Author QiuYuHao
@@ -31,6 +33,11 @@
   @Autowired
   private HiddenDangerMapper hiddenDangerMapper;
   @Autowired
   private IntegralDetailMapper integralDetailMapper;
   @Autowired
   private RegionInspectionRecordMapper regionInspectionRecordMapper;
   private static final Object Lock = new Object();
   @Override
   @Transactional(rollbackFor = Exception.class)
@@ -58,6 +65,9 @@
      SysUserInfo sysUserInfo = UserInfoUtils.getInstance().getUserInfo();
      String userId = sysUserInfo.getUserId();
      hiddenDangerEntity.setUpdateUser(userId);
      if (hiddenDangerEntity.getDictId() != null){
         hiddenDangerEntity.setDangerLocation(hiddenDangerEntity.getDictId());
      }
      hiddenDangerEntity.setUpdateTime(new Date());
      synchronized (Lock){
         hiddenDangerMapper.update(hiddenDangerEntity);
@@ -95,10 +105,14 @@
      }
      PageHelper.startPage(pageNum,pageSize);
      List<HiddenDangerEntity> hiddenDangerEntities = new ArrayList<>();
      if(type == 1){
      if(type == 1){//审核列表
         //小程序 待审核排前面 待审核按时间正序 审核成功的倒叙
         hiddenDangerEntities = hiddenDangerMapper.selectAppList(map);
      }else {
      }else if(type == 2){//隐患举报详情列表
         map.put("createUser",sysUserInfo.getUserId());
         //小程序 待审核排前面 待审核按时间正序 审核成功的倒叙
         hiddenDangerEntities = hiddenDangerMapper.selectPageList(map);
      } else {
         //web 按时间倒序
         hiddenDangerEntities = hiddenDangerMapper.selectPageList(map);
      }
@@ -153,9 +167,56 @@
   }
   @Override
   @Transactional(rollbackFor = Exception.class)
   public BasicResult examine(HiddenDangerEntity hiddenDangerEntity) {
      SysUserInfo sysUserInfo = UserInfoUtils.getInstance().getUserInfo();
      String platUserId = regionInspectionRecordMapper.selectPlatUserId(hiddenDangerEntity.getCreateUser());
      Map platUser = regionInspectionRecordMapper.getPlatUser(platUserId);
      int user_type = (int) platUser.get("user_type");
      Map account = new HashMap();
      account.put("userId",platUserId);
      //查询账户
      IntegralAccountEntity queryAccount = integralDetailMapper.selectByOne(account);
      Double accumulateIntegral = 0.0;
      Double totalIntegral = 0.0;
      if (queryAccount != null){
          accumulateIntegral = queryAccount.getAccumulateIntegral();//累计积分
          totalIntegral = queryAccount.getTotalIntegral();//当前余额
      }
      hiddenDangerEntity.setAuditStatus(1);//1审核通过
      hiddenDangerMapper.update(hiddenDangerEntity);
      hiddenDangerEntity.setDangerLocation(null);
      hiddenDangerEntity.setAuditTime(new Date());
      hiddenDangerEntity.setAuditUser(sysUserInfo.getUserId());
      synchronized (Lock){
         hiddenDangerMapper.update(hiddenDangerEntity);
         IntegralAccountEntity integralAccountEntity = IntegralAccountEntity
               .builder()
               .userId(platUserId)
               .id(UUIDUtils.create())
               .accumulateIntegral(accumulateIntegral+hiddenDangerEntity.getIntegral())
               .totalIntegral(totalIntegral+hiddenDangerEntity.getIntegral())
               .userType(user_type)
               .build();
         IntegralDetailEntity integralDetailEntity = IntegralDetailEntity
               .builder()
               .id(UUIDUtils.create())
               .balanc(totalIntegral+hiddenDangerEntity.getIntegral())
               .integralSource("隐患审核")
               .integralWater(hiddenDangerEntity.getIntegral())
               .createTime(new Date())
               .createUser(sysUserInfo.getUserId())
               .userType(user_type)
               .userId(platUserId)
               .type(1)
               .remark("隐患审核")
               .companyId(sysUserInfo.getCompanyId())
               .build();
         integralDetailMapper.insertAndUpdateAccount(integralAccountEntity);
         integralDetailMapper.insertDetailAndUpdate(integralDetailEntity);
      }
      return BasicResult.success();
   }
}