|
@@ -6,11 +6,19 @@ 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.apache.shiro.SecurityUtils;
|
|
|
+import org.jeecg.common.api.vo.Result;
|
|
|
+import org.jeecg.modules.Index.entity.LreDataInfoVO;
|
|
|
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.jeecg.modules.kyTaskInfo.service.IKyTaskInfoService;
|
|
|
+import org.jeecg.modules.projectCost.entity.ProjectCost;
|
|
|
+import org.jeecg.modules.projectCost.service.IProjectCostService;
|
|
|
+import org.jeecg.modules.system.service.ISysDepartService;
|
|
|
+import org.jeecg.modules.system.service.ISysUserDepartService;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
@@ -19,6 +27,11 @@ import java.math.RoundingMode;
|
|
|
import java.util.*;
|
|
|
import java.util.concurrent.CompletableFuture;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
@Service
|
|
|
public class IndexServiceImpl implements IndexService {
|
|
|
|
|
@@ -39,6 +52,26 @@ public class IndexServiceImpl implements IndexService {
|
|
|
|
|
|
private static final String INCOME_DATA_REDIS_KEY = "incomeDataRedisKey:";
|
|
|
|
|
|
+ /**用户id与部门id对应表*/
|
|
|
+ @Autowired
|
|
|
+ @SuppressWarnings("all")
|
|
|
+ private ISysUserDepartService sysUserDepartService;
|
|
|
+
|
|
|
+ /**部门信息表*/
|
|
|
+ @Autowired
|
|
|
+ @SuppressWarnings("all")
|
|
|
+ private ISysDepartService sysDepartService;
|
|
|
+
|
|
|
+ /**科研任务信息表*/
|
|
|
+ @Autowired
|
|
|
+ @SuppressWarnings("all")
|
|
|
+ private IKyTaskInfoService kyTaskInfoService;
|
|
|
+
|
|
|
+ /**项目成本信息表*/
|
|
|
+ @Autowired
|
|
|
+ @SuppressWarnings("all")
|
|
|
+ private IProjectCostService projectCostService;
|
|
|
+
|
|
|
@Override
|
|
|
public IncomeDataInfoVO getTotalIncome(HttpServletRequest request) {
|
|
|
//首页收入渲染对象
|
|
@@ -204,4 +237,262 @@ public class IndexServiceImpl implements IndexService {
|
|
|
instance.set(Calendar.SECOND, 0);
|
|
|
instance.set(Calendar.MILLISECOND, 0);
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 通过登录的用户找到相应的部门,可能一个或两个
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public List<String> getDepNameBySysUser(){
|
|
|
+ // 获取登录人用户信息 V2.0版本:
|
|
|
+ LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
|
|
|
+ // 获取用户id
|
|
|
+ String userId = sysUser.getId();
|
|
|
+ //根据用户id去找部门id
|
|
|
+ List<String> sysUserDepartIds = sysUserDepartService.getUserDepartIdByUid(userId);
|
|
|
+ System.out.println(sysUserDepartIds);
|
|
|
+ ///根据部门id去找部门名称
|
|
|
+ List<String> sysDepartNames = new ArrayList<>();
|
|
|
+ for(String sysUserDepartId:sysUserDepartIds){
|
|
|
+ sysDepartNames.add(sysDepartService.getDepNameById(sysUserDepartId));
|
|
|
+ }
|
|
|
+ System.out.println(sysDepartNames);
|
|
|
+ return sysDepartNames;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 计算某部门某段时间的利润额
|
|
|
+ *
|
|
|
+ * @return taskNoListNew
|
|
|
+ */
|
|
|
+ public BigDecimal countLre(List<String> taskNoListNew){
|
|
|
+ //3.根据任务号taskno查找需要计算的所有数据list
|
|
|
+ List<ProjectCost> costList = new ArrayList<>();
|
|
|
+ for(String taskNo1:taskNoListNew){
|
|
|
+ costList.addAll(projectCostService.costListByTaskNo(taskNo1));
|
|
|
+ }
|
|
|
+// System.out.println(costList);
|
|
|
+// System.out.println("//////////////////////////////////////////////");
|
|
|
+
|
|
|
+ //4.先计算所有利润额相加和
|
|
|
+ BigDecimal sumLreYear = BigDecimal.ZERO;
|
|
|
+ //5.根据status组批状态去找解组批任务的pcCode
|
|
|
+// List<ProjectCost> costListJZp = new ArrayList<>();
|
|
|
+ List<String> pcCodeList = new ArrayList<>();
|
|
|
+
|
|
|
+ for(ProjectCost projectCost:costList){
|
|
|
+ sumLreYear = sumLreYear.add(projectCost.getLre());
|
|
|
+ if(projectCost.getStatus().equals("1")){
|
|
|
+// costListJZp.add(projectCost);//增添解组批任务列表
|
|
|
+ pcCodeList.add(projectCost.getPccode());//增加解组批任务pcCode用来查找组批任务
|
|
|
+ }
|
|
|
+ }
|
|
|
+// System.out.println("不剔除重复的利润额:");
|
|
|
+// System.out.println(sumLreYear);
|
|
|
+// System.out.println("//////////////////////////////////////////////");
|
|
|
+// System.out.println(costListJZp);
|
|
|
+ //新建一个list来给list中的数据去重 多个解组批任务是同一个pcCode
|
|
|
+ List<String> pcCodeListNew = new ArrayList<>();
|
|
|
+ for(String pcCode:pcCodeList){
|
|
|
+ if (!pcCodeListNew.contains(pcCode)) {
|
|
|
+ pcCodeListNew.add(pcCode);
|
|
|
+ }
|
|
|
+ }
|
|
|
+// System.out.println(pcCodeListNew);
|
|
|
+// System.out.println("//////////////////////////////////////////////");
|
|
|
+
|
|
|
+ //6.根据taskno=pcCode去找组批任务列表
|
|
|
+ List<ProjectCost> costListZp = new ArrayList<>();
|
|
|
+ for(String pcCode2:pcCodeListNew){
|
|
|
+ for(ProjectCost projectCost2:costList){
|
|
|
+ if(projectCost2.getTaskno().equals(pcCode2)){
|
|
|
+ costListZp.add(projectCost2);//增加组批任务列表用来扣除组批任务的利润额
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+// System.out.println(costListZp);
|
|
|
+// System.out.println("//////////////////////////////////////////////");
|
|
|
+
|
|
|
+ //7.根据组批任务的reftaskno去找taskno=reftaskno的组批任务的子任务 lre-组批任务子任务lre
|
|
|
+ //组批任务子任务
|
|
|
+ List<ProjectCost> costListZpZrw = new ArrayList<>();
|
|
|
+ for(ProjectCost projectCost3:costListZp){
|
|
|
+ //lre-组批lre
|
|
|
+ sumLreYear = sumLreYear.subtract(projectCost3.getLre());
|
|
|
+ //根据组批任务的reftaskno去找taskno=reftaskno的组批任务的子任务
|
|
|
+ for(ProjectCost projectCost4:costList){
|
|
|
+ try{
|
|
|
+ if(projectCost3.getTaskno().equals(projectCost4.getReftaskno())){
|
|
|
+ costListZpZrw.add(projectCost4);//增加组批任务子任务
|
|
|
+ }
|
|
|
+ }catch (NullPointerException e){
|
|
|
+ System.out.println("当前数据的reftaskno为null,直接略过即可");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+// System.out.println(costListZpZrw);
|
|
|
+// System.out.println("//////////////////////////////////////////////");
|
|
|
+
|
|
|
+ for(ProjectCost projectCost5:costListZpZrw){
|
|
|
+ //lre-组批子任务lre
|
|
|
+ sumLreYear = sumLreYear.subtract(projectCost5.getLre());
|
|
|
+ }
|
|
|
+ return sumLreYear;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据部门和需要的日期来取任务号tasknolist
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public List<String> getTaskNoListFDepTime(List<String> sysDepartNames, String timeStatus){
|
|
|
+ //获取需要的时间范围
|
|
|
+ //int:0当年范围 1去年同期 2当月 3上个月 4 去年同期月份
|
|
|
+// HashMap<String, Date> timeRangeMap = getTimeRange(0);
|
|
|
+
|
|
|
+ //2.根据部门名称(zrbm、jycs)和实际完成时间(目前是当年)查询taskno
|
|
|
+ List<String> taskNoList = new ArrayList<>();
|
|
|
+ for(String sysDepartName:sysDepartNames){
|
|
|
+ List<String> taskNoList1 = new ArrayList<>();
|
|
|
+ switch (timeStatus){
|
|
|
+ case "0"://当年的所有任务
|
|
|
+ taskNoList1 = kyTaskInfoService.getKyTaskNoByNameCurrYear(sysDepartName);
|
|
|
+ break;
|
|
|
+ case "1"://上一年的所有任务
|
|
|
+ taskNoList1 = kyTaskInfoService.getKyTaskNoByNameLastYear(sysDepartName);
|
|
|
+ break;
|
|
|
+ case "2"://当月的所有任务
|
|
|
+ taskNoList1 = kyTaskInfoService.getKyTaskNoByNameCurrMonth(sysDepartName);
|
|
|
+ break;
|
|
|
+ case "3"://上个月的所有任务
|
|
|
+ taskNoList1 = kyTaskInfoService.getKyTaskNoByNameLastMonth(sysDepartName);
|
|
|
+ break;
|
|
|
+ case "4"://上一年同月的所有任务
|
|
|
+ taskNoList1 = kyTaskInfoService.getKyTaskNoByNameTqMonth(sysDepartName);
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ System.out.println("默认没有任务");
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+// List<String> taskNoList1 = kyTaskInfoService.getKyTaskNoByNameCurrYear(sysDepartName);
|
|
|
+ System.out.println(taskNoList1);
|
|
|
+ taskNoList.addAll(taskNoList1);
|
|
|
+ System.out.println(taskNoList);
|
|
|
+ }
|
|
|
+ //新建一个list来给list中的数据去重 防止责任部门和下达部门都为一个部门,可能会信息重复
|
|
|
+ List<String> taskNoListNew = new ArrayList<>();
|
|
|
+ for(String taskNo:taskNoList){
|
|
|
+ if (!taskNoListNew.contains(taskNo)) {
|
|
|
+ taskNoListNew.add(taskNo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return taskNoListNew;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 计算当年的年总利润额、上一年同期总利润额、年同比增长、当月总利润额、当月同比、当月环比
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Result<LreDataInfoVO> countLre(){
|
|
|
+ BigDecimal initValue = BigDecimal.valueOf(0);
|
|
|
+ LreDataInfoVO lreDataInfoVO = new LreDataInfoVO();
|
|
|
+ lreDataInfoVO.setLreYearTotal(initValue);
|
|
|
+ lreDataInfoVO.setLreYearTq(initValue);
|
|
|
+ lreDataInfoVO.setLreYearTb(initValue);
|
|
|
+ lreDataInfoVO.setLreMonthTotal(initValue);
|
|
|
+ lreDataInfoVO.setLreMonthTb(initValue);
|
|
|
+ lreDataInfoVO.setLreMonthHb(initValue);
|
|
|
+
|
|
|
+ BigDecimal eValue = new BigDecimal("1");
|
|
|
+
|
|
|
+ //1.通过登录的用户找到相应的部门,可能一个或两个
|
|
|
+ List<String> sysDepartNames = getDepNameBySysUser();
|
|
|
+ //2.计算当年的总利润额
|
|
|
+ List<String> taskNoListNew = getTaskNoListFDepTime(sysDepartNames, "0");
|
|
|
+ System.out.println("当年的任务号列表:");
|
|
|
+ System.out.println(taskNoListNew);
|
|
|
+ BigDecimal sumLreYear = countLre(taskNoListNew);
|
|
|
+ System.out.println("当年的利润额为:");
|
|
|
+ System.out.println(sumLreYear);
|
|
|
+ lreDataInfoVO.setLreYearTotal(sumLreYear);
|
|
|
+ System.out.println("----------------------------------------------------");
|
|
|
+
|
|
|
+ //2.计算上一年的总利润额
|
|
|
+ List<String> taskNoListNew2 = getTaskNoListFDepTime(sysDepartNames, "1");
|
|
|
+ System.out.println("上一年的任务号列表:");
|
|
|
+ System.out.println(taskNoListNew2);
|
|
|
+ BigDecimal sumLreLastYear = countLre(taskNoListNew2);
|
|
|
+ System.out.println("上一年的利润额为:");
|
|
|
+ System.out.println(sumLreLastYear);
|
|
|
+ lreDataInfoVO.setLreYearTq(sumLreLastYear);
|
|
|
+ System.out.println("----------------------------------------------------");
|
|
|
+
|
|
|
+ //2.计算年同比增长率
|
|
|
+ try{
|
|
|
+ BigDecimal tbGrowthYear = ((sumLreYear.subtract(sumLreLastYear)).divide(sumLreLastYear, 2, RoundingMode.HALF_UP));
|
|
|
+ lreDataInfoVO.setLreYearTb(tbGrowthYear);
|
|
|
+ System.out.println("年利润同比增长率为:");
|
|
|
+ System.out.println(tbGrowthYear);
|
|
|
+ System.out.println("----------------------------------------------------");
|
|
|
+ }catch (Exception e){
|
|
|
+ lreDataInfoVO.setLreYearTb(eValue);
|
|
|
+ }
|
|
|
+
|
|
|
+ //2.计算当月的总利润额
|
|
|
+ List<String> taskNoListNew3 = getTaskNoListFDepTime(sysDepartNames, "2");
|
|
|
+ System.out.println("当月的任务号列表:");
|
|
|
+ System.out.println(taskNoListNew3);
|
|
|
+ BigDecimal sumLreCurrMonth = countLre(taskNoListNew3);
|
|
|
+ System.out.println("当月的利润额为:");
|
|
|
+ System.out.println(sumLreCurrMonth);
|
|
|
+ lreDataInfoVO.setLreMonthTotal(sumLreCurrMonth);
|
|
|
+ System.out.println("----------------------------------------------------");
|
|
|
+
|
|
|
+ //2.计算上个月的总利润额
|
|
|
+ List<String> taskNoListNew4 = getTaskNoListFDepTime(sysDepartNames, "3");
|
|
|
+ System.out.println("上个月的任务号列表:");
|
|
|
+ System.out.println(taskNoListNew4);
|
|
|
+ BigDecimal sumLreLastMonth = countLre(taskNoListNew4);
|
|
|
+ System.out.println("上个月的利润额为:");
|
|
|
+ System.out.println(sumLreLastMonth);
|
|
|
+ System.out.println("----------------------------------------------------");
|
|
|
+
|
|
|
+ //2.计算月环比增长率
|
|
|
+ try{
|
|
|
+ BigDecimal hbGrowthMonth = ((sumLreCurrMonth.subtract(sumLreLastMonth)).divide(sumLreLastMonth, 2, RoundingMode.HALF_UP));
|
|
|
+ lreDataInfoVO.setLreMonthHb(hbGrowthMonth);
|
|
|
+ System.out.println("月环比为:");
|
|
|
+ System.out.println(hbGrowthMonth);
|
|
|
+ System.out.println("----------------------------------------------------");
|
|
|
+ }catch (Exception e){
|
|
|
+ lreDataInfoVO.setLreMonthHb(eValue);
|
|
|
+ }
|
|
|
+
|
|
|
+ //2.计算去年同期月份的总利润额
|
|
|
+ List<String> taskNoListNew5 = getTaskNoListFDepTime(sysDepartNames, "4");
|
|
|
+ System.out.println("去年同期月份的任务号列表:");
|
|
|
+ System.out.println(taskNoListNew5);
|
|
|
+ BigDecimal sumLreTqMonth = countLre(taskNoListNew5);
|
|
|
+ System.out.println("去年同期月份的利润额为:");
|
|
|
+ System.out.println(sumLreTqMonth);
|
|
|
+ System.out.println("----------------------------------------------------");
|
|
|
+
|
|
|
+ //2.计算月同比增长率
|
|
|
+ try {
|
|
|
+ BigDecimal tbGrowthMonth = ((sumLreCurrMonth.subtract(sumLreTqMonth)).divide(sumLreTqMonth, 2, RoundingMode.HALF_UP));
|
|
|
+ lreDataInfoVO.setLreMonthTb(tbGrowthMonth);
|
|
|
+ System.out.println("月同比为:");
|
|
|
+ System.out.println(tbGrowthMonth);
|
|
|
+ System.out.println("----------------------------------------------------");
|
|
|
+ }catch (Exception e){
|
|
|
+ lreDataInfoVO.setLreMonthTb(eValue);
|
|
|
+ }
|
|
|
+ return Result.OK(lreDataInfoVO);
|
|
|
+ }
|
|
|
+
|
|
|
}
|