Commit 3420618f authored by xixinzhao's avatar xixinzhao

计划生成任务

parent b7bedffb
......@@ -243,10 +243,16 @@ public class Plan extends BasicEntity {
//单位code
@Column(name = "biz_org_code")
private String bizOrgCode;
//单位名称
@Column(name = "biz_org_name")
private String bizOrgName;
/**
* 用户组id
*/
@Column(name = "user_group_id")
private String userGroupId;
public String getBizOrgCode() {
return bizOrgCode;
......@@ -614,4 +620,12 @@ public class Plan extends BasicEntity {
public void setIsSingleExecution(boolean isSingleExecution) {
this.isSingleExecution = isSingleExecution;
}
public String getUserGroupId() {
return userGroupId;
}
public void setUserGroupId(String userGroupId) {
this.userGroupId = userGroupId;
}
}
\ No newline at end of file
......@@ -12,13 +12,13 @@ import java.util.List;
@Repository("iRoutePointDao")
public interface IRoutePointDao extends BaseDao<RoutePoint, Long> {
@Query(value = "SELECT COUNT( point_id ) FROM `p_route_point` where route_id = ?1", nativeQuery = true)
@Query(value = "SELECT COUNT( point_id ) FROM p_route_point where route_id = ?1", nativeQuery = true)
int countRoutePoint(Long routeId);
@Query(value = "SELECT * FROM `p_route_point` where point_id = ?1", nativeQuery = true)
@Query(value = "SELECT * FROM p_route_point where point_id = ?1", nativeQuery = true)
List<RoutePoint> queryByPointId(Long pointId);
@Query(value = "SELECT IfNULL(max(order_no),0) FROM `p_route_point` where route_id = ?1", nativeQuery = true)
@Query(value = "SELECT IfNULL(max(order_no),0) FROM p_route_point where route_id = ?1", nativeQuery = true)
int maxRoutePointOrderNo(Long routeId);
@Modifying
......@@ -32,7 +32,7 @@ public interface IRoutePointDao extends BaseDao<RoutePoint, Long> {
@Query(value = "delete from p_route_point WHERE point_id = ?1", nativeQuery = true)
void delRoutePointByPointId(Long pointId);
@Query(value = "SELECT DISTINCT point_id FROM `p_route_point` where route_id = ?1", nativeQuery = true)
@Query(value = "SELECT DISTINCT point_id FROM p_route_point where route_id = ?1", nativeQuery = true)
List<Long> queryRoutePointIds(Long routeId);
@Modifying
......@@ -59,7 +59,7 @@ public interface IRoutePointDao extends BaseDao<RoutePoint, Long> {
@Query(value = "SELECT id FROM p_route_point WHERE point_id IN (?1)", nativeQuery = true)
List<BigInteger> queryRoutePointByPointId(List<Long> pointIds);
@Query(value = "SELECT DISTINCT point_id FROM `p_route_point` where route_id = ?1", nativeQuery = true)
@Query(value = "SELECT DISTINCT point_id FROM p_route_point where route_id = ?1", nativeQuery = true)
List<String> getRoutePointIds(String routeId);
int deleteByRouteIdAndPointIdInAndIdNotIn(Long targetRouteId, List<Long> targetPointIds, List<Long> ids);
......
package com.yeejoin.amos.patrol.business.dto;
import lombok.Data;
/**
* @author DELL
*/
@Data
public class UserDetailsDto {
/**
* 企业id
*/
private String unitId;
/**
* 企业类型
*/
private String unitType;
/**
* 企业类型Code
*/
private String unitTypeCode;
/**
* 企业名称
*/
private String unitName;
/**
* 企业名称
*/
private String unitCode;
/**
* 用户id
*/
private String userId;
/**
* 用户名称
*/
private String userName;
/**
* 设备类型
*/
private String equipCategory;
/**
* 设备类型code
*/
private String equipCategoryCode;
/**
* 执行对象id
*/
private String groupId;
/**
* 执行对象
*/
private String groupName;
}
package com.yeejoin.amos.patrol.business.feign;
import com.yeejoin.amos.component.feign.model.FeignClientResult;
import com.yeejoin.amos.patrol.business.dto.UserDetailsDto;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.typroject.tyboot.core.restful.utils.ResponseModel;
import java.util.List;
/**
* @author DELL
*/
@FeignClient(name = "${tzs.feign.name}", path = "tcm", configuration = {FeignConfiguration.class})
public interface TzsFeign {
/**
* 根据用户组id获取用户
* @param groupId 用户组id
* @return
*/
@RequestMapping(value = "/userInfo/getGroupAndPersonInfo", method = RequestMethod.GET ,consumes="application/json")
ResponseModel<List<UserDetailsDto>> getGroupAndPersonInfo(@RequestParam(value = "groupId", required = false) Long groupId);
}
......@@ -19,12 +19,10 @@ import com.yeejoin.amos.patrol.business.dao.mapper.PlanTaskDetailMapper;
import com.yeejoin.amos.patrol.business.dao.mapper.PlanTaskMapper;
import com.yeejoin.amos.patrol.business.dao.repository.*;
import com.yeejoin.amos.patrol.business.dto.MsgRo;
import com.yeejoin.amos.patrol.business.dto.UserDetailsDto;
import com.yeejoin.amos.patrol.business.entity.mybatis.CheckChkExListBo;
import com.yeejoin.amos.patrol.business.entity.mybatis.PointCheckDetailBo;
import com.yeejoin.amos.patrol.business.feign.Business;
import com.yeejoin.amos.patrol.business.feign.EquipFeign;
import com.yeejoin.amos.patrol.business.feign.IdxFeign;
import com.yeejoin.amos.patrol.business.feign.JcsFeignClient;
import com.yeejoin.amos.patrol.business.feign.*;
import com.yeejoin.amos.patrol.business.param.CheckPtListPageParam;
import com.yeejoin.amos.patrol.business.param.PlanTaskPageParam;
import com.yeejoin.amos.patrol.business.service.intfc.ICheckService;
......@@ -43,10 +41,7 @@ import com.yeejoin.amos.patrol.core.enums.DefectLevelEnum;
import com.yeejoin.amos.patrol.core.enums.WordTemplateEnum;
import com.yeejoin.amos.patrol.core.util.DateUtil;
import com.yeejoin.amos.patrol.core.util.StringUtil;
import com.yeejoin.amos.patrol.dao.entity.Check;
import com.yeejoin.amos.patrol.dao.entity.Plan;
import com.yeejoin.amos.patrol.dao.entity.PlanTask;
import com.yeejoin.amos.patrol.dao.entity.PlanTaskDetail;
import com.yeejoin.amos.patrol.dao.entity.*;
import com.yeejoin.amos.patrol.exception.YeeException;
import com.yeejoin.amos.patrol.feign.RemoteSecurityService;
import com.yeejoin.amos.patrol.quartz.IJobService;
......@@ -68,6 +63,7 @@ import org.springframework.web.multipart.MultipartFile;
import org.typroject.tyboot.core.foundation.context.RequestContext;
import org.typroject.tyboot.core.foundation.utils.ValidationUtil;
import org.typroject.tyboot.core.restful.exception.instance.BadRequest;
import org.typroject.tyboot.core.restful.utils.ResponseModel;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
......@@ -108,6 +104,9 @@ public class PlanTaskServiceImpl implements IPlanTaskService {
IRoutePointDao iRoutePointDao;
@Autowired
IRouteDao routeDao;
@Autowired
IJobService jobService;
@Autowired
......@@ -134,6 +133,9 @@ public class PlanTaskServiceImpl implements IPlanTaskService {
@Autowired
private IdxFeign idxFeign;
@Autowired
private TzsFeign tzsFeign;
private final String PATROL_PLAN_TASK_KEY = "PATROL_PLAN_ID:";
private final String packageId = "消息/addCheckRule";
......@@ -578,7 +580,8 @@ public class PlanTaskServiceImpl implements IPlanTaskService {
//2.循环遍历执行
HashMap<String, Object> paramMap = new HashMap<String, Object>();
for (Plan plan : planList) {
if (StringUtils.isEmpty(plan.getUserId()))
// tzs修改为查询用户组id
if (StringUtils.isEmpty(plan.getUserGroupId()))
continue;
paramMap.clear();
paramMap.put("id", plan.getId());
......@@ -605,7 +608,7 @@ public class PlanTaskServiceImpl implements IPlanTaskService {
continue;
}
//2.3.执行数据生成(具体时间 + 人员)
//2.3.执行数据生成(具体时间 + 人员) tzs改为用户组
List<HashMap<String, Object>> list = genAllExeDate(plan, vo, XJConstant.SCHED_FLAG);
if (XJConstant.UPD_PLAN_GEN_DATE.equals(vo.getUpdFlag())) {
......@@ -666,8 +669,18 @@ public class PlanTaskServiceImpl implements IPlanTaskService {
vo.setUpdFlag(XJConstant.UPD_PLAN_STATUS);
}
//3.生成含有人员信息的日期执行数据
List<HashMap<String, Object>> dataList = PlanTaskUtil.genWholeExeData(timeList, plan);
return dataList;
// 获取路线中的企业类型和设备类型
// Route route = routeDao.getOne(plan.getRouteId());
Route route = new Route();
List<UserDetailsDto> userDetailsDtos = new ArrayList<>();
// 获取用户组下所有的用户信息
try{
ResponseModel<List<UserDetailsDto>> groupAndPersonInfo = tzsFeign.getGroupAndPersonInfo(Long.valueOf(plan.getUserGroupId()));
userDetailsDtos = groupAndPersonInfo.getResult();
}catch (Exception e) {
log.error(e.getMessage());
}
return PlanTaskUtil.genWholeExeData(timeList, plan, userDetailsDtos, route);
}
......@@ -688,24 +701,12 @@ public class PlanTaskServiceImpl implements IPlanTaskService {
}
// Toke toke = remoteSecurityService.getServerToken();
Map<String, String> deptMap = new HashMap<>();
Map<String, Object> nameMap = new HashMap<>();
try {
String isFixDate = plan.getIsFixedDate();// 是否固定日期
List<Long> pointIdList = iRoutePointDao.queryRoutePointIds(plan.getRouteId());
int pointNum = iRoutePointDao.countRoutePoint(plan.getRouteId());
long batchNo = now.getTime();
// List<AgencyUserModel> agencyUserModels = remoteSecurityService.listUserByUserIds(toke.getToke(), toke.getProduct(), toke.getAppKey(),
// plan.getUserId());
FeignClientResult<List<Map<String, Object>>> agencyUserModelsDate= jcsFeignClient.selectByAmosOrgIdDeptList(plan.getUserId());
List<Map<String, Object>> agencyUserModels = agencyUserModelsDate.getResult();
for (int i = 0; i < agencyUserModels.size(); i++) {
//遍历获取orgcode
nameMap.put(agencyUserModels.get(i).get("amosOrgId").toString(), agencyUserModels.get(i).get("bizOrgName"));
}
Set<String> departmentIds = new HashSet<>();
List<String> depts = Arrays.asList(plan.getUserDept().split(","));
depts.stream().forEach(dept -> {
......@@ -721,26 +722,7 @@ public class PlanTaskServiceImpl implements IPlanTaskService {
while (it.hasNext()) {
departmentIdBuffer.append(it.next()).append(",");
}
Map<String, String> orgCodeMap = new HashMap<>();
if (departmentIds.size() > 0) {
// List<DepartmentModel> departmentModels = remoteSecurityService.getlistDepartmentByDeptIds(
// toke.getToke(), toke.getProduct(), toke.getAppKey(),
// departmentIdBuffer.toString().substring(0, departmentIdBuffer.toString().length() - 1));
FeignClientResult<List<Map<String, Object>>> departmentModeldate= jcsFeignClient.selectByIdDeptList(departmentIdBuffer.toString().substring(0, departmentIdBuffer.toString().length() - 1));
List<Map<String, Object>> departmentModels = departmentModeldate.getResult();
for (String key : deptMap.keySet()) {
String entryValue = deptMap.get(key);
for (Map<String, Object> departmentModel : departmentModels) {
if (entryValue.equals(departmentModel.get("sequenceNbr").toString())) {
orgCodeMap.put(key, departmentModel.get("bizOrgCode").toString());
}
}
}
}
List<PlanTask> planTaskList = new ArrayList<>();
List<PlanTaskDetail> planTaskDetailListSync = new ArrayList<>();
......@@ -750,6 +732,9 @@ public class PlanTaskServiceImpl implements IPlanTaskService {
String endTime = list.get(i).get("END_TIME").toString();
String userId = list.get(i).get("USER_ID") == null ? "-1" : list.get(i).get("USER_ID").toString();
String userDept = list.get(i).get("USER_DEPT") == null ? "-1" : list.get(i).get("USER_DEPT").toString();
String userName = list.get(i).get("USER_NAME") == null ? "-1" : String.valueOf(list.get(i).get("USER_NAME"));
String orgCode = list.get(i).get("ORG_CODE") == null ? "-1" : String.valueOf(list.get(i).get("ORG_CODE"));
PlanTask planTask = iplanTaskDao.findByUserIdAndBeginTimeAndEndTimeAndPlanIdAndRouteId(userId, startTime, endTime, plan.getId(), plan.getRouteId());
if (planTask != null) {
continue;
......@@ -757,25 +742,8 @@ public class PlanTaskServiceImpl implements IPlanTaskService {
planTask = new PlanTask();
//修改巡检p_plan_task orgcode为执行人的org_code -- add by wujunkai 20201216
if (plan.getUserDept().indexOf(",") > 0 && plan.getIsSingleExecution() != true) {
Set<String> orgCodes = new HashSet<>();
StringBuffer nameBuffer = new StringBuffer();
orgCodeMap.forEach((key, entryValue) -> {
orgCodes.add(entryValue);
});
for (Map.Entry<String, Object> entry : nameMap.entrySet()) {
String entryValue = entry.getValue().toString();
nameBuffer.append(entryValue).append(",");
}
planTask.setOrgCode(orgCodes.toString().substring(1, orgCodes.toString().length() - 1));
planTask.setUserName(nameBuffer.toString().substring(0, nameBuffer.toString().length() - 1));
} else {
planTask.setOrgCode(orgCodeMap.get(userId));
planTask.setUserName(nameMap.get(userId).toString());
}
planTask.setOrgCode(orgCode);
planTask.setUserName(userName);
planTask.setPlanId(plan.getId());
planTask.setBatchNo(batchNo);
planTask.setRouteId(plan.getRouteId());
......@@ -862,14 +830,14 @@ public class PlanTaskServiceImpl implements IPlanTaskService {
}
planMapper.updPlanStatusOrGenDate(paramMap);// 更新下次任务生成日期
// 巡检站端与中心级数据同步
TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronization() {
@Override
public void afterCommit() {
// 事物提交后业务逻辑
patrolDataSyncService.planTaskDataSync(planTaskList);
patrolDataSyncService.planTaskDetailDataSync(planTaskDetailListSync);
}
});
// TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronization() {
// @Override
// public void afterCommit() {
// // 事物提交后业务逻辑
// patrolDataSyncService.planTaskDataSync(planTaskList);
// patrolDataSyncService.planTaskDetailDataSync(planTaskDetailListSync);
// }
// });
} catch (Exception e) {
log.error(e.getMessage(), e);
throw new RuntimeException(e.getMessage());
......
package com.yeejoin.amos.patrol.business.util;
import com.yeejoin.amos.patrol.business.constants.XJConstant;
import com.yeejoin.amos.patrol.business.dto.UserDetailsDto;
import com.yeejoin.amos.patrol.business.vo.CalDateVo;
import com.yeejoin.amos.patrol.core.util.DateUtil;
import com.yeejoin.amos.patrol.core.util.StringUtil;
import com.yeejoin.amos.patrol.dao.entity.Plan;
import com.yeejoin.amos.patrol.dao.entity.Route;
import com.yeejoin.amos.patrol.exception.YeeException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;
public class PlanTaskUtil {
private static final Logger log = LoggerFactory.getLogger(PlanTaskUtil.class);
......@@ -503,63 +507,60 @@ private static List<HashMap<String, Object>> genTimeByRate(Plan plan,List<HashMa
* @param plan
* @return
*/
public static List<HashMap<String, Object>> genWholeExeData(List<HashMap<String, Object>> timeList, Plan plan) {
public static List<HashMap<String, Object>> genWholeExeData(List<HashMap<String, Object>> timeList, Plan plan, List<UserDetailsDto> userDetailsDtoList, Route route) {
if(timeList == null || timeList.size()<=0 ){
return null;
}
String users = plan.getUserId();
String userAndDepts = plan.getUserDept();
List<HashMap<String, Object>> wholeList = new ArrayList<HashMap<String, Object>>();
if(StringUtil.isNotEmpty(users)){
String[] userArr = users.split(",");
String[] userAndDeptArr = userAndDepts.split(",");
//IUserService userService = (IUserService) IotContext.getInstance().getBean("userService");
for(int i =0;i<timeList.size();i++){
HashMap<String, Object> tempMap = new HashMap<String, Object>();
Object strBeginTime = timeList.get(i).get("BEGIN_TIME");
Object strEndTime = timeList.get(i).get("END_TIME");
Object nextGenDate = timeList.get(i).get("NEXT_GEN_DATE");
List<HashMap<String, Object>> wholeList = new ArrayList<>();
// String deviceType = route.getDeviceType();
// String unitType = route.getUnitType();
String deviceType = "3000";
String unitType = "1232";
if (!CollectionUtils.isEmpty(userDetailsDtoList)) {
Map<String, List<UserDetailsDto>> userDetailsDtoMap = userDetailsDtoList.stream().
filter(obj -> obj.getEquipCategoryCode().contains(deviceType) && obj.getUnitTypeCode().contains(unitType))
.collect(Collectors.groupingBy(UserDetailsDto::getUnitCode));
for (HashMap<String, Object> stringObjectHashMap : timeList) {
HashMap<String, Object> tempMap = new HashMap<>();
Object strBeginTime = stringObjectHashMap.get("BEGIN_TIME");
Object strEndTime = stringObjectHashMap.get("END_TIME");
Object nextGenDate = stringObjectHashMap.get("NEXT_GEN_DATE");
tempMap.put("BEGIN_TIME", strBeginTime);
tempMap.put("END_TIME", strEndTime);
tempMap.put("NEXT_GEN_DATE", nextGenDate);
if(plan.getIsSingleExecution()){
// for(String userId : userArr){
// if (!ObjectUtils.isEmpty(userId) /*&& userService.existUser(userId)*/) {
// HashMap<String, Object> temp = null;
// temp = (HashMap<String, Object>) tempMap.clone();
// temp.put("USER_ID", userId);
// wholeList.add(temp);
// }
// }
for(String userAndDept : userAndDeptArr){
if (!ObjectUtils.isEmpty(userAndDept)) {
HashMap<String, Object> temp = null;
temp = (HashMap<String, Object>) tempMap.clone();
String userAndDeptTemp[] = userAndDept.split("@");
if(userAndDeptTemp.length >= 1){
temp.put("USER_ID", userAndDeptTemp[0]);
temp.put("USER_DEPT", userAndDept);
}else{
temp.put("USER_ID", "");
temp.put("DEPT_ID", "");
}
wholeList.add(temp);
}
List<HashMap<String, Object>> finalWholeList = wholeList;
userDetailsDtoMap.forEach((unitCode, userDetailsDto) -> {
if (!plan.getIsSingleExecution()) {
HashMap<String, Object> temp;
temp = (HashMap<String, Object>) tempMap.clone();
String userIds = userDetailsDto.stream().map(UserDetailsDto::getUserId).filter(Objects::nonNull).collect(Collectors.joining(","));
String userNames = userDetailsDto.stream().map(UserDetailsDto::getUserName).filter(Objects::nonNull).collect(Collectors.joining(","));
String userDept = userDetailsDto.stream().map(a->{
return a.getUserId() + "@" + unitCode;
}).collect(Collectors.joining(","));
temp.put("USER_ID", userIds);
temp.put("USER_NAME", userNames);
temp.put("ORG_CODE", unitCode);
temp.put("USER_DEPT", userDept);
finalWholeList.add(temp);
} else {
userDetailsDto.forEach(dto -> {
HashMap<String, Object> temp;
temp = (HashMap<String, Object>) tempMap.clone();
temp.put("USER_ID", dto.getUserId());
temp.put("USER_NAME", dto.getUserName());
temp.put("ORG_CODE", dto.getUserId() + "@" + unitCode);
finalWholeList.add(temp);
});
}
}else{
HashMap<String, Object> temp = null;
temp = (HashMap<String, Object>) tempMap.clone();
temp.put("USER_ID", users);
temp.put("USER_DEPT", userAndDepts);
wholeList.add(temp);
}
}
}else{
});
}
} else {
wholeList = timeList;
}
return wholeList;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment