package com.sifang.modules.platform.service;

import com.jfinal.plugin.activerecord.Db;
import com.sifang.modules.sys.common.service.BaseService;
import com.sifang.modules.sys.common.utils.DateUtils;
import org.springframework.stereotype.Service;
import com.jfinal.plugin.activerecord.Record;

import java.util.*;

@Service
public class IndexService extends BaseService {

    public Record  toGetCount(){
        String sql= "SELECT COUNT(id) FROM `crm_order`WHERE service_type= ? AND repair_time>=? AND repair_time<? ";
        Record rd=new Record();
        String arr[]={"维修","安装"};
    for(String type:arr){
     List<Long> list =new ArrayList<>();
     String date=DateUtils.getDate();
     Date day=DateUtils.parseDate(date);
        long lon=day.getTime();
     for(int i=0;i<7;i++){
         String day1=DateUtils.formatDateTime(new Date(lon-3600 * 24 * 1000*(6-i)));
         String day2=DateUtils.formatDateTime(new Date(lon-3600 * 24 * 1000*(6-i-1)));
       Long count=Db.queryLong(sql,type,day1,day2);
      list.add(count);
     }
   rd.set(type,list);
    }
    return  rd;
    }



}
