kongdeqiang
2024-11-12 552c700f584700316e8d1919dd1ad7f551c53ec4
fix : 新增日统计接口
5个文件已修改
1个文件已添加
150 ■■■■■ 已修改文件
src/main/java/com/boying/controller/OrderRecordController.java 108 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/boying/entity/vo/OutParkVo.java 19 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/boying/mapper/OutParkMapper.java 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/boying/service/OutParkService.java 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/boying/service/impl/OutParkServiceImpl.java 6 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/mapper/OutParkMapper.xml 11 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/boying/controller/OrderRecordController.java
@@ -8,27 +8,26 @@
import com.boying.entity.OrderRecord;
import com.boying.entity.OutPark;
import com.boying.entity.Park;
import com.boying.entity.User;
import com.boying.entity.vo.OrderRecordVo;
import com.boying.entity.vo.OutParkVo;
import com.boying.service.OrderRecordService;
import com.boying.service.OutParkService;
import com.boying.service.ParkService;
import com.boying.service.UserService;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.Month;
import java.time.YearMonth;
import java.util.*;
import java.util.logging.Handler;
import java.util.stream.Collectors;
@RestController
@@ -136,5 +135,104 @@
        return R.ok(resultList);
    }
    @PostMapping("/findCountPageByDay")
    public Object findCountPageByDay(Integer parkId,String day) throws ParseException {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        if(StringUtils.isBlank(day)){
            return R.failed("请选择时间查询");
        }else {
            List<Park> parkList= new ArrayList<>();
            if(parkId==null){
                parkList  = parkService.list();
            }else {
                Park byId = parkService.getById(parkId);
                parkList.add(byId);
            }
            String[] split = day.split("-");
            Integer year = Integer.parseInt(split[0]);
            Integer month = Integer.parseInt(split[1]);
            // 使用YearMonth.of()创建YearMonth实例
            YearMonth yearMonth = YearMonth.of(year, month);
            // 使用YearMonth实例的lengthOfMonth()方法获取该月的最大天数
            int maxDay = yearMonth.lengthOfMonth();
            String start = day+"-01";
            String end = day+"-"+maxDay;
            List<OutParkVo> list = outParkService.getVoList(parkId,start,end);
            List<Map<String,Object>> resultMapList = new ArrayList<>();
            List<String>str=new ArrayList<String>();
            for (int i = 1; i <= maxDay; i++) {
                if(i<10){
                    String d=day+"-0"+i;
                    str.add(d);
                }else {
                    String d=day+"-"+i;
                    str.add(d);
                }
            }
            for (String s : str) {
                List<OutParkVo> resultList = new ArrayList<>();
                List<OutParkVo> collect = list.stream().filter(item -> item.getTi().equals(s)).collect(Collectors.toList());
                for (Park park : parkList) {
                    List<OutParkVo> vos = collect.stream().filter(item -> item.getParkId().equals(park.getId())).collect(Collectors.toList());
                    if(vos!=null && vos.size()>0){
                        OutParkVo vo = vos.get(0);
                        vo.setParkName(park.getName());
                        if(vo.getNum()==null){
                            vo.setNum(0);
                        }
                        resultList.add(vo);
                    }else {
                        OutParkVo outParkVo = new OutParkVo();
                        outParkVo.setTi(s);
                        outParkVo.setNum(0);
                        outParkVo.setParkId(park.getId());
                        outParkVo.setParkName(park.getName());
                        outParkVo.setPrice(0.0d);
                        resultList.add(outParkVo);
                    }
                }
                Map<String ,Object>map = new HashMap<>();
                map.put("day",s);
                map.put("data",resultList);
                resultMapList.add(map);
            }
            return  R.ok(resultMapList);
        }
    }
    public static void main(String[] args) {
        // 获取当前日期
        LocalDate currentDate = LocalDate.now();
        // 获取当前月份
        Month currentMonth = currentDate.getMonth();
        int maxLength = currentMonth.maxLength();
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
        List<String>str=new ArrayList<String>();
        //String monthStart=df.format(new Date()).substring(0,8)+"01";
        for (int i = 1; i <= maxLength; i++) {
            if(i<10){
                String d=df.format(new Date()).substring(0,8)+"0"+i;
                str.add(d);
            }else {
                String d=df.format(new Date()).substring(0,8)+i;
                str.add(d);
            }
        }
        for (String s : str) {
            System.out.println(s);
        }
        // 假设我们要获取2023年3月的最大日期
        int year = 2023;
        int month = 3;
        // 使用YearMonth.of()创建YearMonth实例
        YearMonth yearMonth = YearMonth.of(year, month);
        // 使用YearMonth实例的lengthOfMonth()方法获取该月的最大天数
        int maxDay = yearMonth.lengthOfMonth();
        System.out.println(maxDay);
    }
}
src/main/java/com/boying/entity/vo/OutParkVo.java
New file
@@ -0,0 +1,19 @@
package com.boying.entity.vo;
import lombok.Data;
/**
 * @author kdq
 * @version 1.0.0
 * @ClassName OutParkVo.java
 * @Description TODO
 * @createTime 2024年11月11日 17:57:00
 */
@Data
public class OutParkVo {
    private Double price;
    private Integer parkId;
    private Integer num;
    private String ti;
    private String parkName;
}
src/main/java/com/boying/mapper/OutParkMapper.java
@@ -2,6 +2,7 @@
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.boying.entity.OutPark;
import com.boying.entity.vo.OutParkVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
@@ -21,4 +22,6 @@
    long getCount(@Param("carNo")String carNo, @Param("parkId")Long parkId, @Param("payCode")String payCode, @Param("date")String date);
    List<OutParkVo> getVoList(@Param("parkId")Integer parkId,@Param("startDate")String startDate,@Param("endDate")String endDate);
}
src/main/java/com/boying/service/OutParkService.java
@@ -3,6 +3,7 @@
import com.baomidou.mybatisplus.extension.service.IService;
import com.boying.entity.OutPark;
import com.boying.entity.Statistic;
import com.boying.entity.vo.OutParkVo;
import io.swagger.models.auth.In;
import java.time.LocalDateTime;
@@ -51,4 +52,6 @@
    List<Map<String, Object>> getLikeCar(String carNo, Integer parkId, LocalDateTime dateTime);
    List<OutParkVo> getVoList(Integer parkId,String startDate,String endDate);
}
src/main/java/com/boying/service/impl/OutParkServiceImpl.java
@@ -5,6 +5,7 @@
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.boying.entity.*;
import com.boying.entity.vo.OutParkVo;
import com.boying.mapper.EnterParkMapper;
import com.boying.mapper.OutParkMapper;
import com.boying.mapper.StatisticMapper;
@@ -248,6 +249,11 @@
    }
    @Override
    public List<OutParkVo> getVoList(Integer parkId, String startDate, String endDate) {
        return outParkMapper.getVoList(parkId,startDate,endDate);
    }
    @Override
    public OutPark findBy5min2(String carNo, Integer parkId,LocalDateTime dateTime) {
        LocalDateTime localDateTime = dateTime.minusMinutes(7);
        QueryWrapper<OutPark> wrapper = new QueryWrapper<>();
src/main/resources/mapper/OutParkMapper.xml
@@ -70,4 +70,15 @@
          select id,car_no,status2 from  out_park
          where barrier_id = #{barrierId} and `status` = 1 and status2 = 0 and del_flag = 0 limit 1;
    </select>
    <select id="getVoList" resultType="com.boying.entity.vo.OutParkVo">
          SELECT SUM(price) price,IFNULL(count( id ),0) num,park_id,DATE_FORMAT(update_time, '%Y-%m-%d') ti FROM out_park
          WHERE `status` = 1 AND pay_code IS NOT NULL
                <if test="parkId != null and parkId != ''">
                      and park_id = #{parkId}
                </if>
            AND DATE_FORMAT(update_time,'%Y-%m-%d') &gt;= DATE_FORMAT(#{startDate},'%Y-%m-%d')
            AND DATE_FORMAT(update_time,'%Y-%m-%d') &lt;= DATE_FORMAT(#{endDate},'%Y-%m-%d')
          GROUP BY ti,park_id
    </select>
</mapper>