From 858d95b05d61f992d4e510a5b44d3f2a9704d29a Mon Sep 17 00:00:00 2001
From: 邱宇豪 <qyh123230312>
Date: 星期二, 28 十一月 2023 09:21:38 +0800
Subject: [PATCH] 20231128_qiuyh_调整积分相关隐患举报

---
 hd/pipe/secure/src/main/resources/mapping/HiddenDangerMapper.xml                                                     |   10 +++
 hd/pipe/secure/src/main/java/com/thhy/secure/modules/biz/integralAccount/service/impl/IntegralDetailServiceImpl.java |   92 ++++++++++++++++--------------
 hd/pipe/secure/src/main/java/com/thhy/secure/modules/biz/hiddenDanger/service/impl/HiddenDangerServiceImpl.java      |   65 +++++++++++++--------
 hd/pipe/secure/src/main/resources/mapping/IntegralDetailMapper.xml                                                   |    1 
 4 files changed, 99 insertions(+), 69 deletions(-)

diff --git a/hd/pipe/secure/src/main/java/com/thhy/secure/modules/biz/hiddenDanger/service/impl/HiddenDangerServiceImpl.java b/hd/pipe/secure/src/main/java/com/thhy/secure/modules/biz/hiddenDanger/service/impl/HiddenDangerServiceImpl.java
index 82cffe1..c6fbf3b 100644
--- a/hd/pipe/secure/src/main/java/com/thhy/secure/modules/biz/hiddenDanger/service/impl/HiddenDangerServiceImpl.java
+++ b/hd/pipe/secure/src/main/java/com/thhy/secure/modules/biz/hiddenDanger/service/impl/HiddenDangerServiceImpl.java
@@ -102,10 +102,20 @@
 		}
 		PageHelper.startPage(pageNum,pageSize);
 		List<HiddenDangerEntity> hiddenDangerEntities = new ArrayList<>();
-		if(type == 1){
+		if(type == 1){//审核列表
+			if (sysUserInfo.getUserType() == 2){
+				map.put("createUser",sysUserInfo.getUserId());
+			}
 			//小程序 待审核排前面 待审核按时间正序 审核成功的倒叙
 			hiddenDangerEntities = hiddenDangerMapper.selectAppList(map);
-		}else {
+		}else if(type == 2){//隐患举报详情列表
+			if (sysUserInfo.getUserType() == 2){
+				map.put("createUser",sysUserInfo.getUserId());
+			}
+			//小程序 待审核排前面 待审核按时间正序 审核成功的倒叙
+			hiddenDangerEntities = hiddenDangerMapper.selectPageList(map);
+		}
+		else {
 			//web 按时间倒序
 			hiddenDangerEntities = hiddenDangerMapper.selectPageList(map);
 		}
@@ -160,12 +170,10 @@
 	}
 
 	@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);
-		Integer user_type = (int)platUser.get("user_type");
 
 		Map account = new HashMap();
 		account.put("userId",platUserId);
@@ -178,27 +186,36 @@
 			 totalIntegral = queryAccount.getTotalIntegral();//当前余额
 		}
 		hiddenDangerEntity.setAuditStatus(1);//1审核通过
-		hiddenDangerMapper.update(hiddenDangerEntity);
-		IntegralAccountEntity integralAccountEntity = IntegralAccountEntity
-				.builder()
-				.userId(platUserId)
-				.accumulateIntegral(accumulateIntegral+hiddenDangerEntity.getIntegral())
-				.totalIntegral(totalIntegral+hiddenDangerEntity.getIntegral())
-				.build();
+		hiddenDangerEntity.setDangerLocation(null);
+		synchronized (Lock){
+			hiddenDangerMapper.update(hiddenDangerEntity);
+			IntegralAccountEntity integralAccountEntity = IntegralAccountEntity
+					.builder()
+					.userId(platUserId)
+					.id(UUIDUtils.create())
+					.accumulateIntegral(accumulateIntegral+hiddenDangerEntity.getIntegral())
+					.totalIntegral(totalIntegral+hiddenDangerEntity.getIntegral())
+					.userType(sysUserInfo.getUserType())
+					.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)
-				.build();
+			IntegralDetailEntity integralDetailEntity = IntegralDetailEntity
+					.builder()
+					.id(UUIDUtils.create())
+					.balanc(totalIntegral+hiddenDangerEntity.getIntegral())
+					.integralSource("隐患审核")
+					.integralWater(hiddenDangerEntity.getIntegral())
+					.createTime(new Date())
+					.createUser(sysUserInfo.getUserId())
+					.userType(sysUserInfo.getUserType())
+					.userId(platUserId)
+					.type(1)
+					.remark("隐患审核")
+					.companyId(sysUserInfo.getCompanyId())
+					.build();
 
-		integralDetailMapper.insertAndUpdateAccount(integralAccountEntity);
-		integralDetailMapper.insertDetailAndUpdate(integralDetailEntity);
+			integralDetailMapper.insertAndUpdateAccount(integralAccountEntity);
+			integralDetailMapper.insertDetailAndUpdate(integralDetailEntity);
+		}
 		return BasicResult.success();
 	}
 }
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();
 	}
 
diff --git a/hd/pipe/secure/src/main/resources/mapping/HiddenDangerMapper.xml b/hd/pipe/secure/src/main/resources/mapping/HiddenDangerMapper.xml
index 39bd177..aec436b 100644
--- a/hd/pipe/secure/src/main/resources/mapping/HiddenDangerMapper.xml
+++ b/hd/pipe/secure/src/main/resources/mapping/HiddenDangerMapper.xml
@@ -149,7 +149,9 @@
                 t.companyId,
                 t.level,
                 t.integral,
-                su.real_name reporter
+                su.real_name reporter,
+                t.integral,
+                t.level
         from t_hidden_danger t
          LEFT JOIN sys_users su ON su.user_id = t.createUser
          LEFT JOIN sys_users su1 ON su1.user_id = t.updateUser
@@ -184,6 +186,9 @@
             <if test="startTime!= null and endTime!=null and startTime != '' and endTime !=''">
                 and t.createTime BETWEEN #{startTime} and #{endTime}
             </if>
+            <if test="createUser!= null and createUser != ''">
+                and t.createUser =#{createUser}
+            </if>
         order by t.createTime desc
     </select>
 
@@ -214,6 +219,9 @@
         <if test="startTime!= null and endTime!=null and startTime != '' and endTime !=''">
             and t.createTime BETWEEN #{startTime} and #{endTime}
         </if>
+        <if test="createUser!= null and createUser != ''">
+            and t.createUser =#{createUser}
+        </if>
         ORDER BY
         t.auditStatus,
         case when t.auditStatus = 0 then t.createTime END,
diff --git a/hd/pipe/secure/src/main/resources/mapping/IntegralDetailMapper.xml b/hd/pipe/secure/src/main/resources/mapping/IntegralDetailMapper.xml
index 268dc7f..fb51580 100644
--- a/hd/pipe/secure/src/main/resources/mapping/IntegralDetailMapper.xml
+++ b/hd/pipe/secure/src/main/resources/mapping/IntegralDetailMapper.xml
@@ -275,6 +275,7 @@
     <if test="startTime != null and startTime != '' and endTime !=null and endTime !=''">
       AND t.createTime BETWEEN #{startTime} and #{endTime}
     </if>
+    order by t.createTime desc
   </select>
   <select id="selectByOne" resultType="com.thhy.secure.modules.biz.integralAccount.entity.IntegralAccountEntity">
     SELECT

--
Gitblit v1.9.3