|
@@ -1,8 +1,212 @@
|
|
|
package org.jeecg.modules.Index.service.impl;
|
|
|
|
|
|
+import org.apache.commons.lang3.ObjectUtils;
|
|
|
+import org.jeecg.common.system.api.ISysBaseAPI;
|
|
|
+import org.jeecg.common.system.util.JwtUtil;
|
|
|
+import org.jeecg.common.system.vo.LoginUser;
|
|
|
+import org.jeecg.common.util.RedisUtil;
|
|
|
+import org.jeecg.modules.Index.entity.IncomeDataInfoVO;
|
|
|
+import org.jeecg.modules.Index.mapper.IndexMapper;
|
|
|
import org.jeecg.modules.Index.service.IndexService;
|
|
|
+import org.jeecg.modules.projectCost.mapper.ProjectCostMapper;
|
|
|
+import org.jeecg.modules.system.mapper.SysDepartMapper;
|
|
|
+import org.jeecg.modules.xmcbDetail.mapper.ComContractInfoExchangeMapper;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.math.RoundingMode;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.*;
|
|
|
+import java.util.concurrent.CompletableFuture;
|
|
|
+
|
|
|
@Service
|
|
|
public class IndexServiceImpl implements IndexService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IndexMapper indexMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ISysBaseAPI sysBaseApi;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private SysDepartMapper sysDepartMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ProjectCostMapper projectCostMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ComContractInfoExchangeMapper exchangeMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private RedisUtil redisUtil;
|
|
|
+
|
|
|
+ private static final String INCOME_DATA_REDIS_KEY = "incomeDataRedisKey:";
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public IncomeDataInfoVO getTotalIncome(HttpServletRequest request) {
|
|
|
+ //首页收入渲染对象
|
|
|
+ BigDecimal initValue = BigDecimal.valueOf(0);
|
|
|
+ IncomeDataInfoVO incomeDataInfoVO = new IncomeDataInfoVO();
|
|
|
+ incomeDataInfoVO.setIncomeYearTotal(initValue);
|
|
|
+ incomeDataInfoVO.setIncomeYearTq(initValue);
|
|
|
+ incomeDataInfoVO.setIncomeYearTb(initValue);
|
|
|
+ incomeDataInfoVO.setIncomeMonthTotal(initValue);
|
|
|
+ incomeDataInfoVO.setIncomeMonthHb(initValue);
|
|
|
+ incomeDataInfoVO.setIncomeMonthTb(initValue);
|
|
|
+
|
|
|
+ String userNameByToken = JwtUtil.getUserNameByToken(request);
|
|
|
+ LoginUser sysUser = sysBaseApi.getUserByName(userNameByToken);
|
|
|
+
|
|
|
+ List<String> departNames = sysDepartMapper.getSysUserOfDepartNameList(sysUser.getId());
|
|
|
+ if (departNames.isEmpty()) return incomeDataInfoVO;
|
|
|
+
|
|
|
+ StringBuilder stringBuilder = new StringBuilder();
|
|
|
+ for (String departName : departNames) {
|
|
|
+ stringBuilder.append(departName).append("|");
|
|
|
+ }
|
|
|
+ String depart = stringBuilder.toString();
|
|
|
+ IncomeDataInfoVO cacheObject = (IncomeDataInfoVO)redisUtil.get(INCOME_DATA_REDIS_KEY + depart);
|
|
|
+ if (ObjectUtils.isNotEmpty(cacheObject)) {
|
|
|
+ incomeDataInfoVO = cacheObject;
|
|
|
+ return incomeDataInfoVO;
|
|
|
+ }
|
|
|
+
|
|
|
+ ArrayList<String> tasknoList = new ArrayList<>();
|
|
|
+ List<String> ZrbmTasknoList = projectCostMapper.queryZrbmTasknoListbydepartNames(departNames);
|
|
|
+ List<String> XdbmTasknoList = projectCostMapper.queryXdbmTasknoListbydepartNames(departNames);
|
|
|
+ tasknoList.addAll(ZrbmTasknoList);
|
|
|
+ tasknoList.addAll(XdbmTasknoList);
|
|
|
+ if (tasknoList.isEmpty()) return incomeDataInfoVO;
|
|
|
+
|
|
|
+
|
|
|
+ Calendar instance = Calendar.getInstance();
|
|
|
+
|
|
|
+ Date currentYearEndDate = instance.getTime();
|
|
|
+ setZeroYear(instance);
|
|
|
+ Date currentYearBeginDate = instance.getTime();
|
|
|
+
|
|
|
+ List<BigDecimal> currentYearIncomeList = new ArrayList<>();
|
|
|
+ IncomeDataInfoVO finalIncomeDataInfoVO = incomeDataInfoVO;
|
|
|
+ CompletableFuture.runAsync(() -> {
|
|
|
+ //根据年份和当前部门对应的任务号查询,部门当前年的年收入
|
|
|
+ BigDecimal currentYearTotal = exchangeMapper.getIncomeYearTotalByTasknoListAndByQsrqRange(tasknoList, currentYearBeginDate, currentYearEndDate);
|
|
|
+ if (ObjectUtils.isEmpty(currentYearTotal)) currentYearTotal = BigDecimal.valueOf(0);
|
|
|
+ finalIncomeDataInfoVO.setIncomeYearTotal(currentYearTotal);
|
|
|
+ currentYearIncomeList.add(currentYearTotal);
|
|
|
+ }).join();
|
|
|
+
|
|
|
+ instance.setTime(new Date());
|
|
|
+ instance.add(Calendar.YEAR, -1);
|
|
|
+ //去年的今日
|
|
|
+ Date LastTqEndDate = instance.getTime();
|
|
|
+ setZeroYear(instance);
|
|
|
+ Date LastYearBeginDate = instance.getTime();
|
|
|
+
|
|
|
+ ArrayList<BigDecimal> lastYearTqIncomeList = new ArrayList<>();
|
|
|
+ //根据年份和当前部门对应的任务号查询,部门去年同期年收入
|
|
|
+ CompletableFuture.runAsync(() -> {
|
|
|
+ BigDecimal lastYearTqTotal = exchangeMapper.getIncomeYearTotalByTasknoListAndByQsrqRange(tasknoList, LastYearBeginDate, LastTqEndDate);
|
|
|
+ if (ObjectUtils.isEmpty(lastYearTqTotal)) lastYearTqTotal = BigDecimal.valueOf(0);
|
|
|
+ finalIncomeDataInfoVO.setIncomeYearTq(lastYearTqTotal);
|
|
|
+ lastYearTqIncomeList.add(lastYearTqTotal);
|
|
|
+ }).join();
|
|
|
+
|
|
|
+
|
|
|
+ instance.setTime(new Date());
|
|
|
+ Date currentMothEndDate = instance.getTime();
|
|
|
+ setZeroMonth(instance);
|
|
|
+ Date currentMothBginDate = instance.getTime();
|
|
|
+
|
|
|
+ ArrayList<BigDecimal> currentMonthTotalList = new ArrayList<>();
|
|
|
+
|
|
|
+ CompletableFuture.runAsync(() -> {
|
|
|
+ BigDecimal currentMonthTotal = exchangeMapper.getIncomeYearTotalByTasknoListAndByQsrqRange(tasknoList, currentMothBginDate, currentMothEndDate);
|
|
|
+ if (ObjectUtils.isEmpty(currentMonthTotal)) currentMonthTotal = BigDecimal.valueOf(0);
|
|
|
+ finalIncomeDataInfoVO.setIncomeMonthTotal(currentMonthTotal);
|
|
|
+ currentMonthTotalList.add(currentMonthTotal);
|
|
|
+ }).join();
|
|
|
+
|
|
|
+
|
|
|
+ instance.setTime(new Date());
|
|
|
+ instance.add(Calendar.MONTH, -1);
|
|
|
+ Date LastMothTqEndDate = instance.getTime();
|
|
|
+ setZeroMonth(instance);
|
|
|
+ Date LastMothTqBeginDate = instance.getTime();
|
|
|
+
|
|
|
+ ArrayList<BigDecimal> lastMothTqTotalList = new ArrayList<>();
|
|
|
+ CompletableFuture.runAsync(() -> {
|
|
|
+ BigDecimal lastMothTqTotal = exchangeMapper.getIncomeYearTotalByTasknoListAndByQsrqRange(tasknoList, LastMothTqBeginDate, LastMothTqEndDate);
|
|
|
+ if (ObjectUtils.isEmpty(lastMothTqTotal)) lastMothTqTotal = BigDecimal.valueOf(0);
|
|
|
+ lastMothTqTotalList.add(lastMothTqTotal);
|
|
|
+ }).join();
|
|
|
+
|
|
|
+
|
|
|
+ instance.setTime(new Date());
|
|
|
+ instance.add(Calendar.YEAR, -1);
|
|
|
+ Date lastYearMonthTqEndDate = instance.getTime();
|
|
|
+ setZeroMonth(instance);
|
|
|
+ Date lastYearMonthTqBeginDate = instance.getTime();
|
|
|
+
|
|
|
+ ArrayList<BigDecimal> lastYearMonthTqTotalList = new ArrayList<>();
|
|
|
+ CompletableFuture.runAsync(() -> {
|
|
|
+ BigDecimal lastYearMonthTqTotal = exchangeMapper.getIncomeYearTotalByTasknoListAndByQsrqRange(tasknoList, lastYearMonthTqBeginDate, lastYearMonthTqEndDate);
|
|
|
+ if (ObjectUtils.isEmpty(lastYearMonthTqTotal)) lastYearMonthTqTotal = BigDecimal.valueOf(0);
|
|
|
+ lastYearMonthTqTotalList.add(lastYearMonthTqTotal);
|
|
|
+ }).join();
|
|
|
+
|
|
|
+
|
|
|
+ CompletableFuture.runAsync(() -> {
|
|
|
+ BigDecimal currentYearTotal = currentYearIncomeList.get(0);
|
|
|
+ BigDecimal lastYearTqTotal = lastYearTqIncomeList.get(0);
|
|
|
+ //去年同比
|
|
|
+ BigDecimal YearDifference = currentYearTotal.subtract(lastYearTqTotal);
|
|
|
+ BigDecimal incomeYearTb = BigDecimal.valueOf(0);
|
|
|
+ if (lastYearTqTotal.compareTo(BigDecimal.valueOf(0)) != 0)
|
|
|
+ incomeYearTb = YearDifference.divide(lastYearTqTotal, 2, RoundingMode.HALF_UP);
|
|
|
+ finalIncomeDataInfoVO.setIncomeYearTb(incomeYearTb);
|
|
|
+ }).join();
|
|
|
+
|
|
|
+ CompletableFuture.runAsync(() -> {
|
|
|
+ BigDecimal currentMonthTotal = currentMonthTotalList.get(0);
|
|
|
+ BigDecimal lastMothTqTotal = lastMothTqTotalList.get(0);
|
|
|
+ BigDecimal MothDifference = currentMonthTotal.subtract(lastMothTqTotal);
|
|
|
+ BigDecimal incomeMothHb = BigDecimal.valueOf(0);
|
|
|
+ if (lastMothTqTotal.compareTo(BigDecimal.valueOf(0)) != 0)
|
|
|
+ incomeMothHb = MothDifference.divide(lastMothTqTotal, 2, RoundingMode.HALF_UP);
|
|
|
+ finalIncomeDataInfoVO.setIncomeMonthHb(incomeMothHb);
|
|
|
+ }).join();
|
|
|
+
|
|
|
+ CompletableFuture.runAsync(() -> {
|
|
|
+ BigDecimal currentMonthTotal = currentMonthTotalList.get(0);
|
|
|
+ BigDecimal lastYearMonthTqTotal = lastYearMonthTqTotalList.get(0);
|
|
|
+ BigDecimal yearMothDifference = currentMonthTotal.subtract(lastYearMonthTqTotal);
|
|
|
+ BigDecimal incomeYearMothTb = BigDecimal.valueOf(0);
|
|
|
+ if (lastYearMonthTqTotal.compareTo(BigDecimal.valueOf(0)) != 0)
|
|
|
+ incomeYearMothTb = yearMothDifference.divide(lastYearMonthTqTotal, 2, RoundingMode.HALF_UP);
|
|
|
+ finalIncomeDataInfoVO.setIncomeMonthTb(incomeYearMothTb);
|
|
|
+ }).join();
|
|
|
+
|
|
|
+ redisUtil.set(INCOME_DATA_REDIS_KEY + depart, finalIncomeDataInfoVO, 1000L * 60 * 60 * 2);
|
|
|
+
|
|
|
+ return finalIncomeDataInfoVO;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setZeroYear(Calendar instance) {
|
|
|
+ instance.set(Calendar.MONTH, 0);
|
|
|
+ instance.set(Calendar.DAY_OF_MONTH, 0);
|
|
|
+ instance.set(Calendar.HOUR_OF_DAY, 0);
|
|
|
+ instance.set(Calendar.MINUTE, 0);
|
|
|
+ instance.set(Calendar.SECOND, 0);
|
|
|
+ instance.set(Calendar.MILLISECOND, 0);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setZeroMonth(Calendar instance) {
|
|
|
+ instance.set(Calendar.DAY_OF_MONTH, 0);
|
|
|
+ instance.set(Calendar.HOUR_OF_DAY, 0);
|
|
|
+ instance.set(Calendar.MINUTE, 0);
|
|
|
+ instance.set(Calendar.SECOND, 0);
|
|
|
+ instance.set(Calendar.MILLISECOND, 0);
|
|
|
+ }
|
|
|
}
|