package cn.ksource.web.facade.wechat.ewyw;
|
|
import java.util.ArrayList;
|
import java.util.HashMap;
|
import java.util.List;
|
import java.util.Map;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
|
import cn.ksource.core.dao.BaseDao;
|
import cn.ksource.core.dao.SqlParameter;
|
import cn.ksource.core.util.ConvertUtil;
|
import cn.ksource.core.util.DateUtil;
|
import cn.ksource.core.util.StringUtil;
|
import cn.ksource.core.web.WebUtil;
|
|
@Service("ewWorkplanFacade")
|
public class EwWorkplanFacadeImpl implements EwWorkplanFacade {
|
|
@Autowired
|
private BaseDao baseDao;
|
|
@Override
|
public Map queryDailyCalandar(Map<String, String> params) {
|
String year = params.get("year");
|
String month = params.get("month");
|
String cusId = params.get("cusId");
|
|
if(!StringUtil.notEmpty(year)) {
|
year = DateUtil.getToday("yyyy");
|
}
|
if(!StringUtil.notEmpty(month)) {
|
month = DateUtil.getToday("MM");
|
}
|
|
String time = new String();
|
long nMonth = DateUtil.getCurrentDate6();
|
String yearMonth = year+month;
|
if(String.valueOf(nMonth).equals(yearMonth)) {
|
time = DateUtil.getToday("yyyyMMdd");
|
} else {
|
time = yearMonth+"01";
|
}
|
|
//所在周的前一个周日和后一个周六
|
Long[] sunSat = DateUtil.getSundaySaturday(Long.valueOf(time));
|
|
List<String> weekDays = DateUtil.getBetweenTwoDateCycleList(String.valueOf(sunSat[0]), String.valueOf(sunSat[1]), 2, 1, "yyyyMMdd", "yyyyMMdd");
|
|
|
//查询该月的第一天和最后一天
|
String[] dates = StringUtil.queryFirstLastDate(year,month);
|
//查询第一天属于周几
|
long firstDay = ConvertUtil.obj2Long(dates[0].replaceAll("-", ""));
|
long endDay = ConvertUtil.obj2Long(dates[1].replaceAll("-", ""));
|
int week = DateUtil.getDayOfWeek(firstDay);
|
|
List<String> allDate = new ArrayList<String>();
|
for(int i=week; i>0; i--) {
|
allDate.add(ConvertUtil.obj2StrBlank(DateUtil.getDateAdd(firstDay, -i, 8)));
|
}
|
|
List<String> list = new ArrayList<String>();
|
list = DateUtil.getBetweenTwoDateList(ConvertUtil.obj2StrBlank(firstDay), ConvertUtil.obj2StrBlank(endDay), 2, "yyyyMMdd");
|
|
for(String str : list) {
|
allDate.add(str.replaceAll("-", ""));
|
}
|
|
int lastSize = 42-allDate.size();
|
for(int i=1; i<=lastSize; i++) {
|
allDate.add(ConvertUtil.obj2StrBlank(DateUtil.getDateAdd(endDay, i, 8)));
|
}
|
|
|
Map paramMap = new HashMap();
|
List<Map> reportList = new ArrayList<Map>();
|
StringBuilder builder = new StringBuilder();
|
builder.append(" SELECT COUNT(PATROL_DATE) AS NUM,PATROL_DATE AS REPORT_DATE FROM CI_DAILY_PATROL WHERE PATROL_DATE >= :beginTime AND PATROL_DATE <= :endTime ");
|
|
paramMap.put("beginTime", allDate.get(0));
|
paramMap.put("endTime", allDate.get(allDate.size()-1));
|
|
if(StringUtil.isNotBlank(params.get("userId"))) {
|
builder.append(" AND USER_ID=:userId ");
|
paramMap.put("userId", params.get("userId"));
|
}
|
|
if(StringUtil.isNotBlank(cusId)){
|
builder.append(" AND CUS_ID = :cusId ");
|
paramMap.put("cusId", cusId);
|
}
|
|
builder.append(" GROUP BY PATROL_DATE ORDER BY PATROL_DATE DESC ");
|
reportList = baseDao.queryForList(builder.toString(),paramMap);
|
|
Map cacheMap = new HashMap();
|
for(Map map : reportList) {
|
cacheMap.put(map.get("REPORT_DATE"), map);
|
}
|
|
List resultList = new ArrayList();
|
List weekList = new ArrayList();
|
|
String today = DateUtil.getToday("yyyyMMdd");
|
for(String str : allDate) {
|
long strLong = ConvertUtil.obj2Long(str);
|
if(cacheMap.containsKey(strLong)) {
|
Map map = (Map)cacheMap.get(strLong);
|
//判断当天是否已经巡检过
|
map.put("isCheck", 1);
|
|
//判断是不是当月,如果不是当月当月颜色不一致
|
String nowMonth = DateUtil.format("MM", str);
|
if(month.equals(nowMonth)) {
|
map.put("nowMonth", 1);
|
} else {
|
map.put("nowMonth", 2);
|
}
|
//展示的日期(天)
|
map.put("showMonth", DateUtil.format("dd", str));
|
|
//查询是否是当天之前
|
|
|
if(str.equals(today)) {
|
map.put("isTody", "1");
|
} else {
|
if(ConvertUtil.obj2Long(today)>ConvertUtil.obj2Long(str)) {
|
map.put("isTody", "2");
|
} else {
|
map.put("isTody", "0");
|
}
|
}
|
|
if(weekDays.contains(str)) {
|
weekList.add(map);
|
}
|
|
resultList.add(map);
|
} else {
|
Map map = new HashMap();
|
map.put("isCheck", 2);
|
map.put("REPORT_DATE", str);
|
String nowMonth = DateUtil.format("MM", str);
|
if(month.equals(nowMonth)) {
|
map.put("nowMonth", 1);
|
} else {
|
map.put("nowMonth", 2);
|
}
|
map.put("showMonth", DateUtil.format("dd", str));
|
if(str.equals(today)) {
|
map.put("isTody", "1");
|
} else {
|
if(ConvertUtil.obj2Long(today)>ConvertUtil.obj2Long(str)) {
|
map.put("isTody", "2");
|
} else {
|
map.put("isTody", "0");
|
}
|
}
|
resultList.add(map);
|
|
if(weekDays.contains(str)) {
|
weekList.add(map);
|
}
|
}
|
}
|
|
Map resultMap = new HashMap();
|
resultMap.put("monthDays", resultList);
|
resultMap.put("weekDays", weekList);
|
|
return resultMap;
|
}
|
|
@Override
|
public List<Map> queryMyReportByDate(Map<String, String> params) {
|
String selectSql = new String();
|
SqlParameter paramMap = new SqlParameter("userId",params.get("userId"));
|
String beginDate = params.get("beginDate");
|
String endDate = params.get("endDate");
|
|
if(!StringUtil.notEmpty(endDate)) {
|
endDate = beginDate;
|
}
|
if(beginDate.equals(endDate)) {
|
selectSql = "SELECT * FROM CI_DAILY_PATROL WHERE USER_ID=:userId AND PATROL_DATE = :date ";
|
paramMap.put("date", beginDate);
|
} else {
|
selectSql = "SELECT * FROM CI_DAILY_PATROL WHERE USER_ID=:userId AND PATROL_DATE BETWEEN :beginTime AND :endTime ORDER BY PATROL_DATE DESC ";
|
paramMap.put("beginTime", beginDate);
|
paramMap.put("endTime", endDate);
|
}
|
|
String cusId = params.get("cusId");
|
if(StringUtil.notEmpty(cusId)) {
|
selectSql += " AND CUS_ID = :cusId";
|
paramMap.put("cusId", cusId);
|
}
|
List<Map> reports = baseDao.queryForList(selectSql,paramMap);
|
return reports;
|
}
|
|
@Override
|
public List<Map> queryReportByDate(Map<String, String> params) {
|
StringBuilder builder = new StringBuilder();
|
SqlParameter paramMap = new SqlParameter();
|
String beginDate = params.get("beginDate");
|
String endDate = params.get("endDate");
|
if(!StringUtil.notEmpty(endDate)) {
|
endDate = beginDate;
|
}
|
|
if(beginDate.equals(endDate)) {
|
builder = new StringBuilder("SELECT * FROM CI_DAILY_PATROL WHERE PATROL_DATE = :date ");
|
paramMap.put("date", beginDate);
|
} else {
|
builder = new StringBuilder("SELECT * FROM CI_DAILY_PATROL WHERE PATROL_DATE BETWEEN :beginTime AND :endTime ");
|
paramMap.put("beginTime", beginDate);
|
paramMap.put("endTime", endDate);
|
}
|
|
String cusId = params.get("cusId");
|
if(StringUtil.notEmpty(cusId)) {
|
builder.append(" AND CUS_ID = :cusId");
|
paramMap.put("cusId", cusId);
|
}
|
builder.append(" ORDER BY PATROL_DATE DESC ");
|
List<Map> reports = baseDao.queryForList(builder.toString(),paramMap);
|
return reports;
|
}
|
|
|
|
}
|