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;
|
}
|
}
|