|
@@ -3,8 +3,15 @@ package com.qmth.themis.business.service.impl;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.qmth.themis.business.dao.TERegionSummaryMapper;
|
|
|
import com.qmth.themis.business.entity.TERegionSummary;
|
|
|
+import com.qmth.themis.business.enums.RegionSummaryEnum;
|
|
|
import com.qmth.themis.business.service.TERegionSummaryService;
|
|
|
+import com.qmth.themis.business.service.ThemisCacheService;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.util.List;
|
|
|
+import java.util.StringJoiner;
|
|
|
|
|
|
/**
|
|
|
* <p>
|
|
@@ -17,4 +24,43 @@ import org.springframework.stereotype.Service;
|
|
|
@Service
|
|
|
public class TERegionSummaryServiceImpl extends ServiceImpl<TERegionSummaryMapper, TERegionSummary> implements TERegionSummaryService {
|
|
|
|
|
|
+ @Resource
|
|
|
+ ThemisCacheService themisCacheService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存地区统计信息
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void regionSummary() {
|
|
|
+ List<TERegionSummary> teRegionSummaryList = this.baseMapper.regionSummary();
|
|
|
+ if (!CollectionUtils.isEmpty(teRegionSummaryList)) {
|
|
|
+ for (TERegionSummary t : teRegionSummaryList) {
|
|
|
+ int count = this.baseMapper.selectRegionSummaryCount(t.getCountry(), t.getProvince());
|
|
|
+ StringJoiner stringJoinerFieldName = new StringJoiner(",");
|
|
|
+ StringJoiner stringJoinerFieldValue = new StringJoiner(",");
|
|
|
+ RegionSummaryEnum[] regionSummaryEnums = RegionSummaryEnum.values();
|
|
|
+ if (count == 0) {
|
|
|
+ for (int i = 0; i < regionSummaryEnums.length; i++) {
|
|
|
+ stringJoinerFieldName.add(regionSummaryEnums[i].getCode());
|
|
|
+ }
|
|
|
+ stringJoinerFieldValue.add("'" + t.getCountry() + "'")
|
|
|
+ .add("'" + t.getProvince() + "'")
|
|
|
+ .add(t.getOnlineCount() + "");
|
|
|
+ this.baseMapper.saveRegionSummary(stringJoinerFieldName.toString(), stringJoinerFieldValue.toString());
|
|
|
+ } else {
|
|
|
+ for (int i = 0; i < regionSummaryEnums.length; i++) {
|
|
|
+ switch (regionSummaryEnums[i]) {
|
|
|
+ case onlineCount:
|
|
|
+ stringJoinerFieldValue.add(regionSummaryEnums[i].getCode() + "=" + t.getOnlineCount());
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ this.baseMapper.updateRegionSummary(t.getCountry(), t.getProvince(), stringJoinerFieldValue.toString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ themisCacheService.updateRegionSummaryCache();
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|