cy
2022-06-21 129904537f66509f97b285e7eb4f42b3dc349dd0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
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;
    }
 
    
    
}