123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604 |
- package com.yys.scsp.controller.app;
- import com.alibaba.druid.support.json.JSONUtils;
- import com.yys.scsp.config.jwt.JwtIgnore;
- import com.yys.scsp.entity.*;
- import com.yys.scsp.entityVo.TOrderInfoVo;
- import com.yys.scsp.mapper.TPowerRecordMapper;
- import com.yys.scsp.service.*;
- import com.yys.scsp.service.device.MessageService;
- import com.yys.scsp.utils.*;
- import com.yys.scsp.websocket.WebSocketServer;
- import org.apache.commons.lang.StringUtils;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Controller;
- import org.springframework.transaction.annotation.Transactional;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.RequestParam;
- import org.springframework.web.bind.annotation.ResponseBody;
- import java.math.BigDecimal;
- import java.text.DateFormat;
- import java.text.SimpleDateFormat;
- import java.util.*;
- /**
- * User: yangkaiyong
- * Date: 2019/8/28
- * Remake:
- */
- @Controller
- @RequestMapping("app/order")
- @SuppressWarnings("unchecked")
- public class TAppOrderController {
- static Logger logger = LoggerFactory.getLogger(TAppOrderController.class);
- @Autowired
- private TAppUserService userService;
- @Autowired
- private TDeviceService deviceService;
- @Autowired
- private TNetworkDotService networkDotService;
- @Autowired
- private TOrderInfoService tOrderInfoService;
- @Autowired
- public MessageService messageService;
- @Autowired
- public TPowerRecordMapper powerRecordMapper;
- @Autowired
- private TMonthlyService tMonthlyService;
- @Autowired
- private TAnnualService annualService;
- @Autowired
- private SharingConfigService configService;
- /**
- * 录入订单
- * @param userId 用户ID
- * @param deviceCode 设备号
- * @param totalPrice 总价
- * @param devicePort 设备端口
- * @param orderType 充电类型 0刷卡充电 1 扫码充电 2免费充电 3包月充电
- * @param hour 充电时长,单位:分钟
- * @param type 收费类型 0时间 1电量 2功率
- * @param isFullStop 是否充满自停,默认充满自停
- * @param
- * @param
- * @return
- */
- @RequestMapping("saveOrder")
- @JwtIgnore // 加此注解, 请求不做token验证
- @ResponseBody
- @Transactional
- public ResultUtil saveOrder(@RequestParam(value = "userId") Integer userId,
- @RequestParam(value = "deviceCode") String deviceCode,
- @RequestParam(value = "totalPrice") Double totalPrice,
- @RequestParam(value = "devicePort") Integer devicePort,
- @RequestParam(value = "orderType") Integer orderType,
- @RequestParam(value = "hour") Integer hour,
- @RequestParam(value = "type") String type,
- @RequestParam(value = "isFullStop", required = false, defaultValue = "1") Integer isFullStop,
- @RequestParam(value = "insuranceFee", required = false, defaultValue = "0") Double insuranceFee
- ) {
- if (Objects.isNull(userId) || StringUtils.isBlank(deviceCode)
- || Objects.isNull(totalPrice) || Objects.isNull(devicePort)
- || Objects.isNull(orderType) || Objects.isNull(hour)) {
- return ResultUtil.error("参数不合格");
- }
- // 所有订单充电时长不得超过12小时
- if (hour > 12 * 60)
- hour = 12 * 60;
- TAppUser appUser = userService.findAppUserById(userId);
- if (Objects.isNull(appUser)) {
- return ResultUtil.error("用户不存在");
- }
- Map device = deviceService.findDeviceInfoByDeviceCode(deviceCode);
- if (Objects.isNull(device)) {
- return ResultUtil.error("设备未录入");
- }
- Integer portStatus = (Integer) device.get("port" + devicePort);
- if (portStatus == 1) {
- return ResultUtil.error("端口" + portStatus + "正在使用状态");
- }
- // 判断是否存在未响应的订单,是则取消下单
- Map orderMap = new HashMap();
- orderMap.put("orderStatus", 0);
- orderMap.put("page", 0);
- orderMap.put("limit", 1);
- orderMap.put("deviceCode", deviceCode);
- orderMap.put("port", devicePort);
- List<TOrderInfoVo> orderList = tOrderInfoService.findAppOrderList(orderMap);
- if (orderList.size() > 0)
- return ResultUtil.error("已提交订单,请勿重复提交");
- // //是否抽单
- // int isDraw = 0;
- boolean canUseAnnual;
- boolean canUseMonthly = false;
- //1.判断是不是包年用户
- Map<String, Object> annualMap = canUseAnnual(userId, device, hour);
- canUseAnnual = (Boolean) annualMap.get("canUseAnnual");
- if (canUseAnnual) {
- logger.info("用户{}使用包年充电{}分钟", userId, hour);
- orderType = 4;
- type = "00";
- hour = (Integer) annualMap.get("hour");
- } else {
- //2.判断是不是包月用户
- Map<String, Object> monthlyMap = canUseMonthly(userId, device, hour);
- canUseMonthly = (Boolean) monthlyMap.get("canUseMonthly");
- if (canUseMonthly) {
- logger.info("用户{}使用包月充电{}分钟", userId, hour);
- orderType = 3;
- type = "00";
- hour = (Integer) monthlyMap.get("hour");
- } else {
- if (!"03".equals(type)) {
- if (BigDecimal.valueOf(appUser.getCash()).compareTo(BigDecimal.valueOf(totalPrice)) < 0) {
- return ResultUtil.error("订单金额不能大于余额,请充值");
- }
- // 正运行订单总金额
- double appOrderSumPrice = tOrderInfoService.findAppOrderSumPrice(userId);
- BigDecimal remain = BigDecimal.valueOf(appUser.getCash()).subtract(new BigDecimal(appOrderSumPrice));
- if (remain.doubleValue() < totalPrice) {
- return ResultUtil.error("当前已有订单在充电,余额不足开启其他端口,请充值");
- }
- } else {// 电费+服务费收费
- // 判断余额是否大于或等于开启充电最低余额,小于不能充电
- String minBalance = configService.getGlobalConfig(SharingConfig.CHARGING_START_BALANCE);
- if (appUser.getCash().compareTo(Double.valueOf(minBalance)) < 0) {
- return ResultUtil.error("余额小于启动充电最低余额" + minBalance + "元,请充值");
- }
- }
- // 根据订单总数判断判断是否抽单
- // int orderCount = tOrderInfoService.getOrderCountByDeviceCode(deviceCode);
- // NetworkDot networkDot = networkDotService.findNetworkDotInfoById(StringISNULLUtil.mapToInteger(device.get("networkDotId")));
- // Integer drawOrderNumber = networkDot.getDrawNumber();
- // if (drawOrderNumber == null)
- // drawOrderNumber = Integer.valueOf(configService.getGlobalConfig(SharingConfig.DRAW_ORDER_NUMBER));
- // if ((orderCount + 1) % drawOrderNumber == 0)
- // isDraw = 1;
- }
- }
- // String nonceStr = (UUID.randomUUID()).toString().replaceAll("-", "");
- DateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");
- Calendar calendar = Calendar.getInstance();
- String dateName = df.format(calendar.getTime());
- int v = (int) ((Math.random() * 9 + 1) * 1000000);
- //设置订单号
- String outTradeNo = dateName + v;
- OrderInfo orderInfoMy = new OrderInfo();
- orderInfoMy.setOrderCode(outTradeNo);
- orderInfoMy.setUserId(appUser.getId());
- orderInfoMy.setDeviceId(StringISNULLUtil.mapToInteger(device.get("id")));
- orderInfoMy.setTotalPrice(BigDecimal.valueOf(totalPrice));
- orderInfoMy.setDeviceCode(deviceCode);
- orderInfoMy.setDevicePort(devicePort);
- orderInfoMy.setOrderType(orderType);
- orderInfoMy.setOrderStatus(0);
- orderInfoMy.setPayStatus(1);
- // 包月、包年和电费+服务费模式订单设置为已续充
- if (orderType == 3 || orderType == 4 || "03".equals(type)) {
- orderInfoMy.setIsContinued(1);
- } else {
- orderInfoMy.setIsContinued(0);
- }
- orderInfoMy.setIsDraw(0);
- orderInfoMy.setInsuranceFee(insuranceFee);// 保险费用
- orderInfoMy.setPriceType(Integer.parseInt(type));
- Calendar ca = Calendar.getInstance();
- orderInfoMy.setCreateTime(ca.getTime());
- orderInfoMy.setStartTime(ca.getTime());
- if (!(canUseAnnual || canUseMonthly)) {
- switch (type) {
- case "00":
- break;
- case "01":// 电量
- hour = hour * 100;
- break;
- case "02":// 功率
- type = "00";
- hour = 25;
- break;
- case "03":// 电费+服务费
- type = "00";
- }
- }
- ca.add(Calendar.MINUTE, hour);
- Date end = ca.getTime();
- orderInfoMy.setEndTime(end);
- orderInfoMy.setHour(hour + "");
- tOrderInfoService.addOrderInfo(orderInfoMy);
- Integer port = devicePort;
- if (isFullStop == 0)
- port = devicePort | (1 << 8 - 1);
- String ports = String.format("%02x", port);
- String cmc = "2A0AAE" + ports + type + String.format("%04x", hour);
- //将十六进制字符串转数组
- byte[] bytes = HexUtils.hexStringToBytes(cmc);
- String crc = CrcTest.getCRC(bytes);
- System.out.println("CRC:" + crc);
- String s = HexUtils.HighAndLowSwap(crc);
- String cmd = cmc + s + "23";
- messageService.sendMqttMessage("/down/" + deviceCode, 1, HexUtils.hexStringToBytes(cmd));
- Map map = new HashMap();
- Map data = new HashMap();
- data.put("messageType", 1);
- map.put("deviceCode", deviceCode);
- map.put("devicePort", devicePort);
- map.put("type", 1);
- map.put("commandContent", cmd);
- map.put("createTime", new Date());
- map.put("commandRemarks", "启动" + devicePort + "端口");
- data.put("messageData", map);
- WebSocketServer.sendMsg(deviceCode, JSONUtils.toJSONString(data));
- return ResultUtil.success("执行成功!");
- }
- /**
- * 查询订单
- *
- * @param deviceCode
- * @param port
- * @param page
- * @param limit
- * @param userId
- * @param orderStatus
- * @return
- */
- @RequestMapping("getOrderList")
- @JwtIgnore // 加此注解, 请求不做token验证
- @ResponseBody
- public ResultUtil getOrderList(@RequestParam("deviceCode") String deviceCode,
- @RequestParam("port") Integer port,
- @RequestParam("page") Integer page,
- @RequestParam("limit") Integer limit,
- @RequestParam("userId") Integer userId,
- @RequestParam("orderStatus") Integer orderStatus) {
- if (StringUtils.isBlank(deviceCode) || Objects.isNull(userId) || Objects.isNull(port) || Objects.isNull(page) || Objects.isNull(limit) || Objects.isNull(orderStatus)) {
- return ResultUtil.error("参数不合格");
- }
- try {
- Map maps = new HashMap();
- maps.put("deviceCode", deviceCode);
- maps.put("port", port);
- maps.put("orderStatus", orderStatus);
- maps.put("page", (page - 1) * 10);
- maps.put("limit", limit);
- maps.put("userId", userId);
- List<TOrderInfoVo> appOrderList = tOrderInfoService.findAppOrderList(maps);
- return ResultUtil.success(appOrderList);
- } catch (Exception e) {
- return ResultUtil.error("查询设备信息失败");
- }
- }
- /**
- * 充电结束后查看弹出订单详情
- *
- * @param orderCode 订单号
- * @return
- */
- @RequestMapping("getOrderListByOrderCode")
- @JwtIgnore // 加此注解, 请求不做token验证
- @ResponseBody
-
- public ResultUtil getOrderListByOrderCode(@RequestParam("orderCode") String orderCode) {
- if (Objects.isNull(orderCode)) {
- return ResultUtil.error("参数不合格");
- }
- try {
- Map maps = new HashMap();
- maps.put("orderCode", orderCode);
- TOrderInfoVo order = tOrderInfoService.findAppOrderByOrderCode(maps);
- // String power = order.getChargingPower();
- // if (StringUtils.isEmpty(power)) {
- // power = order.getPower();
- // }
- // 收费标准
- // if (StringUtils.isNotEmpty(power)) {
- // Device device = deviceService.findDeviceByDeviceCode(order.getDeviceCode());
- // for (PriceContent priceContent : device.getPriceContentList()) {
- // if (Double.parseDouble(power) >= Double.parseDouble(priceContent.getPowerSectionBefore())
- // && ( StringUtils.isEmpty(priceContent.getPowerSectionAfter())
- // || Double.parseDouble(power) <= Double.parseDouble(priceContent.getPowerSectionAfter()) )) {
- // order.setPriceContent(priceContent);
- // break;
- // }
- // }
- // }
- return ResultUtil.success(order);
- } catch (Exception e) {
- return ResultUtil.error("查询订单详情失败");
- }
- }
- /**
- * 查询订单列表
- *
- * @param page 页码
- * @param limit 每页数
- * @param userId 用户id
- * @param orderStatus 订单状态
- * @return
- */
- @RequestMapping("getAppOrderListTable")
- @JwtIgnore // 加此注解, 请求不做token验证
- @ResponseBody
- public ResultUtil findAppOrderListTable(
- @RequestParam("page") Integer page,
- @RequestParam("limit") Integer limit,
- @RequestParam("userId") Integer userId,
- @RequestParam("orderStatus") Integer orderStatus
- ) {
- if (Objects.isNull(page) || Objects.isNull(limit) || Objects.isNull(orderStatus)) {
- return ResultUtil.error("参数不合格");
- }
- try {
- Map maps = new HashMap();
- maps.put("orderStatus", orderStatus);
- maps.put("page", (page - 1) * limit);
- maps.put("limit", limit);
- maps.put("userId", userId);
- List<TOrderInfoVo> appOrderList = tOrderInfoService.findAppOrderListTable(maps);
- return ResultUtil.success(appOrderList);
- } catch (Exception e) {
- return ResultUtil.error("查询订单列表失败");
- }
- }
- /**
- * 取消订单
- *
- * @param orderCode
- * @return
- */
- @RequestMapping("closeOrder")
- @JwtIgnore // 加此注解, 请求不做token验证
- @ResponseBody
- public ResultUtil closeOrder(@RequestParam("orderCode") String orderCode,@RequestParam(value="deviceCat",defaultValue="0") Integer deviceCat) {
- if (StringUtils.isBlank(orderCode)) {
- return ResultUtil.error("参数不合格");
- }
- try {
- Map maps = new HashMap();
- maps.put("orderCode", orderCode);
- TOrderInfoVo appOrderList = tOrderInfoService.findAppOrderByOrderCode(maps);
- if (appOrderList.getOrderStatus() != 1) {
- return ResultUtil.error("订单不可结束");
- }
- // 更新下发停止订单类型为用户停止
- tOrderInfoService.updateStopType(appOrderList.getId(), 9, "");
- String ports = String.format("%02x", appOrderList.getDevicePort());
- String cmc = "2A07AF" + ports;
- //将十六进制字符串转数组
- byte[] bytes = HexUtils.hexStringToBytes(cmc);
- String crc = CrcTest.getCRC(bytes);
- String s = HexUtils.HighAndLowSwap(crc);
- String cmd = cmc + s + "23";
- logger.info("用户结束充电,订单号:{},关闭端口报文:{}", orderCode, cmd);
- messageService.sendMqttMessage("/down/" + appOrderList.getDeviceCode(), 1, HexUtils.hexStringToBytes(cmd));
- Map map = new HashMap();
- map.put("deviceCode", appOrderList.getDeviceCode());
- map.put("type", 1);
- map.put("commandContent", cmd);
- map.put("commandRemarks", "关闭订单" + ports + "端口");
- //deviceService.addDeviceCommandDetails(map);
- WebSocketServer.sendMsg(appOrderList.getDeviceCode(), JSONUtils.toJSONString(map));
- return ResultUtil.success();
- } catch (Exception e) {
- return ResultUtil.error("取消订单失败");
- }
- }
- /**
- * 查询用户当天订单已充电分钟
- * @param userId
- * @param orderType
- * @return
- */
- @RequestMapping("getOrderSumHourByTime")
- @JwtIgnore // 加此注解, 请求不做token验证
- @ResponseBody
- public ResultUtil getOrderSumHourByTime(
- @RequestParam("userId") Integer userId,
- @RequestParam("orderType") Integer orderType
- ) {
- if (Objects.isNull(userId) || Objects.isNull(orderType)) {
- return ResultUtil.error("参数不合格");
- }
- try {
- return ResultUtil.success(getUsedMinute(userId, orderType));
- } catch (Exception e) {
- return ResultUtil.error("查询订单已充电分钟失败");
- }
- }
- /**
- * 查询用户当天订单已充电度数
- * @param userId
- * @param orderType
- * @return
- */
- @RequestMapping("getOrderUsedDegree")
- @JwtIgnore // 加此注解, 请求不做token验证
- @ResponseBody
- public ResultUtil getOrderUsedDegree(
- @RequestParam("userId") Integer userId,
- @RequestParam("orderType") Integer orderType
- ) {
- if (Objects.isNull(userId) || Objects.isNull(orderType)) {
- return ResultUtil.error("参数不合格");
- }
- try {
- return ResultUtil.success(getUsedDegree(userId, orderType));
- } catch (Exception e) {
- return ResultUtil.error("查询订单已充电分钟失败");
- }
- }
- /**
- * 用户是否可以使用包月
- * @param userId 用户ID
- * @param device 设备
- * @param hour 充电时长
- * @return 返回是否可以使用包月和充电时长
- */
- private Map<String, Object> canUseMonthly(Integer userId, Map<String, Object> device, int hour) {
- Map<String, Object> result = new HashMap<>();
- boolean canUseMonthly = false;
- TAppUser user = userService.findAppUserById(userId);
- TMonthly monthly = tMonthlyService.getMonthlyByUserId(userId);
- if (Objects.nonNull(monthly)) { //用户包月记录是否存在
- Boolean hasMonthCard = false;
- if (Integer.valueOf(device.get("hasMonthCard").toString())==1) {
- hasMonthCard = true;
- }
- logger.info("设备是否开启包月:{},用户包月是否有效:{}", hasMonthCard, monthly.isAvailable());
- //判断包月是否可用依据有3个,分别是设备是否开启包月、包月是否有效、购买包月站点是否和设备站点一致
- canUseMonthly = hasMonthCard && monthly.isAvailable()
- && monthly.getNetworkDotId().equals(Integer.valueOf(device.get("networkDotId").toString()));
- if (canUseMonthly) {
- // 用户包月剩余时长
- long remainMinute = monthly.getTime() - monthly.getUsedTime();
- logger.info("用户{}包月剩余{}分钟,当前订单充电{}分钟", userId, remainMinute, hour);
- // 判断包月是否设置每日限免时长,是的话获取当日已使用包月限免分钟
- if (remainMinute <= 0) {
- canUseMonthly = false;
- } else if (user.getChargingPower() != null && monthly.getPowerUpper() != null
- && user.getChargingPower().compareTo(monthly.getPowerUpper()) > 0) {
- canUseMonthly = false;// 用户充电功率超出包月功率限制
- } else {
- if (Objects.isNull(monthly.getDailyTime())) {
- if (remainMinute < hour)
- hour = (int) remainMinute;
- } else {
- // 当日已使用包月时长
- long usedMinute = getUsedMinute(userId, 3);
- // 计算当日剩余充电限制时长
- int toDayCanUseTime = (int) (monthly.getDailyTime() - usedMinute);
- logger.info("用户{}包月每日限免时长:{},今日已使用包月时长:{}", userId, monthly.getDailyTime(), usedMinute);
- // 当日剩余限制时长
- if (toDayCanUseTime <= 0) {
- logger.info("用户{}包月每日限免时长已用完", userId);
- canUseMonthly = false;
- } else {
- // 每日限免时长与总限免时长比较,用较小的
- int chargeMinute = Math.min(toDayCanUseTime, (int) remainMinute);
- if (chargeMinute < hour)
- hour = chargeMinute;
- }
- }
- }
- }
- }
- result.put("canUseMonthly", canUseMonthly);
- result.put("hour", hour);
- return result;
- }
- /**
- * 用户是否可以使用包年
- * @param userId 用户ID
- * @param device 设备
- * @param hour 充电时长
- * @return 返回是否可以使用包年和充电时长
- */
- private Map<String, Object> canUseAnnual(Integer userId, Map<String, Object> device, int hour) {
- Map<String, Object> result = new HashMap<>();
- boolean canUseAnnual = false;
- TAnnualUser annualUser = annualService.getAnnualUserByUserId(userId);
- if (Objects.nonNull(annualUser)) {
- Boolean hasAnnualCard = false;
- if (Integer.valueOf(device.get("hasAnnualCard").toString())==1) {
- hasAnnualCard = true;
- }
- logger.info("设备是否开启包年:{},用户包年是否有效:{}", hasAnnualCard, annualUser.isAvailable());
- //判断包年是否可用依据有3个,分别是设备是否开启包年、包年是否有效、购买包年站点是否和设备站点一致
- canUseAnnual = hasAnnualCard && annualUser.isAvailable()
- && annualUser.getNetworkDotId().equals(Integer.valueOf(device.get("networkDotId").toString()));
- if (canUseAnnual) {
- // 用户包月剩余时长
- long remainMinute = annualUser.getTotalMinute() - annualUser.getUsedMinute();
- logger.info("用户{}包年剩余{}分钟,当前订单充电{}分钟", userId, remainMinute, hour);
- // 判断包月是否设置每日限免时长,是的话获取当日已使用包月限免分钟
- if (remainMinute <= 0) {
- canUseAnnual = false;
- } else {
- if (Objects.isNull(annualUser.getDailyMinute())) {
- if (remainMinute < hour)
- hour = (int) remainMinute;
- } else {
- // 当日已使用包月时长
- long usedMinute = getUsedMinute(userId, 4);
- // 计算当日剩余充电限制时长
- int todayCanUseMinute = (int) (annualUser.getDailyMinute() - usedMinute);
- logger.info("用户{}包年每日限免时长:{},当天已使用时长:{}", userId, annualUser.getDailyMinute(), usedMinute);
- // 当日剩余限制时长
- if (todayCanUseMinute <= 0) {
- logger.info("用户{}包年每日限免时长已用完", userId);
- canUseAnnual = false;
- } else {
- // 每日限免时长与总限免时长比较,用较小的
- int chargeMinute = Math.min(todayCanUseMinute, (int) remainMinute);
- if (chargeMinute < hour)
- hour = chargeMinute;
- }
- }
- }
- }
- }
- result.put("canUseAnnual", canUseAnnual);
- result.put("hour", hour);
- return result;
- }
- private long getUsedMinute(Integer userId, Integer orderType) {
- Calendar calendar = Calendar.getInstance();
- calendar.set(Calendar.HOUR_OF_DAY, 0);
- calendar.set(Calendar.MINUTE, 0);
- calendar.set(Calendar.SECOND, 0);
- calendar.set(Calendar.MILLISECOND, 0);
- // 当天最开始时间
- Date startTime = calendar.getTime();
- calendar.add(Calendar.DATE, 1);
- // 第二天
- Date endTime = calendar.getTime();
- return tOrderInfoService.getOrderSumHourByTime(userId, orderType,
- startTime, endTime);
- }
- private double getUsedDegree(Integer userId, Integer orderType) {
- Calendar calendar = Calendar.getInstance();
- calendar.set(Calendar.HOUR_OF_DAY, 0);
- calendar.set(Calendar.MINUTE, 0);
- calendar.set(Calendar.SECOND, 0);
- calendar.set(Calendar.MILLISECOND, 0);
- // 当天最开始时间
- Date startTime = calendar.getTime();
- calendar.add(Calendar.DATE, 1);
- // 第二天
- Date endTime = calendar.getTime();
- return tOrderInfoService.getOrderTotalPowerByTime(userId, orderType,
- startTime, endTime);
- }
- }
|