package cn.ksource.web.facade.remind;
|
|
import java.util.ArrayList;
|
import java.util.Arrays;
|
import java.util.HashMap;
|
import java.util.List;
|
import java.util.Map;
|
|
import javax.annotation.Resource;
|
import javax.servlet.http.HttpServletRequest;
|
|
import org.apache.commons.lang.StringUtils;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
|
import cn.ksource.beans.SC_PARTNER_CUSTOMER_INFO;
|
import cn.ksource.beans.SC_PARTNER_CUSTOMER_SUB;
|
import cn.ksource.beans.SC_WORKFLOW_CI_REMIND;
|
import cn.ksource.core.dao.BaseDao;
|
import cn.ksource.core.dao.SqlParameter;
|
import cn.ksource.core.page.PageInfo;
|
import cn.ksource.core.util.ConvertUtil;
|
import cn.ksource.core.util.DateUtil;
|
import cn.ksource.core.util.JsonUtil;
|
import cn.ksource.core.util.StringUtil;
|
import cn.ksource.core.web.SysInfoMsg;
|
import cn.ksource.web.Constants;
|
import cn.ksource.web.entity.WorkFlowSupportEntity;
|
import cn.ksource.web.service.WorkOrderCodeService;
|
import cn.ksource.web.service.workFlowSupport.WorkFlowSupportService;
|
import cn.ksource.web.util.DateParepareUtil;
|
|
@Service
|
@SuppressWarnings({ "rawtypes" })
|
public class RemindFacadeImpl implements RemindFacade {
|
|
@Resource
|
private BaseDao baseDao;
|
@Autowired
|
private WorkOrderCodeService workOrderCodeService;
|
@Autowired
|
private WorkFlowSupportService workFlowSupportService;
|
|
@Override
|
public PageInfo getRemindItemData(PageInfo pageInfo, Map<String, String> params) {
|
Map support = getRmindItemSupport(params);
|
String sql = support.get("sql").toString();
|
return baseDao.queryforSplitPageInfo(pageInfo, sql, params);
|
}
|
|
@Override
|
public Object getRemindItemCount(Map<String, String> params) {
|
Map support = getRmindItemSupport(params);
|
String sql = "select count(*) from ( " + support.get("sql").toString() + " ) t ";
|
return baseDao.queryForInteger(sql, params);
|
}
|
|
private Map getRmindItemSupport(Map<String, String> params) {
|
Map<String, Object> support = new HashMap<String, Object>();
|
StringBuilder sql = new StringBuilder();
|
sql.append(" select a.* ,b.id item_id,b.using_state statu ");
|
sql.append(" from ci_remind_item a,ci_remind_customer_item b ");
|
//sql.append(" where b.item_id=a.id and b.customer_id=:cusId ");
|
sql.append(" where b.item_id=a.id and b.customer_id='-1' ");
|
if (StringUtil.isNotBlank(params.get("itemName"))) {
|
sql.append(" and a.item_name like :itemName ");
|
params.put("itemName", "%" + params.get("itemName") + "%");
|
}
|
if (StringUtil.isNotBlank(params.get("itemType"))) {
|
sql.append(" and a.item_type = :itemType ");
|
}
|
if (StringUtil.isNotBlank(params.get("state"))) {
|
sql.append(" and a.state = :state ");
|
}
|
if (StringUtil.isNotBlank(params.get("fullCateId"))) {
|
String[] arr = params.get("fullCateId").split("-");
|
params.put("cateId", arr[arr.length - 1]);
|
sql.append(" and a.business_id = :cateId ");
|
}
|
sql.append(" order by a.order_num asc ");
|
support.put("sql", sql.toString());
|
support.put("param", params);
|
return support;
|
}
|
|
@Override
|
public void saveRemindItem(Map<String, String> params) {
|
StringBuilder sql = new StringBuilder();
|
String[] cateIds = params.get("full_cate_id").split("-");
|
String[] cateNames = params.get("full_cate_name").split("-");
|
if (cateIds.length == 3) {
|
params.put("business_id", cateIds[2]);
|
params.put("business_name", cateNames[2]);
|
params.put("p_id", cateIds[1]);
|
} else {
|
params.put("business_id", cateIds[1]);
|
params.put("business_name", cateNames[1]);
|
params.put("p_id", cateIds[0]);
|
}
|
|
if (StringUtil.isBlank(params.get("id"))) {// 插入
|
String id = StringUtil.getUUID();
|
params.put("id", id);
|
sql.append(" insert into ci_remind_item ( ");
|
sql.append(" id,item_name,cycle,priority_level_id,priority_level_name,item_note,order_num, ");
|
sql.append(" state,business_id,business_name,item_type,customer_id,p_id,full_cate_id,full_cate_name ");
|
sql.append(" ) values ( ");
|
sql.append(" :id,:item_name,:cycle,:priority_level_id,:priority_level_name,:item_note,:order_num, ");
|
sql.append(" 1,:business_id,:business_name,:item_type,:customer_id,:p_id,:full_cate_id,:full_cate_name ) ");
|
baseDao.execute(sql.toString(), params);
|
sql.setLength(0);
|
params.put("item_id", id);
|
params.put("id", StringUtil.getUUID());
|
sql.append("insert into ci_remind_customer_item (id,customer_id,item_id,using_state) values ");
|
sql.append(" (:id,:customer_id,:item_id,1) ");
|
baseDao.execute(sql.toString(), params);
|
} else {// 编辑
|
sql.append(
|
" update ci_remind_item set item_name=:item_name,cycle=:cycle,priority_level_id=:priority_level_id, ");
|
sql.append(
|
" priority_level_name=:priority_level_name,item_note=:item_note,order_num=:order_num,business_id=:business_id, ");
|
sql.append(
|
" business_name=:business_name,p_id=:p_id,full_cate_id=:full_cate_id,full_cate_name=:full_cate_name ");
|
sql.append(" where id=:id ");
|
baseDao.execute(sql.toString(), params);
|
}
|
|
}
|
|
@Override
|
public Map getRemindItemById(String id) {
|
return baseDao.queryForMap("select * from ci_remind_item where id=:id ", new SqlParameter("id", id));
|
}
|
|
@Override
|
public List<Map> getGelItemList(Map<String, String> params) {
|
StringBuilder sql = new StringBuilder();
|
sql.append(" select a.* from ci_remind_item a where a.state=1 and a.item_type=1 and not exists ");
|
sql.append(" (select item_id from ci_remind_customer_item b where b.item_id=a.id and b.customer_id=:cusId ) ");
|
if (StringUtil.isNotBlank(params.get("itemName"))) {
|
sql.append(" and a.item_name like :itemName ");
|
params.put("itemName", "%" + params.get("itemName") + "%");
|
}
|
if (StringUtil.isNotBlank(params.get("fullCateId"))) {
|
String[] arr = params.get("fullCateId").split("-");
|
params.put("cateId", arr[arr.length - 1]);
|
sql.append(" and a.business_id = :cateId ");
|
}
|
return baseDao.queryForList(sql.toString(), params);
|
}
|
|
@Override
|
public void doSelGelRemindItem(String ids, String cusId) {
|
StringBuilder sql = new StringBuilder();
|
String[] arr = ids.split(",");
|
List<String> list = Arrays.asList(arr);
|
sql.append(" select * from ci_remind_item where id in (:list) ");
|
List<Map> items = baseDao.queryForList(sql.toString(), new SqlParameter("list", list));
|
if (items != null && items.size() > 0) {
|
sql.setLength(0);
|
sql.append("insert into ci_remind_customer_item (id,customer_id,item_id,using_state) values ");
|
sql.append(" (:id,:cusId,:item_id,1) ");
|
List<SqlParameter> pList = new ArrayList<SqlParameter>();
|
for (Map item : items) {
|
SqlParameter p = new SqlParameter();
|
p.putAll(item);
|
p.put("id", StringUtil.getUUID());
|
p.put("cusId", cusId);
|
p.put("item_id", item.get("id"));
|
pList.add(p);
|
}
|
baseDao.executeBatch(sql.toString(), pList);
|
|
}
|
|
}
|
|
/**
|
* 跳转到给客户制定计划页面
|
*/
|
@Override
|
public Map queryCustomerDetail(String customerId) {
|
String selectSql = "SELECT B.ID, B.CUSTOMER_NAME,B.CONTACT,B.PHONE,C.CUSTOMER_ID ,C.SUB_CUSTOMER_ID "
|
+ " FROM SC_PARTNER_CUSTOMER_INFO B LEFT JOIN CI_REMIND_CUSTOMER_ITEM_CYCLE C ON B.ID=C.CUSTOMER_ID "
|
+ " WHERE B.ID = :customerId ";
|
Map project = baseDao.queryForMap(selectSql, new SqlParameter("customerId", customerId));
|
return project;
|
}
|
|
/**
|
* 查询子客户
|
*
|
* @param customerId
|
* @return
|
*/
|
@Override
|
public List querySubList(String customerId) {
|
Map paramMap = new HashMap();
|
paramMap.put("customerId", customerId);
|
// 查询当前客户的信息
|
String selectSql = "SELECT ID,CUSTOMER_NAME FROM SC_PARTNER_CUSTOMER_INFO WHERE ID = :customerId";
|
Map customer = baseDao.queryForMap(selectSql, paramMap);
|
if (null != customer && customer.size() > 0) {
|
// 查询下级客户
|
String selectSubSql = "SELECT A.*,B.CONTACTS_NAME,B.CONTACTS_TEL "
|
+ " FROM SC_PARTNER_CUSTOMER_SUB A LEFT JOIN CI_REMIND_CUSTOMER_ITEM_CYCLE B "
|
+ " ON B.SUB_CUSTOMER_ID=A.ID WHERE A.CUSTOMER_ID = :customerId "
|
+ " AND A.DEL_FLAG = 1 GROUP BY A.ID ORDER BY A.MY_LEVEL ";
|
List<Map> subCus = baseDao.queryForList(selectSubSql, paramMap);
|
|
return subCus;
|
}
|
return null;
|
}
|
|
@Override
|
public Map queryPlanCount(String itemId, String customerId) {
|
String selectSql = "SELECT CUSTOMER_ID,SUB_CUSTOMER_ID,COUNT(ID) AS NUM FROM CI_REMIND_TIMERTASK WHERE CUSTOMER_ID = :customerId AND CUSTOMER_ITEM_ID = :itemId GROUP BY CUSTOMER_ID,SUB_CUSTOMER_ID";
|
Map paramMap = new HashMap();
|
paramMap.put("itemId", itemId);
|
paramMap.put("customerId", customerId);
|
List<Map> plans = baseDao.queryForList(selectSql, paramMap);
|
Map resultMap = new HashMap();
|
|
if (null != plans && plans.size() > 0) {
|
for (Map plan : plans) {
|
String customer = ConvertUtil.obj2StrBlank(plan.get("CUSTOMER_ID"));
|
String subCustomerId = ConvertUtil.obj2StrBlank(plan.get("SUB_CUSTOMER_ID"));
|
String num = ConvertUtil.obj2StrBlank(plan.get("NUM"));
|
resultMap.put(customer + "-" + subCustomerId, num);
|
}
|
}
|
|
String selectSql2 = "SELECT CUSTOMER_ID,SUB_CUSTOMER_ID,STATE,COUNT(ID) AS NUM FROM CI_REMIND_TIMERTASK WHERE CUSTOMER_ID = :customerId AND STATE = 2 AND CUSTOMER_ITEM_ID = :itemId GROUP BY CUSTOMER_ID,SUB_CUSTOMER_ID,STATE";
|
List<Map> zxPlans = baseDao.queryForList(selectSql2, paramMap);
|
if (null != zxPlans && zxPlans.size() > 0) {
|
for (Map plan : zxPlans) {
|
String customer = ConvertUtil.obj2StrBlank(plan.get("CUSTOMER_ID"));
|
String subCustomerId = ConvertUtil.obj2StrBlank(plan.get("SUB_CUSTOMER_ID"));
|
String num = ConvertUtil.obj2StrBlank(plan.get("NUM"));
|
resultMap.put(customer + "-" + subCustomerId + "2", num);
|
}
|
}
|
return resultMap;
|
}
|
|
@Override
|
public Map queryRemindItemCycle(String itemId, String customerId, String subId) {
|
String selectSql = new String();
|
Map paramMap = new HashMap();
|
paramMap.put("itemId", itemId);
|
paramMap.put("customerId", customerId);
|
paramMap.put("subId", subId);
|
if(StringUtil.isBlank(subId)){
|
paramMap.put("subId", customerId);
|
}
|
selectSql = "SELECT * FROM CI_REMIND_CUSTOMER_ITEM_CYCLE WHERE PROJECT_ITEM_ID = :itemId AND CUSTOMER_ID = :customerId AND SUB_CUSTOMER_ID = :subId ";
|
Map cycle = baseDao.queryForMap(selectSql, paramMap);
|
return cycle;
|
}
|
|
/**
|
* 删除未执行的例行维护计划表
|
*/
|
private void deleteRemindTask(String customerItemId, String customerId, String subCustomerId) {
|
// long today = DateUtil.getCurrentDate8();
|
String deleteSql = "DELETE FROM CI_REMIND_TIMERTASK WHERE PLAN_EXECUTION_DATE > :today AND STATE = :state AND CUSTOMER_ITEM_ID = :customerItemId AND CUSTOMER_ID = :customerId";
|
Map paramMap = new HashMap();
|
paramMap.put("customerId", customerId);
|
if (StringUtil.notEmpty(subCustomerId)) {
|
deleteSql += " AND SUB_CUSTOMER_ID = :subCustomerId ";
|
paramMap.put("subCustomerId", subCustomerId);
|
} else {
|
deleteSql += " AND SUB_CUSTOMER_ID = :customerId ";
|
}
|
|
paramMap.put("today", DateUtil.getCurrentDate8());
|
paramMap.put("state", Constants.CI_REMIND_TIMERTASK_STATE_WZX);
|
paramMap.put("customerItemId", customerItemId);
|
// paramMap.put("today", today);
|
baseDao.execute(deleteSql, paramMap);
|
}
|
|
/**
|
* 生成例行维护计划表
|
*
|
* @param projectItemId
|
*/
|
private void createRemindTask(String id, String projectItemId, String customerId, String subCustomerId) {
|
// 查询项目
|
|
String selectSql = "SELECT A.* ,C.VALID_END_DATE FROM CI_REMIND_CUSTOMER_ITEM_CYCLE A,SC_PARTNER_CUSTOMER_INFO C"
|
+ " WHERE A.CUSTOMER_ID = C.ID AND A.ID=:id AND C.CUSTOMER_STATE=1 AND C.VALID_END_DATE >= :today AND C.VALID_BEGIN_DATE <= :today ";
|
String cid = customerId;
|
|
Map item = baseDao.queryForMap(selectSql,new SqlParameter("id", id).addValue("today", DateUtil.getCurrentDate8()).addValue("cid", cid));
|
if (null != item && item.size() > 0) {
|
String leix = ConvertUtil.obj2StrBlank(item.get("LEIX"));
|
String zhouqi = ConvertUtil.obj2StrBlank(item.get("ZHOUQI"));
|
|
String endTime = ConvertUtil.obj2StrBlank(item.get("VALID_END_DATE"));
|
|
String today = DateUtil.getToday("yyyyMMdd");
|
|
Map paramMap = new HashMap();
|
paramMap.put("projectItemId", projectItemId);
|
paramMap.put("state", Constants.CI_REMIND_TIMERTASK_STATE_YZX);
|
paramMap.put("customerId", customerId);
|
// 查询已经执行过的日期,生成新的提醒表时,去掉已经执行过的日期
|
String zxSql = "SELECT * FROM CI_REMIND_TIMERTASK WHERE CUSTOMER_ITEM_ID = :projectItemId AND STATE = :state AND CUSTOMER_ID = :customerId ";
|
zxSql += " AND SUB_CUSTOMER_ID = :subCustomerId ";
|
if (StringUtil.notEmpty(subCustomerId)) {
|
paramMap.put("subCustomerId", subCustomerId);
|
} else {
|
paramMap.put("subCustomerId", customerId);
|
}
|
List<Map> zxList = baseDao.queryForList(zxSql, paramMap);
|
Map zxCache = new HashMap();
|
if (null != zxList && zxList.size() > 0) {
|
for (Map zx : zxList) {
|
String day = ConvertUtil.obj2StrBlank(zx.get("PLAN_EXECUTION_DATE"));
|
zxCache.put(day, zx);
|
}
|
}
|
|
// 生成智能提醒时间表
|
String insertSql = "INSERT INTO CI_REMIND_TIMERTASK(ID,CUSTOMER_ITEM_ID,STATE,PLAN_EXECUTION_DATE,CUSTOMER_ID,SUB_CUSTOMER_ID) VALUES (:id,:project_item_id,1,:plan_execution_date,:customerId,:subCustomerId)";
|
if (leix.equals("1")) {
|
String beginExecDate = ConvertUtil.obj2StrBlank(item.get("BEGIN_EXEC_DATE"));
|
|
List<SqlParameter> paramList = new ArrayList<SqlParameter>();
|
List<String> dates = DateUtil.getBetweenTwoDateCycleList(beginExecDate, endTime, 2,
|
ConvertUtil.obj2Int(zhouqi), "yyyyMMdd", "yyyyMMdd");
|
if (null != dates && dates.size() > 0) {
|
Map param = new HashMap();
|
param.put("project_item_id", projectItemId);
|
param.put("customerId", customerId);
|
if (StringUtil.notEmpty(subCustomerId)) {
|
param.put("subCustomerId", subCustomerId);
|
} else {
|
param.put("subCustomerId", customerId);
|
}
|
for (String str : dates) {
|
if (!zxCache.containsKey(str)) {
|
SqlParameter sqlParameter = new SqlParameter();
|
sqlParameter.addValue("id", StringUtil.getUUID());
|
|
sqlParameter.addValue("plan_execution_date", str);
|
sqlParameter.putAll(param);
|
paramList.add(sqlParameter);
|
}
|
}
|
baseDao.executeBatch(insertSql, paramList);
|
}
|
}
|
}
|
}
|
|
/**
|
* 更新例行维护的执行周期
|
*/
|
@Override
|
public boolean updateRemindCycle(HttpServletRequest request) {
|
|
String id = request.getParameter("id");
|
String leix = request.getParameter("leix");
|
String zhouqi = request.getParameter("zhouqi");
|
String execDate = request.getParameter("execDate");
|
String beginExecDate = request.getParameter("beginExecDate");
|
|
String project_item_id = request.getParameter("project_item_id");
|
|
String customerId = request.getParameter("customerId");
|
|
String subId = request.getParameter("subId");
|
String contactsName = request.getParameter("contactsName");
|
|
String contactsTel = request.getParameter("contactsTel");
|
|
if (StringUtil.notEmpty(id)) {
|
String updateSql = "UPDATE CI_REMIND_CUSTOMER_ITEM_CYCLE SET LEIX = :leix,ZHOUQI = :zhouqi,BEGIN_EXEC_DATE = :beginExecDate,CONTACTS_NAME=:contactsName,CONTACTS_TEL=:contactsTel WHERE ID = :id ";
|
Map paramMap = new HashMap();
|
paramMap.put("leix", leix);
|
if (leix.equals("1")) {
|
paramMap.put("zhouqi", zhouqi);
|
paramMap.put("beginExecDate", beginExecDate);
|
} else if (leix.equals("2")) {
|
paramMap.put("zhouqi", null);
|
paramMap.put("beginExecDate", null);
|
}
|
paramMap.put("id", id);
|
paramMap.put("contactsName", contactsName);
|
paramMap.put("contactsTel", contactsTel);
|
baseDao.execute(updateSql, paramMap);
|
} else {
|
String insertSql = "INSERT INTO CI_REMIND_CUSTOMER_ITEM_CYCLE(ID,PROJECT_ITEM_ID,LEIX,ZHOUQI,BEGIN_EXEC_DATE,CUSTOMER_ID,SUB_CUSTOMER_ID,CONTACTS_NAME,CONTACTS_TEL) VALUES (:id,:project_item_id,:leix,:zhouqi,:begin_exec_date,:customer_id,:sub_customer_id,:contactsName,:contactsTel)";
|
Map paramMap = new HashMap();
|
id = StringUtil.getUUID();
|
paramMap.put("id", id);
|
paramMap.put("project_item_id", project_item_id);
|
paramMap.put("leix", leix);
|
if (leix.equals("1")) {
|
paramMap.put("zhouqi", zhouqi);
|
paramMap.put("begin_exec_date", beginExecDate);
|
} else if (leix.equals("2")) {
|
paramMap.put("zhouqi", null);
|
paramMap.put("begin_exec_date", null);
|
}
|
paramMap.put("customer_id", customerId);
|
if (StringUtil.notEmpty(subId)) {
|
paramMap.put("sub_customer_id", subId);
|
} else {
|
paramMap.put("sub_customer_id", customerId);
|
}
|
paramMap.put("contactsName", contactsName);
|
paramMap.put("contactsTel", contactsTel);
|
baseDao.execute(insertSql, paramMap);
|
}
|
|
// 删除未执行的例行维护计划
|
deleteRemindTask(project_item_id, customerId, subId);
|
|
// 新增新的计划
|
createRemindTask(id, project_item_id, customerId, subId);
|
|
return true;
|
}
|
|
@Override
|
public Map queryRemind(String customerItemId) {
|
String selectSql = "SELECT A.ID,A.ITEM_NAME,A.CYCLE,A.PRIORITY_LEVEL_ID,"
|
+ " A.PRIORITY_LEVEL_NAME,A.ITEM_NOTE,A.ORDER_NUM,A.STATE,A.BUSINESS_ID,"
|
+ " A.BUSINESS_NAME,A.ITEM_TYPE,B.ID AS CUSTOMER_ITEM_ID,B.CUSTOMER_ID "
|
+ " FROM CI_REMIND_ITEM A,CI_REMIND_CUSTOMER_ITEM B WHERE A.ID = B.ITEM_ID AND B.ID = :id ";
|
Map item = baseDao.queryForMap(selectSql, new SqlParameter("id", customerItemId));
|
return item;
|
}
|
|
/**
|
* 查询执行计划
|
*
|
* @param customerItemId
|
* @param customerId
|
* @param subCustomerId
|
* @return
|
*/
|
@Override
|
public List queryItemPlan(String customerItemId, String customerId, String subCustomerId) {
|
List result = new ArrayList();
|
if (StringUtil.notEmpty(customerId)) {
|
SC_PARTNER_CUSTOMER_INFO customer = new SC_PARTNER_CUSTOMER_INFO(customerId).getInstanceById();
|
|
long beginTime = customer.getValid_begin_date();
|
long endTime = customer.getValid_end_date();
|
|
Map paramMap = new HashMap();
|
// 查询所有已经生成的计划
|
String selectSql = "SELECT * FROM CI_REMIND_TIMERTASK WHERE CUSTOMER_ITEM_ID = :customerItemId AND CUSTOMER_ID = :customerId ";
|
paramMap.put("customerId", customerId);
|
paramMap.put("customerItemId", customerItemId);
|
selectSql += " AND SUB_CUSTOMER_ID = :subId ";
|
if (StringUtil.notEmpty(subCustomerId)) {
|
paramMap.put("subId", subCustomerId);
|
} else {
|
paramMap.put("subId", customerId);
|
}
|
|
selectSql += " ORDER BY PLAN_EXECUTION_DATE ";
|
List<Map> plans = baseDao.queryForList(selectSql, paramMap);
|
|
Map<String, Map> cacheMap = new HashMap<String, Map>();
|
if (null != plans && plans.size() > 0) {
|
for (Map plan : plans) {
|
String day = ConvertUtil.obj2StrBlank(plan.get("PLAN_EXECUTION_DATE"));
|
cacheMap.put(day, plan);
|
}
|
}
|
|
// 求出所有月份的集合
|
List<String> months = DateUtil.getBetweenTwoDateCycleList(ConvertUtil.obj2StrBlank(beginTime),
|
ConvertUtil.obj2StrBlank(endTime), 1, 1, "yyyyMMdd", "yyyyMM");
|
if (null != months && months.size() > 0) {
|
for (int i = 0; i < months.size(); i++) {
|
String month = months.get(i);
|
|
String beginDay = month + "01";
|
// 得到当月的最后一天
|
String lastDay = DateParepareUtil.lastDayMonth(month, "yyyyMM", "yyyyMMdd");
|
|
List<String> days = DateUtil.getBetweenTwoDateCycleList(beginDay, lastDay, 2, 1, "yyyyMMdd",
|
"yyyyMMdd");
|
|
List<Map> newList = new ArrayList<Map>();
|
for (String str : days) {
|
Map map = new HashMap();
|
|
if (cacheMap.containsKey(str)) {
|
map = cacheMap.get(str);
|
map.put("day", str);
|
map.put("check", 1);
|
} else {
|
map.put("day", str);
|
map.put("check", 2);
|
}
|
|
// 是否显示复选框
|
long date = ConvertUtil.obj2Long(str);
|
if (date >= beginTime && date <= endTime) {
|
map.put("showbox", 1);
|
} else {
|
map.put("showbox", 2);
|
}
|
|
// 今天之前的复选框不可用
|
long today = DateUtil.getCurrentDate8();
|
if (date > today) {
|
map.put("isUse", 1);
|
} else {
|
map.put("isUse", 2);
|
}
|
|
newList.add(map);
|
}
|
|
Map map = new HashMap();
|
map.put("month", month);
|
map.put("days", newList);
|
result.add(map);
|
}
|
}
|
|
}
|
System.out.println(JsonUtil.list2Json(result));
|
return result;
|
}
|
|
@Override
|
public boolean saveRemindItemPlan(Map<String, String> param, String[] days) {
|
String customerItemId = param.get("customerItemId");
|
String customerId = param.get("customerId");
|
String subId = param.get("subId");
|
System.out.println(days);
|
|
// 删除未执行的例行维护计划表
|
deleteRemindTask(customerItemId, customerId, subId);
|
|
// 通过传进来的日期,生成新的执行计划表
|
if (null != days && days.length > 0) {
|
String insertSql = "INSERT INTO CI_REMIND_TIMERTASK(ID,CUSTOMER_ITEM_ID,STATE,PLAN_EXECUTION_DATE,CUSTOMER_ID,SUB_CUSTOMER_ID) VALUES (:id,:customer_item_id,1,:plan_execution_date,:customer_id,:sub_customer_id)";
|
List<SqlParameter> paramList = new ArrayList<SqlParameter>();
|
param.put("customer_id", customerId);
|
param.put("customer_item_id", customerItemId);
|
if (StringUtil.isNotBlank(subId)) {
|
param.put("sub_customer_id", subId);
|
} else {
|
param.put("sub_customer_id", customerId);
|
}
|
for (String day : days) {
|
SqlParameter sqlParameter = new SqlParameter();
|
sqlParameter.put("id", StringUtil.getUUID());
|
sqlParameter.put("plan_execution_date", day);
|
sqlParameter.putAll(param);
|
paramList.add(sqlParameter);
|
}
|
baseDao.executeBatch(insertSql, paramList);
|
}
|
|
return true;
|
}
|
|
@Override
|
public List getSubRemindCiList(Map<String, String> param) {
|
String itemId = param.get("itemId");
|
String subId = param.get("subId");
|
String customerId = param.get("customerId");
|
StringBuilder sql = new StringBuilder();
|
sql.append(
|
"SELECT A.*,B.STATE,B.PROJECT_ITEM_ID FROM cmdb_ci_base A ,CI_REMIND_CILIST B ,CI_REMIND_CUSTOMER_ITEM C");
|
sql.append(" WHERE A.ID=B.CI_ID AND B.PROJECT_ITEM_ID=C.ID AND B.PROJECT_ITEM_ID=:itemId AND B.STATE=1 AND A.STATE=1");
|
// SqlParameter params=new SqlParameter();
|
// if(StringUtil.notEmpty(subId)){
|
sql.append(" AND A.SUB_CUS_ID=:subId");
|
// }else{
|
// sql.append(" AND A.CUS_ID=:customerId");
|
// }
|
param.put("itemId", itemId);
|
param.put("subId", subId);
|
param.put("customerId", customerId);
|
return baseDao.queryForList(sql.toString(), param);
|
}
|
|
@Override
|
public PageInfo getSubCheckCiList(PageInfo pageInfo, Map<String, String> param) {
|
String itemId = param.get("itemId");
|
String customerId = param.get("customerId");
|
String subId = param.get("subId");
|
if (!StringUtil.notEmpty(subId)) {
|
subId = customerId;
|
}
|
String ciName = param.get("ciName");
|
String cateId = param.get("cateId");
|
String categoryId = param.get("categoryId");
|
String code = param.get("code");
|
StringBuilder sql = new StringBuilder();
|
sql.append("SELECT * FROM cmdb_ci_base A ");
|
sql.append(" WHERE A.SUB_CUS_ID=:subId AND A.STATE=1 AND A.ID");
|
sql.append(" NOT IN(SELECT A.ID FROM cmdb_ci_base A ,CI_REMIND_CILIST B ,CI_REMIND_CUSTOMER_ITEM C ");
|
sql.append("WHERE A.ID=B.CI_ID AND B.PROJECT_ITEM_ID=C.ID AND B.PROJECT_ITEM_ID=:itemId)");
|
if (StringUtil.notEmpty(ciName)) {
|
sql.append(" AND A.CINAME LIKE :ciName");
|
}
|
if(StringUtil.notEmpty(code)){
|
sql.append(" AND A.SEARCHCODE LIKE :code");
|
}
|
// if(StringUtil.notEmpty(cateId)){
|
// sql.append(" AND A.LV3_ID = :cateId");
|
// }
|
if (StringUtil.notEmpty(subId)) {
|
sql.append(" AND A.SUB_CUS_ID=:subId");
|
} else {
|
sql.append(" AND A.CUS_ID=:customerId");
|
}
|
if (StringUtil.notEmpty(categoryId)) {
|
sql.append(" AND ( A.LV3_ID=:categoryId OR A.LV2_ID=:categoryId )");
|
}
|
sql.append(" GROUP BY A.ID");
|
// SqlParameter param=new SqlParameter();
|
|
param.put("itemId", itemId);
|
param.put("subId", subId);
|
param.put("customerId", customerId);
|
param.put("ciName", "%" + ciName + "%");
|
param.put("code", "%" + code + "%");
|
param.put("cateId", cateId);
|
|
param.put("itemId", itemId);
|
param.put("subId", subId);
|
param.put("customerId", customerId);
|
param.put("ciName", "%" + ciName + "%");
|
param.put("categoryId", categoryId);
|
|
pageInfo = baseDao.queryforSplitPageInfo(pageInfo, sql.toString(), param);
|
|
return pageInfo;
|
}
|
|
@Override
|
public Integer getSubCheckCiCount(Map<String, String> param) {
|
String itemId = param.get("itemId");
|
String subId = param.get("subId");
|
String ciName = param.get("ciName");
|
String code = param.get("code");
|
String customerId = param.get("customerId");
|
String categoryId = param.get("categoryId");
|
StringBuilder sql = new StringBuilder();
|
sql.append("SELECT count(*) FROM cmdb_ci_base A ");
|
sql.append(" WHERE A.SUB_CUS_ID=:subId AND A.STATE=1 AND A.ID");
|
sql.append(" NOT IN(SELECT A.ID FROM cmdb_ci_base A ,CI_REMIND_CILIST B ,CI_REMIND_CUSTOMER_ITEM C ");
|
sql.append("WHERE A.ID=B.CI_ID AND B.PROJECT_ITEM_ID=C.ID AND B.PROJECT_ITEM_ID=:itemId) ");
|
if (StringUtil.notEmpty(ciName)) {
|
sql.append(" AND A.CINAME LIKE :ciName");
|
}
|
if(StringUtil.notEmpty(code)){
|
sql.append(" AND A.SEARCHCODE LIKE :code");
|
}
|
if (StringUtil.notEmpty(subId)) {
|
sql.append(" AND A.SUB_CUS_ID=:subId");
|
} else {
|
sql.append(" AND A.CUS_ID=:customerId");
|
}
|
if (StringUtil.notEmpty(categoryId)) {
|
sql.append(" AND A.LV3_ID=:categoryId");
|
}
|
param.put("itemId", itemId);
|
param.put("subId", subId);
|
param.put("customerId", customerId);
|
param.put("ciName", "%" + ciName + "%");
|
param.put("code", "%" + code + "%");
|
param.put("categoryId", categoryId);
|
return baseDao.queryForInteger(sql.toString(), param);
|
}
|
|
@Override
|
public String saveSubCi(Map<String, String> param) {
|
String itemId = param.get("itemId");
|
String item = param.get("item");
|
if (StringUtil.notEmpty(itemId) && StringUtil.notEmpty(item)) {
|
String[] items = item.split(",");
|
String insertSql = "INSERT INTO CI_REMIND_CILIST(ID,PROJECT_ITEM_ID,CI_ID,STATE) VALUES (:id,:itemId,:item,1)";
|
List<SqlParameter> paramList = new ArrayList<SqlParameter>();
|
for (String str : items) {
|
if (StringUtil.notEmpty(str)) {
|
SqlParameter sqlParameter = new SqlParameter();
|
sqlParameter.put("id", StringUtil.getUUID());
|
sqlParameter.put("itemId", itemId);
|
sqlParameter.put("item", str);
|
paramList.add(sqlParameter);
|
}
|
}
|
baseDao.executeBatch(insertSql, paramList);
|
return "1";
|
}
|
return "2";
|
}
|
|
/**
|
* 禁用/启用设备
|
*/
|
@Override
|
public void deleteSubRemindCi(Map<String, String> param) {
|
String ciId = param.get("ciId");
|
String type = param.get("type");
|
String itemId = param.get("itemId");
|
String sql = "DELETE FROM CI_REMIND_CILIST WHERE CI_ID=:ciId AND PROJECT_ITEM_ID=:itemId";
|
baseDao.execute(sql,
|
new SqlParameter().addValue("ciId", ciId).addValue("type", type).addValue("itemId", itemId));
|
|
}
|
|
/**
|
* 定时生成例行维护工单
|
*/
|
@Override
|
public boolean saveRemindOrder() {
|
|
long today = DateUtil.getCurrentDate8();
|
long nextWeek = DateUtil.getDateAdd(today, 7, 8);
|
// 查询一周内需要生成的工单
|
String selectSql = "SELECT C.ITEM_NAME,C.ITEM_NOTE,A.*,B.ID AS CUSTOMER_ITEM_NUM,B.ITEM_ID,C.BUSINESS_ID "
|
+ " FROM CI_REMIND_TIMERTASK A,CI_REMIND_CUSTOMER_ITEM B,CI_REMIND_ITEM C "
|
+ " WHERE A.CUSTOMER_ITEM_ID = B.ID AND B.ITEM_ID = C.ID "
|
+ " AND B.USING_STATE = 1 AND A.STATE = :state "
|
+ " AND A.PLAN_EXECUTION_DATE >=:today AND A.PLAN_EXECUTION_DATE<:nextWeek ";
|
Map paramMap = new HashMap();
|
paramMap.put("state", Constants.CI_REMIND_TIMERTASK_STATE_WZX);
|
paramMap.put("today", today);
|
paramMap.put("nextWeek", nextWeek);
|
List<Map> tasks = baseDao.queryForList(selectSql, paramMap);
|
|
long createTime = DateUtil.getCurrentDate14();
|
// 循环启动流程
|
if (null != tasks && tasks.size() > 0) {
|
List<SqlParameter> backParam = new ArrayList<SqlParameter>();
|
for (Map task : tasks) {
|
String customerId = ConvertUtil.obj2StrBlank(task.get("CUSTOMER_ID"));
|
if (StringUtil.notEmpty(customerId)) {
|
String remind_id = ConvertUtil.obj2StrBlank(task.get("ITEM_ID"));
|
|
String subCustomerId = ConvertUtil.obj2StrBlank(task.get("SUB_CUSTOMER_ID"));
|
|
SC_PARTNER_CUSTOMER_INFO customer = new SC_PARTNER_CUSTOMER_INFO(customerId).getInstanceById();
|
String customerName = customer.getCustomer_name();
|
|
String insertSql = "INSERT INTO SC_WORKFLOW_CI_REMIND(ID,ORDER_CODE,NAME,CUSTOMER_ID,CUSTOMER_NAME,CREATE_TIME,STATE,REMIND_ID,SUB_CUSTOMER_ID,SUB_CUSTOMER_NAME,CONTACTS_NAME,CONTACTS_TEL,SERVICE_CONTENT) "
|
+ "VALUES (:id,:order_code,:name,:customer_id,:customer_name,:create_time,1,:remind_id,:sub_customer_id,:sub_customer_name,:contacts_name,:contacts_tel,:item_note)";
|
Map param = new HashMap();
|
String orderId = StringUtil.getUUID();
|
param.put("id", orderId);
|
String orderCode = workOrderCodeService.getCiRemindOrderCode();
|
param.put("order_code", orderCode);
|
param.put("customer_id", customerId);
|
param.put("customer_name", customerName);
|
param.put("create_time", createTime);
|
|
param.put("remind_id", remind_id);
|
param.put("name", "例行维护-" + ConvertUtil.obj2StrBlank(task.get("ITEM_NAME")));
|
param.put("item_note", ConvertUtil.obj2StrBlank(task.get("ITEM_NOTE")));
|
|
if (StringUtil.notEmpty(subCustomerId)) {
|
param.put("sub_customer_id", subCustomerId);
|
// 如果客户编号与所属单位编号一致,说明为客户本身,修改人:杨凯
|
if (StringUtils.equalsIgnoreCase(customerId, subCustomerId)) {
|
param.put("sub_customer_name",
|
new SC_PARTNER_CUSTOMER_INFO(subCustomerId).getInstanceById().getCustomer_name());
|
} else {
|
param.put("sub_customer_name",
|
new SC_PARTNER_CUSTOMER_SUB(subCustomerId).getInstanceById().getCustomer_name());
|
}
|
}
|
|
String sql = "SELECT * FROM CI_REMIND_CUSTOMER_ITEM_CYCLE WHERE PROJECT_ITEM_ID=:customer_item_id AND SUB_CUSTOMER_ID=:subId";
|
// 获取周期联系人/联系方式
|
Map cycle = baseDao.queryForMap(sql,
|
new SqlParameter().addValue("customer_item_id", task.get("CUSTOMER_ITEM_NUM"))
|
.addValue("subId", subCustomerId));
|
param.put("contacts_name", cycle.get("CONTACTS_NAME"));
|
param.put("contacts_tel", cycle.get("CONTACTS_TEL"));
|
baseDao.execute(insertSql, param);
|
|
Map pm = new HashMap();
|
// 查询该维护项对应客户指定的设备
|
String ciSql = "SELECT A.* FROM CI_REMIND_CILIST A,CMDB_CI_BASE B WHERE A.CI_ID = B.ID AND A.STATE = 1 AND A.PROJECT_ITEM_ID = :customerItemId AND B.CUS_ID = :customerId ";
|
ciSql += " AND B.SUB_CUS_ID = :subCustomerId ";
|
if (StringUtil.isBlank(subCustomerId)) {
|
pm.put("subCustomerId", customerId);
|
} else {
|
pm.put("subCustomerId", subCustomerId);
|
}
|
|
pm.put("customerItemId", task.get("CUSTOMER_ITEM_ID"));
|
pm.put("customerId", customerId);
|
List<Map> devices = baseDao.queryForList(ciSql, pm);
|
|
if (null != devices && devices.size() > 0) {
|
String insertDeviceSql = "INSERT INTO SC_WORKFLOW_CI_REMIND_DETAIL(ID,ORDER_ID,CI_ID,DEAL_STATE) VALUES (:id,:order_id,:ci_id,3)";
|
List<SqlParameter> deviceParam = new ArrayList<SqlParameter>();
|
for (Map device : devices) {
|
SqlParameter sqlParameter = new SqlParameter();
|
sqlParameter.put("id", StringUtil.getUUID());
|
sqlParameter.put("order_id", orderId);
|
sqlParameter.put("ci_id", device.get("CI_ID"));
|
deviceParam.add(sqlParameter);
|
}
|
baseDao.executeBatch(insertDeviceSql, deviceParam);
|
}
|
|
// ====================================
|
// 启动流程
|
startRemindFlow(orderId, customerId);
|
SC_WORKFLOW_CI_REMIND remind = new SC_WORKFLOW_CI_REMIND(orderId).getInstanceById();
|
|
// ===================================
|
|
// 回填执行计划信息
|
String taskId = ConvertUtil.obj2StrBlank(task.get("ID"));
|
|
SqlParameter sqlParameter = new SqlParameter();
|
sqlParameter.put("id", taskId);
|
sqlParameter.put("state", Constants.CI_REMIND_TIMERTASK_STATE_YZX);
|
|
sqlParameter.put("create_time", createTime);
|
sqlParameter.put("flow_id", remind.getFlow_id());
|
backParam.add(sqlParameter);
|
}
|
}
|
|
if (backParam.size() > 0) {
|
String updateSql = "UPDATE CI_REMIND_TIMERTASK SET STATE = :state,CREATE_TIME = :create_time,FLOW_ID = :flow_id WHERE ID = :id";
|
baseDao.executeBatch(updateSql, backParam);
|
}
|
}
|
|
return true;
|
}
|
|
private SysInfoMsg startRemindFlow(String orderId, String customerId) {
|
// 启动流程
|
WorkFlowSupportEntity support = new WorkFlowSupportEntity();
|
support.setOrderId(orderId);
|
support.setNextNodeTemplateId(Constants.REMIND_DISPATCH);
|
support.setWorkFlowType(Constants.WORKFLOW_BASE_BUSINESS_TYPE_CI_REMIND);
|
|
String sql = "SELECT YWJL_ID USER_ID,YWJL_NAME USER_NAME,1 AS IS_ADMIN FROM SC_PARTNER_CUSTOMER_INFO WHERE ID=:customerId ";
|
|
List<Map> list = new ArrayList<Map>();
|
Map map = baseDao.queryForMap(sql, new SqlParameter("customerId", customerId));
|
|
list.add(map);
|
support.setNextUserList(list);
|
SysInfoMsg msg = workFlowSupportService.doOrderFlow(support);
|
return msg;
|
}
|
|
@Override
|
public PageInfo getCiRemindOrderData(PageInfo pageInfo, Map<String, String> params) {
|
Map support = geCiRemindOrderSupport(params);
|
String sql = support.get("sql").toString();
|
return baseDao.queryforSplitPageInfo(pageInfo, sql, params);
|
}
|
|
@Override
|
public Integer getCiRemindOrderCount(Map<String, String> params) {
|
Map support = geCiRemindOrderSupport(params);
|
String sql = "select count(*) from ( " + support.get("sql").toString() + " ) t ";
|
return baseDao.queryForInteger(sql, params);
|
}
|
|
private Map geCiRemindOrderSupport(Map<String, String> params) {
|
Map<String, Object> support = new HashMap<String, Object>();
|
StringBuilder sql = new StringBuilder();
|
sql.append(" SELECT A.*,B.ORDER_CODE,B.NAME,B.STATE,B.CUSTOMER_NAME,B.CREATE_TIME,B.ID AS BUSINESS_ID ");
|
sql.append(" FROM SC_WORKFLOW_CI_REMIND_DETAIL A,SC_WORKFLOW_CI_REMIND B WHERE A.ORDER_ID = B.ID ");
|
sql.append(" AND A.CI_ID = :id ORDER BY START_TIME DESC ");
|
support.put("sql", sql.toString());
|
support.put("param", params);
|
return support;
|
}
|
|
@Override
|
public void delRemindItem(Map params) {
|
String sql = "update ci_remind_customer_item set using_state = :statu where id=:id ";
|
baseDao.execute(sql, params);
|
}
|
|
}
|