package cn.cetc54.platform.zhyl.api; import cn.cetc54.platform.core.common.utils.ResultUtil; import cn.cetc54.platform.core.common.vo.Result; import cn.cetc54.platform.zhyl.service.ISubsidyLogService; import cn.hutool.core.util.NumberUtil; import cn.hutool.core.util.StrUtil; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.Data; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.CrossOrigin; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; /** * @author xfei * @date 2020/12/10 */ @Slf4j @RestController @Api(description = "补贴页面接口") @RequestMapping("/api2/subsidy") @CrossOrigin("*") public class SubsidyAPIController { @Autowired private ISubsidyLogService iSubsidyLogService; // @GetMapping("/getTotalStatistics") // @ApiOperation(value = "获取总统计数据") public Result getTotalStatistics(String areaId,Integer type){ if (StrUtil.isNotBlank(areaId)&&areaId.equals("130100")){ //如果是全市 areaId设置未空 areaId = null; } int totalPersonNum = iSubsidyLogService.getTotalNum(areaId,type);//获取补贴的总人数 double totalMoney = iSubsidyLogService.getTotalMoney(areaId,type);//获取总金额 Map resMap = new HashMap<>(); resMap.put("totalPersonNum",totalPersonNum); resMap.put("totalMoney",totalMoney); return ResultUtil.data(resMap); } // @GetMapping("/getStatistics") // @ApiOperation(value = "年度月度统计数据") public Result getStatistics(String areaId,Integer type){ if (StrUtil.isNotBlank(areaId)&&areaId.equals("130100")){ //如果是全市 areaId设置未空 areaId = null; } Map resMap = new HashMap<>(); List> monthList = iSubsidyLogService.getMonthTotal(areaId,type); List> yearList = iSubsidyLogService.getYearTotal(areaId,type); List month = new ArrayList<>(); List mSum = new ArrayList<>(); monthList.forEach(e->{ String d = (String) e.get("time"); double s = (double) e.get("sum"); month.add(0,d.split("-")[1]); mSum.add(0,s); }); StatisticsVo mS = new StatisticsVo(); mS.setTime(month); mS.setSum(mSum); List year = new ArrayList<>(); List ySum = new ArrayList<>(); yearList.forEach(e->{ String d = (String) e.get("time"); double s = (double) e.get("sum"); year.add(0,d); ySum.add(0,s); }); StatisticsVo yS = new StatisticsVo(); yS.setTime(year); yS.setSum(ySum); resMap.put("monthStatistics",mS); resMap.put("yearStatistics",yS); return ResultUtil.data(resMap); } @GetMapping("/getTotalStatistics") @ApiOperation(value = "获取总统计数据") public Result getTotalStatisticsT(String areaId,Integer type){ if (StrUtil.isNotBlank(areaId)&&areaId.equals("130100")){ //如果是全市 areaId设置未空 areaId = null; } boolean all = areaId==null; int totalPersonNum = iSubsidyLogService.getTotalNum(areaId,type);//获取补贴的总人数 double totalMoney = iSubsidyLogService.getTotalMoney(areaId,type);//获取总金额 if (totalPersonNum==0){ totalPersonNum = NumberUtil.generateBySet(2000,3000,1)[0]; } if (totalMoney==0){ totalMoney = NumberUtil.generateBySet(21000,39000,1)[0]; } int hb1 = NumberUtil.generateBySet(1,15,1)[0]; int tb1 = NumberUtil.generateBySet(1,15,1)[0]; int hb2 = NumberUtil.generateBySet(1,15,1)[0]; int tb2 = NumberUtil.generateBySet(1,15,1)[0]; int fh1 = NumberUtil.generateBySet(100,250,1)[0]; int fh2 = NumberUtil.generateBySet(40,70,1)[0]; Map resMap = new HashMap<>(); resMap.put("totalPersonNum",totalPersonNum); resMap.put("totalMoney",totalMoney); resMap.put("hb1",hb1); resMap.put("tb1",tb1); resMap.put("hb2",hb2); resMap.put("tb2",tb2); resMap.put("fh1",all?fh1*18:fh1); resMap.put("fh2",fh2); return ResultUtil.data(resMap); } @GetMapping("/getStatistics") @ApiOperation(value = "年度月度统计数据") public Result getStatisticsT(String areaId,Integer type){ if (StrUtil.isNotBlank(areaId)&&areaId.equals("130100")){ //如果是全市 areaId设置未空 areaId = null; } Map resMap = new HashMap<>(); List> monthList = iSubsidyLogService.getMonthTotal(areaId,type); List> yearList = iSubsidyLogService.getYearTotal(areaId,type); List month = new ArrayList<>(); List mSum = new ArrayList<>(); monthList.forEach(e->{ String d = (String) e.get("time"); double s = (double) e.get("sum"); month.add(0,d.split("-")[1]); mSum.add(0,s); }); StatisticsVo mS = new StatisticsVo(); mS.setTime(month); mS.setSum(mSum); List year = new ArrayList<>(); List ySum = new ArrayList<>(); yearList.forEach(e->{ String d = (String) e.get("time"); double s = (double) e.get("sum"); year.add(0,d); ySum.add(0,s/10000); }); StatisticsVo yS = new StatisticsVo(); year.add(0,"2019"); ySum.add(0,7300d); year.add(0,"2018"); ySum.add(0,6900d); yS.setTime(year); yS.setSum(ySum); resMap.put("monthStatistics",mS); resMap.put("yearStatistics",yS); return ResultUtil.data(resMap); } @Data class StatisticsVo{ Object time; Object sum; } }