您的位置:首页 > 新闻 > 会展 > 广州社交软件app开发_前端网页制作_电商运营培训_聚名网

广州社交软件app开发_前端网页制作_电商运营培训_聚名网

2025/5/10 1:44:46 来源:https://blog.csdn.net/h2728677716/article/details/147190740  浏览:    关键词:广州社交软件app开发_前端网页制作_电商运营培训_聚名网
广州社交软件app开发_前端网页制作_电商运营培训_聚名网

controller

重点:根据时间格式接受时间类型参数

@DateTimeFormat(pattern = "yyyy-MM-dd") LocalDateTime begin,
@DateTimeFormat(pattern = "yyyy-MM-dd") LocalDateTime end)

@RestController
@RequestMapping("/admin/report")
@Slf4j
public class ReportContrroller {@GetMapping("/turnoverStatics")public Result<TurnoverReportVO> turnoverStatics(@DateTimeFormat(pattern = "yyyy-MM-dd") LocalDateTime begin,@DateTimeFormat(pattern = "yyyy-MM-dd") LocalDateTime end){return null;}

实现类

根据前端传过来的两个时间点(开始时间点,结束时间点),算出这两个时间点间隔多少天,存放到一个ArrayList中。

并计算每天营业额总数,也存放到ArrayList中,构建成一个TurnoverReportVO返回给前端。 

重点:

根据LocalTime算出当天的开始时间MIN和结束时间MAX并专程LocalDateTime 

LocalDateTime beginTime = LocalDateTime.of(date, LocalTime.MIN);
LocalDateTime endTime = LocalDateTime.of(date, LocalTime.MAX); 

表达式的方式:

判断如果是空就赋值0.0,否则还是保持原来数值。

turnover = turnover == null ? 0.0 : turnover;

@Service
public class ReportServiceImpl implements ReportService {@Autowiredprivate OrderMapper orderMapper;public TurnoverReportVO getTrunoverStatics(LocalDate begin, LocalDate end) {List<LocalDate> dateList = new ArrayList();dateList.add(begin);while (!begin.equals(end)){begin = begin.plusDays(1);dateList.add(begin);}List<Double> Amounts = new ArrayList();for (LocalDate date : dateList){LocalDateTime beginTime = LocalDateTime.of(date, LocalTime.MIN);LocalDateTime endTime = LocalDateTime.of(date, LocalTime.MAX);//select sum(Amount) from orders where order_time >beginTime and order_time < endTime and status = 5;//Double sumAmount = orderMapper.getSumamount(beginTime, endTime);Map map = new HashMap();map.put("begin",beginTime);map.put("end",endTime);map.put("status", Orders.COMPLETED);Double turnover = orderMapper.getSumamount(map);turnover = turnover == null ? 0.0 : turnover;Amounts.add(turnover);}TurnoverReportVO turnoverReportVO = TurnoverReportVO.builder().dateList(StringUtils.join(dateList,",")).turnoverList(StringUtils.join(Amounts,",")).build();return turnoverReportVO;}
}
<select id="getSumamount" resultType="java.lang.Double">select sum(Amount) from orders<where><if test="begin != null">and order_time &gt; #{begin}</if><if test="end != null">and order_time &lt; #{end}</if><if test="status != null">and status=#{status}</if></where></select>

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com