|
|
@ -18,15 +18,21 @@ |
|
|
|
package com.epmet.service.screen.impl; |
|
|
|
|
|
|
|
import com.epmet.commons.tools.constant.NumConstant; |
|
|
|
import com.epmet.commons.tools.utils.ConvertUtils; |
|
|
|
import com.epmet.commons.tools.utils.Result; |
|
|
|
import com.epmet.constant.CompareConstant; |
|
|
|
import com.epmet.dao.screen.*; |
|
|
|
import com.epmet.dto.screencoll.form.*; |
|
|
|
import com.epmet.entity.screen.ScreenEventImgDataEntity; |
|
|
|
import com.epmet.entity.screen.ScreenUserJoinEntity; |
|
|
|
import com.epmet.service.screen.ScreenCollService; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
import java.math.BigDecimal; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.Calendar; |
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
/** |
|
|
@ -76,14 +82,11 @@ public class ScreenCollServiceImpl implements ScreenCollService { |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public void insertPartyUserRankData(List<PartyUserRankDataFormDTO> formDTO,String customerId) { |
|
|
|
if (null != formDTO && formDTO.size() > NumConstant.ZERO){ |
|
|
|
String[] orgIds = new String[formDTO.size()]; |
|
|
|
for (int i = NumConstant.ZERO; i < formDTO.size(); i++){ |
|
|
|
orgIds[i] = formDTO.get(i).getOrgId(); |
|
|
|
} |
|
|
|
screenPartyUserRankDataDao.deletePartyUserRankData(customerId, |
|
|
|
formDTO.get(NumConstant.ZERO).getYearId(), |
|
|
|
formDTO.get(NumConstant.ZERO).getMonthId(), |
|
|
|
orgIds); |
|
|
|
formDTO.get(NumConstant.ZERO).getGridId(), |
|
|
|
formDTO.get(NumConstant.ZERO).getUserId()); |
|
|
|
} |
|
|
|
|
|
|
|
screenPartyUserRankDataDao.batchInsertPartyUserRankData(formDTO,customerId); |
|
|
|
} |
|
|
@ -309,7 +312,103 @@ public class ScreenCollServiceImpl implements ScreenCollService { |
|
|
|
formDTO.get(NumConstant.ZERO).getMonthId(), |
|
|
|
orgIds); |
|
|
|
|
|
|
|
screenUserJoinDao.batchInsertUserJoin(formDTO, customerId); |
|
|
|
String[] lastMonth = this.lastMonthDate(); |
|
|
|
// 获取上个月的基本数据
|
|
|
|
List<ScreenUserJoinEntity> lastMonthJoinList = screenUserJoinDao.selectLastMonthScreenUserJoinList(customerId, |
|
|
|
lastMonth[NumConstant.ZERO], |
|
|
|
lastMonth[NumConstant.ONE], |
|
|
|
orgIds); |
|
|
|
|
|
|
|
// 定义本月待添加数据的集合
|
|
|
|
List<ScreenUserJoinEntity> curMonthJoinEntityList = new ArrayList<>(); |
|
|
|
// 增加率计算
|
|
|
|
if (null != lastMonthJoinList && lastMonthJoinList.size() > NumConstant.ZERO){ |
|
|
|
// 存在上个月的数据 (本月-上月)/上月 *100
|
|
|
|
for (int i = NumConstant.ZERO; i < formDTO.size(); i++){ |
|
|
|
for (int j = NumConstant.ZERO; j < lastMonthJoinList.size(); j++){ |
|
|
|
if (formDTO.get(i).getOrgId().equals(lastMonthJoinList.get(j).getOrgId())){ |
|
|
|
ScreenUserJoinEntity entity = ConvertUtils.sourceToTarget(formDTO.get(i), ScreenUserJoinEntity.class); |
|
|
|
entity.setJoinTotalUpRate(this.calculateGrowthRateNumber(lastMonthJoinList.get(i).getJoinTotal(), formDTO.get(j).getJoinTotal())); |
|
|
|
entity.setJoinTotalUpFlag(this.calculateGrowthRateFlag(lastMonthJoinList.get(i).getJoinTotal(), formDTO.get(j).getJoinTotal())); |
|
|
|
entity.setAvgIssueUpRate(this.calculateGrowthRateNumber(lastMonthJoinList.get(i).getAvgIssue(), formDTO.get(j).getAvgIssue())); |
|
|
|
entity.setAvgIssueUpFlag(this.calculateGrowthRateFlag(lastMonthJoinList.get(i).getAvgIssue(), formDTO.get(j).getAvgIssue())); |
|
|
|
entity.setAgvgJoinUpRate(this.calculateGrowthRateNumber(lastMonthJoinList.get(i).getAvgJoin(), formDTO.get(j).getAvgJoin())); |
|
|
|
entity.setAgvgJoinUpFlag(this.calculateGrowthRateFlag(lastMonthJoinList.get(i).getAvgJoin(), formDTO.get(j).getAvgJoin())); |
|
|
|
curMonthJoinEntityList.add(entity); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
// 计算增长率后的 待新增数据
|
|
|
|
BigDecimal zero = new BigDecimal(NumConstant.ZERO); |
|
|
|
// 不存在上个月的数据
|
|
|
|
for (int i = NumConstant.ZERO; i < formDTO.size(); i++){ |
|
|
|
ScreenUserJoinEntity entity = ConvertUtils.sourceToTarget(formDTO.get(i), ScreenUserJoinEntity.class); |
|
|
|
entity.setJoinTotalUpRate(zero); |
|
|
|
entity.setJoinTotalUpFlag(""); |
|
|
|
entity.setAvgIssueUpRate(zero); |
|
|
|
entity.setAvgIssueUpFlag(""); |
|
|
|
entity.setAgvgJoinUpRate(zero); |
|
|
|
entity.setAgvgJoinUpFlag(""); |
|
|
|
curMonthJoinEntityList.add(entity); |
|
|
|
} |
|
|
|
} |
|
|
|
screenUserJoinDao.batchInsertUserJoin(curMonthJoinEntityList, customerId); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 获取当前日期的前一个月的日期 |
|
|
|
* @param |
|
|
|
* @return java.lang.String[] |
|
|
|
* @Author zhangyong |
|
|
|
* @Date 15:33 2020-08-21 |
|
|
|
**/ |
|
|
|
private String[] lastMonthDate(){ |
|
|
|
String[] date = new String[NumConstant.TWO]; |
|
|
|
//Java获取当前日期的前一个月的日期
|
|
|
|
Calendar calendar = Calendar.getInstance(); |
|
|
|
calendar.add(Calendar.MONTH, NumConstant.ONE_NEG); |
|
|
|
int year = calendar.get(Calendar.YEAR); |
|
|
|
int month = calendar.get(Calendar.MONTH) + NumConstant.ONE; |
|
|
|
date[NumConstant.ZERO] = String.valueOf(year); |
|
|
|
date[NumConstant.ONE] = String.valueOf(month);; |
|
|
|
if (NumConstant.TEN >= month){ |
|
|
|
date[NumConstant.ONE] = NumConstant.ZERO_STR + month; |
|
|
|
} |
|
|
|
return date; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 计算 本月数值 相较于 上月数值,的增长率 |
|
|
|
* |
|
|
|
* @param old 上月数值 |
|
|
|
* @param now 本月数值 |
|
|
|
* @return java.math.BigDecimal |
|
|
|
* @Author zhangyong |
|
|
|
* @Date 15:38 2020-08-21 |
|
|
|
**/ |
|
|
|
private BigDecimal calculateGrowthRateNumber(Integer old, Integer now){ |
|
|
|
int number = (now - old) / old * NumConstant.ONE_HUNDRED; |
|
|
|
return new BigDecimal(number); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 计算 本月数值 相较于 上月数值,的增长率, 得出标识 |
|
|
|
* |
|
|
|
* @param old 上月数值 |
|
|
|
* @param now 本月数值 |
|
|
|
* @return java.util.String |
|
|
|
* @Author zhangyong |
|
|
|
* @Date 15:38 2020-08-21 |
|
|
|
**/ |
|
|
|
private String calculateGrowthRateFlag(Integer old, Integer now){ |
|
|
|
if (old > now){ |
|
|
|
return CompareConstant.DECR_STR; |
|
|
|
} else if (old < now){ |
|
|
|
return CompareConstant.INCR_STR; |
|
|
|
} else { |
|
|
|
return CompareConstant.EQ_STR; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|