|
@@ -11,6 +11,7 @@ import me.zhengjie.modules.dm.statement.service.dto.DmStatementDto;
|
|
|
import me.zhengjie.modules.dm.statement.service.mapstruct.DmHaveDinnerMapper;
|
|
|
import me.zhengjie.utils.FileUtil;
|
|
|
import me.zhengjie.utils.PageUtil;
|
|
|
+import me.zhengjie.utils.StringUtils;
|
|
|
import org.springframework.data.domain.Page;
|
|
|
import org.springframework.data.domain.Pageable;
|
|
|
import org.springframework.stereotype.Service;
|
|
@@ -34,34 +35,106 @@ public class DmHaveDinnerServiceImpl implements DmHaveDinnerService {
|
|
|
|
|
|
@Override
|
|
|
public JSONObject selectDiningStatements(String stateDate, String endDate, String type, Pageable pageable) {
|
|
|
+
|
|
|
+ SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
+
|
|
|
+ SimpleDateFormat month = new SimpleDateFormat("yyyy-MM");
|
|
|
+
|
|
|
+ SimpleDateFormat year = new SimpleDateFormat("yyyy");
|
|
|
+
|
|
|
+ Boolean flag = false;
|
|
|
+
|
|
|
+ if (!StringUtils.isEmpty(stateDate) || !StringUtils.isEmpty(endDate)){
|
|
|
+ flag = true;
|
|
|
+ }
|
|
|
+
|
|
|
// 前三
|
|
|
Page<List<Map<String, Object>>> top = null;
|
|
|
// 后三
|
|
|
Page<List<Map<String, Object>>> stop = null;
|
|
|
// 默认按月来
|
|
|
if (type == null){
|
|
|
- top = dmHaveDinnerRepository.selectMonthTopView(stateDate,endDate,pageable);
|
|
|
- stop = dmHaveDinnerRepository.selectMonthStopView(stateDate, endDate, pageable);
|
|
|
+ type = "month";
|
|
|
}
|
|
|
//按日报来
|
|
|
if (type.equals("day")){
|
|
|
- top = dmHaveDinnerRepository.selectDayTopView(stateDate,endDate,pageable);
|
|
|
- stop = dmHaveDinnerRepository.selectDayStopView(stateDate, endDate, pageable);
|
|
|
+ Calendar instance = Calendar.getInstance();
|
|
|
+ //当前时间
|
|
|
+ String nowTime = simpleDateFormat.format(instance.getTime()) + " 23:59:59";
|
|
|
+ String StartTime = simpleDateFormat.format(instance.getTime()) + " 00:00:00";
|
|
|
+ if (flag){
|
|
|
+ top = dmHaveDinnerRepository.selectTop(stateDate,endDate,null);
|
|
|
+ stop = dmHaveDinnerRepository.selectStop(stateDate, endDate,null);
|
|
|
+ }else {
|
|
|
+ top = dmHaveDinnerRepository.selectTop(StartTime,nowTime,null);
|
|
|
+ stop = dmHaveDinnerRepository.selectStop(StartTime, nowTime,null);
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
// 按周报来
|
|
|
if (type.equals("week")){
|
|
|
- top = dmHaveDinnerRepository.selectWeekTopView(stateDate,endDate,pageable);
|
|
|
- stop = dmHaveDinnerRepository.selectWeekStopView(stateDate, endDate, pageable);
|
|
|
+ Calendar instance = Calendar.getInstance();
|
|
|
+ //判断当前时间在当前星期中事星期几 由于日历类中星期一是从周日算的
|
|
|
+ int i = instance.get(Calendar.DAY_OF_WEEK)-1;
|
|
|
+
|
|
|
+ //当前时间
|
|
|
+ String nowTime = "";
|
|
|
+ //开始时间
|
|
|
+ String startTime = "";
|
|
|
+
|
|
|
+ if (i==0){
|
|
|
+ instance.add(Calendar.DATE, 1-i);
|
|
|
+ startTime = simpleDateFormat.format(instance.getTime()) + " 00:00:00";
|
|
|
+ instance.add(Calendar.DATE, 7-1);
|
|
|
+ nowTime = simpleDateFormat.format(instance.getTime()) + " 23:59:59";
|
|
|
+ }else {
|
|
|
+ instance.add(Calendar.DATE,1-i);
|
|
|
+ startTime = simpleDateFormat.format(instance.getTime()) + " 00:00:00";
|
|
|
+ instance.add(Calendar.DATE, 7-1);
|
|
|
+ nowTime = simpleDateFormat.format(instance.getTime()) + " 23:59:59";
|
|
|
+ }
|
|
|
+ if (flag){
|
|
|
+ top = dmHaveDinnerRepository.selectTop(stateDate,endDate,null);
|
|
|
+ stop = dmHaveDinnerRepository.selectStop(stateDate, endDate,null);
|
|
|
+ }else {
|
|
|
+ top = dmHaveDinnerRepository.selectTop(startTime,nowTime,null);
|
|
|
+ stop = dmHaveDinnerRepository.selectStop(startTime, nowTime,null);
|
|
|
+ }
|
|
|
}
|
|
|
// 按月报来
|
|
|
if (type.equals("month")){
|
|
|
- top = dmHaveDinnerRepository.selectMonthTopView(stateDate,endDate,pageable);
|
|
|
- stop = dmHaveDinnerRepository.selectMonthStopView(stateDate, endDate, pageable);
|
|
|
+
|
|
|
+ Calendar instance = Calendar.getInstance();
|
|
|
+ // 当前月份最大多少天
|
|
|
+ int actualMaximum = instance.getActualMaximum(Calendar.DATE);
|
|
|
+ //当前时间
|
|
|
+ String nowTime = month.format(instance.getTime()) + "-"+actualMaximum+" 23:59:59";
|
|
|
+ String startTime = month.format(instance.getTime()) + "-01 00:00:00";
|
|
|
+ if (flag){
|
|
|
+ top = dmHaveDinnerRepository.selectTop(stateDate,endDate,null);
|
|
|
+ stop = dmHaveDinnerRepository.selectStop(stateDate, endDate,null);
|
|
|
+ }else {
|
|
|
+ top = dmHaveDinnerRepository.selectTop(startTime,nowTime,null);
|
|
|
+ stop = dmHaveDinnerRepository.selectStop(startTime, nowTime,null);
|
|
|
+ }
|
|
|
}
|
|
|
// 按年报来
|
|
|
if (type.equals("year")){
|
|
|
- top = dmHaveDinnerRepository.selectYearTopView(stateDate,endDate,pageable);
|
|
|
- stop = dmHaveDinnerRepository.selectYearStopView(stateDate, endDate, pageable);
|
|
|
+ Calendar instance = Calendar.getInstance();
|
|
|
+ //设置到12月用来取最大天数
|
|
|
+ instance.set(Calendar.MONTH, 11);
|
|
|
+ // 当年最大月份最大多少天
|
|
|
+ int actualMaximum = instance.getActualMaximum(Calendar.DATE);
|
|
|
+ //当前时间
|
|
|
+ String nowTime = year.format(instance.getTime())+ "-12-"+actualMaximum+" 23:59:59";
|
|
|
+ String startTime = year.format( instance.getTime())+ "-01-01 00:00:00";
|
|
|
+ if (flag){
|
|
|
+ top = dmHaveDinnerRepository.selectTop(stateDate,endDate,null);
|
|
|
+ stop = dmHaveDinnerRepository.selectStop(stateDate, endDate,null);
|
|
|
+ }else {
|
|
|
+ top = dmHaveDinnerRepository.selectTop(startTime,nowTime,null);
|
|
|
+ stop = dmHaveDinnerRepository.selectStop(startTime, nowTime,null);
|
|
|
+ }
|
|
|
}
|
|
|
JSONObject jsonObject = new JSONObject();
|
|
|
jsonObject.put("top", PageUtil.toPage(top));
|