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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
package cn.ksource.web.facade.wechat.uwyw;
 
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.util.ConvertUtil;
import cn.ksource.core.util.DateUtil;
import cn.ksource.core.util.StringUtil;
import cn.ksource.core.web.WebUtil;
import cn.ksource.core.workflow.WorkflowCoreService;
import cn.ksource.web.Constants;
import cn.ksource.web.facade.health.HealthFacade;
 
@Service
public class UHealthFacadeImpl implements UHealthFacade {
 
    @Autowired
    private WorkflowCoreService workflowCoreService;
    @Autowired
    private BaseDao baseDao;
    @Autowired
    private HealthFacade healthFacade;
 
    @Override
    public int uHealthCount(HttpServletRequest request) {
        Map supportMap = getAllHealthSql(request);
        String sql = "select count(*) from ( " + supportMap.get("sql").toString() + " ) t";
        return baseDao.queryForInteger(sql,(Map)supportMap.get("param"));
        
        
    }
 
    @Override
    public List uHealthData(HttpServletRequest request) {
        Map supportMap = getAllHealthSql(request);
        List<Map> list = baseDao.queryforSplitPage(request, supportMap.get("sql").toString(), (Map)supportMap.get("param"));
        return list;
    }
    
    
    
    
    /**
     * 工单列表
     * @param request
     * @return
     */
    private Map getAllHealthSql(HttpServletRequest request){
        
        String flowState = request.getParameter("flowstate");
        String customerId = WebUtil.getUserWywCusId(request);
        String subCustomerId = request.getParameter("subCustomerId");
        String orderCode = request.getParameter("orderCode");
        String nodeTemplateId = request.getParameter("node");
        String begintime = request.getParameter("begintime");
        String endtime = request.getParameter("endtime");
        
        Map paramMap = new HashMap();
        paramMap.put("flowState", flowState);
        paramMap.put("customerId",  customerId);
        paramMap.put("subCustomerId", subCustomerId);
        paramMap.put("nodeTemplateId", nodeTemplateId);
        paramMap.put("orderCode", "%"+orderCode+"%");
        paramMap.put("businessType", Constants.WORKFLOW_BASE_BUSINESS_TYPE_CI_HEALTH);
        
        StringBuilder builder = new StringBuilder();
        builder.append(" select b.PROJECT_NAME,b.BUSINESS_ID,b.ID FLOWID,b.WFNAME,b.CREATERNAME,b.CREATETIME,b.CURRENT_NODE_NAME,b.BUSINESSTYPE, ");
        builder.append(" t.PLAN_EXE_DATE,r.ORDER_CODE,r.ID ORDERID,r.CI_RUN_NOTE,b.CUSTOMER_NAME,b.SUB_CUSTOMER_NAME,B.WFSTATE  ");
        builder.append(" from SC_WORKFLOW_CI_HEALTH r  ");
        builder.append(" inner join WORKFLOW_BASE b on r.FLOW_ID = b.ID ");
        builder.append(" inner join CI_HEALTH_PLAN_TIMER t on r.ID = t.FLOW_ID ");
        if(StringUtil.isNotBlank(flowState)){
            if(flowState.equals("11")){
                builder.append(" inner join WORKFLOW_NODE N on b.CURRENT_NODE_ID = n.ID ");
                builder.append(" AND N.FLOWSTATE = 1  AND N.CURRENT_DEALER_ID IS NOT NULL ");
            }
        }
        builder.append(" where 1=1 ");
        //工单类型
        builder.append(" AND b.BUSINESSTYPE = :businessType");
        if(StringUtil.isNotBlank(nodeTemplateId)){
            builder.append(" and n.NODE_TEMPLATE_ID IS NOT NULL and  n.NODE_TEMPLATE_ID =:nodeTemplateId and b.WFSTATE = 1 ");
        }
        //客户
        if(StringUtil.isNotBlank(customerId)) {
            builder.append(" AND b.CUSTOMER_ID = :customerId ");
        }
        //下属单位
        if(StringUtil.isNotBlank(subCustomerId)) {
            builder.append(" AND b.SUB_CUSTOMER_ID = :subCustomerId ");
        }
        //工单状态
        if(StringUtil.isNotBlank(flowState) && !flowState.equals("11")){
            builder.append(" AND b.WFSTATE = :flowState ");
        }
        
        if(StringUtil.notEmpty(begintime)) {
            builder.append(" AND b.CREATETIME >= :begintime ");
            paramMap.put("begintime", begintime+"000000");
        }
        if(StringUtil.notEmpty(endtime)) {
            builder.append(" AND b.CREATETIME <= :endtime ");
            paramMap.put("endtime", endtime+"240000");
        }
        
        builder.append(" order by b.CREATETIME desc,t.PLAN_EXE_DATE desc ");            
                
        Map supportMap = new HashMap();
        supportMap.put("sql",builder);
        supportMap.put("param", paramMap);
        return supportMap;
    }
    
    
    
 
 
    @Override
    public Map queryHealthCalandar(HttpServletRequest request) {
        String year = request.getParameter("year");
        String month = request.getParameter("month");
        String queryType = request.getParameter("queryType");
        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)));
        }
        
        List<Map> orderList = new ArrayList<Map>();
        List<Map> planList = new ArrayList<Map>();
        Map orderSetMap = new HashMap();
        Map planSetMap = new HashMap();
        
            Map params = new HashMap();
            String selMonth = year+month;
            String bustype = "7";
            params.put("selMonth", selMonth);
            if(StringUtil.isNotBlank(queryType)){
                params.put("queryType", queryType);
            }
            params.put("bustype", bustype);
            if(StringUtil.isBlank(queryType)){
                params.put("customer_id", WebUtil.getUserWywCusId(request));
            }
            Map result = healthFacade.queryHealthDate(params);
            orderList=(List<Map>)result.get("orderDatas");
            planList=(List<Map>)result.get("planDatas");
        
        if(orderList!=null&&orderList.size()>0){
            for(Map map : orderList) {
                orderSetMap.put(ConvertUtil.obj2StrBlank(map.get("m_date")).replace("-", ""), "1");
            }
        }
        
        if(planList!=null&&planList.size()>0){
            for(Map map : planList) {
                planSetMap.put(ConvertUtil.obj2StrBlank(map.get("m_date")).replace("-", ""), "1");
            }
        }
        List resultList = new ArrayList();
        List weekList = new ArrayList();
        
        String today = DateUtil.getToday("yyyyMMdd");
        for(String dateStr : allDate) {
            if(orderSetMap.containsKey(dateStr)) {
                Map map = new HashMap();
                //判断当天是否有工单
                map.put("hasOrder", true);
                map.put("dateStr", dateStr);
                //判断是不是当月,如果不是当月当月颜色不一致
                String nowMonth = DateUtil.format("MM", dateStr);
                if(month.equals(nowMonth)) {
                    map.put("nowMonth", 1);
                } else {
                    map.put("nowMonth", 2);
                }
                //展示的日期(天)
                map.put("showMonth", DateUtil.format("dd", dateStr));
                //查询是否是当天之前
                if(dateStr.equals(today)) {
                    map.put("isTody", "1");
                } else {
                    if(ConvertUtil.obj2Long(today)>ConvertUtil.obj2Long(dateStr)) {
                        map.put("isTody", "0");
                    } else {
                        if(planSetMap.containsKey(dateStr)){
                            map.put("isTody", "2");
                        }
                        
                    }
                }
                if(weekDays.contains(dateStr)) {
                    weekList.add(map);
                }
                resultList.add(map);
            } else {
                Map map = new HashMap();
                map.put("hasOrder", false);
                String nowMonth = DateUtil.format("MM", dateStr);
                if(month.equals(nowMonth)) {
                    map.put("nowMonth", 1);
                } else {
                    map.put("nowMonth", 2);
                }
                map.put("showMonth", DateUtil.format("dd", dateStr));
                if(dateStr.equals(today)) {
                    map.put("isTody", "1");
                }else {
                    if(ConvertUtil.obj2Long(today)>ConvertUtil.obj2Long(dateStr)) {
                        map.put("isTody", "0");
                    } else {
                        if(planSetMap.containsKey(dateStr)){
                            map.put("isTody", "2");
                        }
                    }
                }
                resultList.add(map);
                
                if(weekDays.contains(dateStr)) {
                    weekList.add(map);
                }
            }
        }
        
        Map resultMap = new HashMap();
        resultMap.put("monthDays", resultList);
        resultMap.put("weekDays", weekList);
        
        return resultMap;
    }
    
    private List<Map> getProList(HttpServletRequest request){
        List<Map> projects = new ArrayList<Map>();
        Map pro = new HashMap();
        projects.add(pro);
        return projects;
    }
}