Răsfoiți Sursa

刷新票数

彬彬 4 ani în urmă
părinte
comite
28b2d0fe3d

+ 12 - 0
src/main/java/org/springblade/sing/active/controller/ActiveProductRecordController.java

@@ -246,4 +246,16 @@ public class ActiveProductRecordController extends BladeController {
 		return R.status(activeProductRecordService.deleteLogic(longs));
 		return R.status(activeProductRecordService.deleteLogic(longs));
 	}
 	}
 
 
+	/**
+	 * 刷新票数
+	 */
+	@PostMapping("/editCountByProductId")
+	public R editCountByProductId(Long id){
+		return R.status(activeProductRecordService.editCountById(id));
+	}
+
+	@PostMapping("/editVoteCountByActiveId")
+	public R editVoteCountByActiveId(Long activeId){
+		return R.status(activeProductRecordService.editVoteCountByActiveId(activeId));
+	}
 }
 }

+ 10 - 0
src/main/java/org/springblade/sing/active/mapper/ActiveHelpRecordMapper.java

@@ -24,6 +24,7 @@ import org.springblade.sing.active.vo.ActiveHelpRecordVO;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import java.util.List;
 import java.util.List;
+import java.util.Map;
 
 
 /**
 /**
  * 活动助力记录 Mapper 接口
  * 活动助力记录 Mapper 接口
@@ -53,4 +54,13 @@ public interface ActiveHelpRecordMapper extends BaseMapper<ActiveHelpRecord> {
 	 * 查询投票明细
 	 * 查询投票明细
 	 */
 	 */
 	List<ProductVote> selectVote(Long productId);
 	List<ProductVote> selectVote(Long productId);
+
+	/**
+	 * 查询作品票数
+	 * @param productId
+	 * @return
+	 */
+    Long selectVoteCountByProductId(Long productId);
+
+    List<Map<String,Object>> selectVoteCountByActiveId(Long activeId);
 }
 }

+ 12 - 0
src/main/java/org/springblade/sing/active/mapper/ActiveHelpRecordMapper.xml

@@ -67,4 +67,16 @@
         group by h.ip,h.status order by t_count desc
         group by h.ip,h.status order by t_count desc
     </select>
     </select>
 
 
+    <select id="selectVoteCountByProductId" resultType="Long">
+        select sum(vote_count) from sing_active_help_record where product_id = #{productId} and is_deleted = 0 and status = 1
+    </select>
+
+    <resultMap id="voteCountByIdMap" type="Map">
+        <result column="product_id" property="productId"/>
+        <result column="vote_count" property="voteCount"/>
+    </resultMap>
+
+    <select id="selectVoteCountByActiveId" resultMap="voteCountByIdMap">
+        select product_id,sum(vote_count) vote_count from sing_active_help_record where is_deleted = 0 and status = 1 and active_id = #{activeId} GROUP BY product_id
+    </select>
 </mapper>
 </mapper>

+ 14 - 0
src/main/java/org/springblade/sing/active/service/IActiveProductRecordService.java

@@ -42,4 +42,18 @@ public interface IActiveProductRecordService extends BaseService<ActiveProductRe
 	 * 活动作品数
 	 * 活动作品数
 	 */
 	 */
 	Long selectProductCountByActiveId(Long activeId);
 	Long selectProductCountByActiveId(Long activeId);
+
+	/**
+	 * 更新当个作品票数
+	 * @param id
+	 * @return
+	 */
+	boolean editCountById(Long id);
+
+	/**
+	 * 更新整个活动下作品的票数
+	 * @param activeId
+	 * @return
+	 */
+	boolean editVoteCountByActiveId(Long activeId);
 }
 }

+ 45 - 0
src/main/java/org/springblade/sing/active/service/impl/ActiveProductRecordServiceImpl.java

@@ -16,13 +16,24 @@
  */
  */
 package org.springblade.sing.active.service.impl;
 package org.springblade.sing.active.service.impl;
 
 
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import org.checkerframework.checker.units.qual.A;
+import org.springblade.core.mp.support.Condition;
 import org.springblade.sing.active.entity.ActiveProductRecord;
 import org.springblade.sing.active.entity.ActiveProductRecord;
+import org.springblade.sing.active.mapper.ActiveHelpMapper;
+import org.springblade.sing.active.mapper.ActiveHelpRecordMapper;
+import org.springblade.sing.active.service.IActiveHelpRecordService;
 import org.springblade.sing.active.vo.ActiveProductRecordVO;
 import org.springblade.sing.active.vo.ActiveProductRecordVO;
 import org.springblade.sing.active.mapper.ActiveProductRecordMapper;
 import org.springblade.sing.active.mapper.ActiveProductRecordMapper;
 import org.springblade.sing.active.service.IActiveProductRecordService;
 import org.springblade.sing.active.service.IActiveProductRecordService;
 import org.springblade.core.mp.base.BaseServiceImpl;
 import org.springblade.core.mp.base.BaseServiceImpl;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.core.metadata.IPage;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.util.List;
+import java.util.Map;
 
 
 /**
 /**
  * 活动作品 服务实现类
  * 活动作品 服务实现类
@@ -33,6 +44,9 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
 @Service
 @Service
 public class ActiveProductRecordServiceImpl extends BaseServiceImpl<ActiveProductRecordMapper, ActiveProductRecord> implements IActiveProductRecordService {
 public class ActiveProductRecordServiceImpl extends BaseServiceImpl<ActiveProductRecordMapper, ActiveProductRecord> implements IActiveProductRecordService {
 
 
+	@Autowired
+	private ActiveHelpRecordMapper activeHelpRecordMapper;
+
 	@Override
 	@Override
 	public IPage<ActiveProductRecordVO> selectActiveProductRecordPage(IPage<ActiveProductRecordVO> page, ActiveProductRecordVO activeProductRecord) {
 	public IPage<ActiveProductRecordVO> selectActiveProductRecordPage(IPage<ActiveProductRecordVO> page, ActiveProductRecordVO activeProductRecord) {
 		return page.setRecords(baseMapper.selectActiveProductRecordPage(page, activeProductRecord));
 		return page.setRecords(baseMapper.selectActiveProductRecordPage(page, activeProductRecord));
@@ -43,4 +57,35 @@ public class ActiveProductRecordServiceImpl extends BaseServiceImpl<ActiveProduc
 		return baseMapper.selectProductByActiveId(activeId);
 		return baseMapper.selectProductByActiveId(activeId);
     }
     }
 
 
+	@Override
+	@Transactional
+	public boolean editCountById(Long id) {
+
+		ActiveProductRecord activeProductRecord = baseMapper.selectById(id);
+
+		//查询真实票数
+		Long count = activeHelpRecordMapper.selectVoteCountByProductId(id);
+		activeProductRecord.setVoteCount(count);
+		baseMapper.updateById(activeProductRecord);
+		return true;
+	}
+
+	@Override
+	public boolean editVoteCountByActiveId(Long activeId) {
+
+		List<ActiveProductRecord> activeProductRecords = baseMapper.selectList(new LambdaQueryWrapper<ActiveProductRecord>()
+			.eq(activeId != null, ActiveProductRecord::getActiveId, activeId));
+
+		List<Map<String, Object>> list = activeHelpRecordMapper.selectVoteCountByActiveId(activeId);
+		for (ActiveProductRecord activeProductRecord : activeProductRecords) {
+			for (Map<String, Object> map : list) {
+				if (map.get("productId") == activeProductRecord.getId()){
+					activeProductRecord.setVoteCount((Long)map.get("voteCount"));
+				}
+			}
+		}
+		super.updateBatchById(activeProductRecords);
+		return true;
+	}
+
 }
 }