|
@@ -7,31 +7,31 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
-import com.ruoyi.common.core.domain.entity.SysUser;
|
|
|
import com.ruoyi.common.enums.BusinessType;
|
|
|
import com.ruoyi.common.exception.ServiceException;
|
|
|
import com.ruoyi.common.utils.SecurityUtils;
|
|
|
import com.ruoyi.common.utils.bean.BeanUtils;
|
|
|
import com.ruoyi.system.mapper.SysUserMapper;
|
|
|
-import com.ruoyi.system.service.ISysRoleService;
|
|
|
import com.ruoyi.system.service.ISysUserService;
|
|
|
import com.ruoyi.web.domain.dto.event.EventAddRequest;
|
|
|
import com.ruoyi.web.domain.dto.event.EventEditRequest;
|
|
|
import com.ruoyi.web.domain.dto.event.EventQueryRequest;
|
|
|
import com.ruoyi.web.domain.entity.Event;
|
|
|
import com.ruoyi.web.domain.entity.EventAssign;
|
|
|
+import com.ruoyi.web.domain.entity.PersonInfo;
|
|
|
+import com.ruoyi.web.domain.vo.PersonInfoVO;
|
|
|
import com.ruoyi.web.domain.vo.event.EventVO;
|
|
|
import com.ruoyi.web.mapper.EventAssignMapper;
|
|
|
import com.ruoyi.web.mapper.EventMapper;
|
|
|
+import com.ruoyi.web.service.EventAssignService;
|
|
|
import com.ruoyi.web.service.EventService;
|
|
|
+import com.ruoyi.web.service.PersonInfoService;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import java.util.Arrays;
|
|
|
-import java.util.Collections;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
import java.util.stream.Collectors;
|
|
@@ -50,11 +50,14 @@ public class EventServiceImpl extends ServiceImpl<EventMapper, Event>
|
|
|
private ISysUserService sysUserService;
|
|
|
|
|
|
@Resource
|
|
|
- private ISysRoleService sysRoleService;
|
|
|
-
|
|
|
- @Autowired
|
|
|
private SysUserMapper sysUserMapper;
|
|
|
|
|
|
+ @Resource
|
|
|
+ private PersonInfoService personInfoService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private EventAssignService eventAssignService;
|
|
|
+
|
|
|
/**
|
|
|
* 添加事件并分配给对应负责人
|
|
|
*
|
|
@@ -71,13 +74,25 @@ public class EventServiceImpl extends ServiceImpl<EventMapper, Event>
|
|
|
// 转换为实体对象
|
|
|
Event event = new Event();
|
|
|
BeanUtil.copyProperties(eventAddRequest, event);
|
|
|
+
|
|
|
+ // 通过系统用户id 获取对应 人口表id
|
|
|
+ Long userId = SecurityUtils.getUserId();
|
|
|
+ QueryWrapper<PersonInfo> wrapper = new QueryWrapper<>();
|
|
|
+ wrapper.select("id")
|
|
|
+ .eq("user_id",userId);
|
|
|
+ List<PersonInfo> personInfoList = personInfoService.list(wrapper);
|
|
|
+ if (!personInfoList.isEmpty()) {
|
|
|
+ PersonInfo personInfo = personInfoList.get(0);
|
|
|
+ event.setSubmitterId(personInfo.getId());
|
|
|
+ } else {
|
|
|
+ event.setSubmitterId(null);
|
|
|
+ }
|
|
|
+
|
|
|
//数据校验
|
|
|
validEvent(event, BusinessType.INSERT);
|
|
|
-
|
|
|
// 保存到事件表
|
|
|
this.save(event);
|
|
|
-
|
|
|
- // 根据事件类型分配负责人
|
|
|
+ // 根据事件类型自动分配负责人
|
|
|
assignEventToPersons(event.getId(), event.getType());
|
|
|
return event.getId();
|
|
|
} catch (Exception e) {
|
|
@@ -93,7 +108,7 @@ public class EventServiceImpl extends ServiceImpl<EventMapper, Event>
|
|
|
* @param eventType 事件类型
|
|
|
*/
|
|
|
private void assignEventToPersons(Integer eventId, Integer eventType) {
|
|
|
- // 根据事件类型查找对应的负责人
|
|
|
+ // 根据事件类型查找对应的负责人 id 集合
|
|
|
List<Integer> personIds = getPersonIdsByEventType(eventType);
|
|
|
|
|
|
if (personIds.isEmpty()) {
|
|
@@ -113,8 +128,32 @@ public class EventServiceImpl extends ServiceImpl<EventMapper, Event>
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
/**
|
|
|
- * 根据事件类型获取负责人ID列表
|
|
|
+ * 根据事件类型获取负责人列表
|
|
|
+ * @param eventType
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public List<PersonInfoVO> getPersonInfoVOByEventType(Integer eventType) {
|
|
|
+ List<Integer> userIdsByEventType = getPersonIdsByEventType(eventType);
|
|
|
+ List<PersonInfoVO> personInfoVOListByUserIds = personInfoService.getPersonInfoVOListByUserIds(userIdsByEventType);
|
|
|
+ return personInfoVOListByUserIds;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+// /**
|
|
|
+// * 通过 id 获取负责人列表
|
|
|
+// * @param personIds
|
|
|
+// * @return
|
|
|
+// */
|
|
|
+// //todo
|
|
|
+// private List<SysUser> getSysUserByIdList(List<Integer> personIds) {
|
|
|
+// return sysUserMapper.selectUserListForEvent(personIds);
|
|
|
+// }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据事件类型获取负责人系统用户ID列表
|
|
|
*
|
|
|
* @param eventType 事件类型
|
|
|
* @return 负责人ID列表
|
|
@@ -140,6 +179,7 @@ public class EventServiceImpl extends ServiceImpl<EventMapper, Event>
|
|
|
return matchedUserIds;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
/**
|
|
|
* 删除
|
|
|
*
|
|
@@ -169,7 +209,6 @@ public class EventServiceImpl extends ServiceImpl<EventMapper, Event>
|
|
|
|
|
|
// 4. 执行删除(返回是否删除成功)
|
|
|
return remove(queryWrapper);
|
|
|
-
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -285,22 +324,55 @@ public class EventServiceImpl extends ServiceImpl<EventMapper, Event>
|
|
|
queryWrapper.eq("event_id", event.getId());
|
|
|
// 获取事件分配信息列表
|
|
|
List<EventAssign> eventAssigns = eventAssignMapper.selectList(queryWrapper);
|
|
|
- // 3. 提取负责人ID列表
|
|
|
+ // 3. 提取负责人 系统用户ID列表
|
|
|
List<Integer> userIds = eventAssigns.stream()
|
|
|
.map(EventAssign::getPersonId)
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
|
- // 4. 批量查询有效的用户信息
|
|
|
- List<SysUser> chargeUserList = userIds.isEmpty() ?
|
|
|
- Collections.emptyList() :
|
|
|
- sysUserMapper.selectUserListForEvent(userIds);
|
|
|
-
|
|
|
- // 实际项目中需要根据personId查询用户信息
|
|
|
+ // 4. 批量查询有效的负责人信息
|
|
|
+ List<PersonInfoVO> chargeUserList ;
|
|
|
+ if (ObjectUtil.isNotEmpty(userIds)){
|
|
|
+ chargeUserList = personInfoService.getPersonInfoVOListByUserIds(userIds);
|
|
|
+ }else{
|
|
|
+ chargeUserList=null;
|
|
|
+ }
|
|
|
eventVO.setChargeUserList(chargeUserList);
|
|
|
|
|
|
- // 5. 查询处理人
|
|
|
-// queryWrapper.eq()
|
|
|
+ // 5. 通过填报人id 查询村民姓名
|
|
|
+ Integer submitterId = event.getSubmitterId();
|
|
|
+
|
|
|
+
|
|
|
+ PersonInfo personInfo = personInfoService.getById(submitterId);
|
|
|
+ eventVO.setSubmitterName(personInfo.getRealname());
|
|
|
+
|
|
|
+ // 6. 查询处理人
|
|
|
+ QueryWrapper<EventAssign> wrapper = new QueryWrapper<>();
|
|
|
+ wrapper.select("person_id")
|
|
|
+ .eq("event_id", event.getId())
|
|
|
+ .eq("status", 1);
|
|
|
+ EventAssign eventAssign = eventAssignService.getOne(wrapper);
|
|
|
+ if (ObjectUtil.isNotEmpty(eventAssign)){
|
|
|
+ Integer personId = eventAssign.getPersonId();
|
|
|
+ if(personId == 1){
|
|
|
+ eventVO.setProcessUserName("超级管理员");
|
|
|
+ }else{
|
|
|
+ QueryWrapper<PersonInfo> queryWrapper2 = new QueryWrapper<>();
|
|
|
+ queryWrapper2.select("id", "realname")
|
|
|
+ .eq("user_id", personId);
|
|
|
+
|
|
|
+ List<PersonInfo> personInfoList = personInfoService.list(queryWrapper2);
|
|
|
+
|
|
|
+ if (!personInfoList.isEmpty()) {
|
|
|
+ PersonInfo personInfo2 = personInfoList.get(0);
|
|
|
+ eventVO.setProcessUserName(personInfo2.getRealname());
|
|
|
+ } else {
|
|
|
+ eventVO.setProcessUserName(null);
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
+ } else {
|
|
|
+ eventVO.setProcessUserName(null);
|
|
|
+ }
|
|
|
return eventVO;
|
|
|
}
|
|
|
|
|
@@ -354,6 +426,7 @@ public class EventServiceImpl extends ServiceImpl<EventMapper, Event>
|
|
|
}
|
|
|
|
|
|
// 从对象中取值
|
|
|
+ String description = eventQueryRequest.getDescription();
|
|
|
Date startTime = eventQueryRequest.getStartTime();
|
|
|
Date endTime = eventQueryRequest.getEndTime();
|
|
|
Integer type = eventQueryRequest.getType();
|
|
@@ -363,7 +436,8 @@ public class EventServiceImpl extends ServiceImpl<EventMapper, Event>
|
|
|
String sortField = eventQueryRequest.getSortField();
|
|
|
String sortOrder = eventQueryRequest.getSortOrder();
|
|
|
|
|
|
- // 事件类别、事发地点、填报人、状态
|
|
|
+ // 事件描述、事件类别、事发地点、填报人id(人口表id)、状态
|
|
|
+ queryWrapper.like(StrUtil.isNotBlank(description), "description", description);
|
|
|
queryWrapper.eq(ObjectUtil.isNotEmpty(type), "type", type);
|
|
|
queryWrapper.eq(StrUtil.isNotBlank(location), "location", location);
|
|
|
queryWrapper.eq(StringUtils.isNotBlank(status), "status", status);
|
|
@@ -389,22 +463,27 @@ public class EventServiceImpl extends ServiceImpl<EventMapper, Event>
|
|
|
return queryWrapper;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
/**
|
|
|
* 任一负责人处理事件:主表CAS(状态) + 分配表同步
|
|
|
*/
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
- public boolean handleEvent(Integer eventId, Integer personId, String processResult) {
|
|
|
+ public boolean handleEvent(Integer eventId, String processResult,Date processTime) {
|
|
|
+ Long personId = SecurityUtils.getUserId();
|
|
|
if (eventId == null || personId == null) {
|
|
|
throw new ServiceException("参数不能为空");
|
|
|
}
|
|
|
// 1. 事件主表CAS:尝试抢占锁,只能修改状态为 0 的事件
|
|
|
UpdateWrapper<Event> casUpdate = new UpdateWrapper<>();
|
|
|
+ if (ObjectUtil.isEmpty(processTime)){
|
|
|
+ processTime = new Date();
|
|
|
+ }
|
|
|
casUpdate.eq("id", eventId)
|
|
|
.eq("status", "0")
|
|
|
.set("status", "1")
|
|
|
.set("process_result", processResult)
|
|
|
- .set("process_time", new Date())
|
|
|
+ .set("process_time", processTime)
|
|
|
.set("update_time", new Date());
|
|
|
int w = this.baseMapper.update(null, casUpdate);
|
|
|
|
|
@@ -427,7 +506,7 @@ public class EventServiceImpl extends ServiceImpl<EventMapper, Event>
|
|
|
eventAssignMapper.update(null, othersDone);
|
|
|
return true;
|
|
|
} else {
|
|
|
- // 抢锁失败:将当前负责人状态-> 2
|
|
|
+ // 抢锁失败:当前事件已经被其他负责人处理,将当前负责人状态 -> 2
|
|
|
UpdateWrapper<EventAssign> meLose = new UpdateWrapper<>();
|
|
|
meLose.eq("event_id", eventId)
|
|
|
.eq("person_id", personId)
|
|
@@ -442,6 +521,7 @@ public class EventServiceImpl extends ServiceImpl<EventMapper, Event>
|
|
|
/**
|
|
|
* 再次派发:仅在事件未完结时允许;存在则重置为未完结并标记再派发,不存在则插入
|
|
|
*/
|
|
|
+ // todo 校验事件类型 与 负责人类型 是否匹配 personIds 为人口表 需要转换
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public void reassignEvent(Integer eventId, List<Integer> personIds) {
|
|
@@ -458,7 +538,9 @@ public class EventServiceImpl extends ServiceImpl<EventMapper, Event>
|
|
|
}
|
|
|
|
|
|
Date now = new Date();
|
|
|
- for (Integer uid : personIds) {
|
|
|
+ // 通过人口id 获取 系统用户id
|
|
|
+ List<Integer> userIds = personInfoService.getUserIdListByPersonIds(personIds);
|
|
|
+ for (Integer uid : userIds) {
|
|
|
// 先尝试更新存在的数据
|
|
|
UpdateWrapper<EventAssign> reset = new UpdateWrapper<>();
|
|
|
reset.eq("event_id", eventId)
|
|
@@ -481,8 +563,4 @@ public class EventServiceImpl extends ServiceImpl<EventMapper, Event>
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+}
|