|
|
@ -1,13 +1,7 @@ |
|
|
|
package com.ruoyi.aftersales.service.impl; |
|
|
|
|
|
|
|
import java.text.SimpleDateFormat; |
|
|
|
import java.util.*; |
|
|
|
|
|
|
|
import com.github.pagehelper.Page; |
|
|
|
import com.ruoyi.aftersales.domain.vo.AftersalesOrderVO; |
|
|
|
import com.ruoyi.common.core.domain.entity.SysUser; |
|
|
|
import com.ruoyi.common.core.page.PageDomain; |
|
|
|
import com.ruoyi.common.core.page.TableSupport; |
|
|
|
import com.ruoyi.common.core.redis.RedisCache; |
|
|
|
import com.ruoyi.common.utils.DateUtils; |
|
|
|
import com.ruoyi.common.utils.ShiroUtils; |
|
|
@ -15,16 +9,12 @@ import com.ruoyi.common.utils.StringUtils; |
|
|
|
import com.ruoyi.process.general.service.IProcessService; |
|
|
|
import com.ruoyi.process.todoitem.mapper.BizTodoItemMapper; |
|
|
|
import com.ruoyi.system.domain.SysAttach; |
|
|
|
import com.ruoyi.system.domain.SysMakeorderPick; |
|
|
|
import com.ruoyi.system.mapper.SysAttachMapper; |
|
|
|
import com.ruoyi.system.mapper.SysUserMapper; |
|
|
|
import com.ruoyi.system.service.ISysAttachFileService; |
|
|
|
import com.ruoyi.system.service.ISysAttachService; |
|
|
|
import com.ruoyi.system.service.ISysRoleService; |
|
|
|
import org.activiti.engine.TaskService; |
|
|
|
import org.activiti.engine.impl.persistence.entity.TaskEntityImpl; |
|
|
|
import org.activiti.engine.runtime.ProcessInstance; |
|
|
|
import org.activiti.engine.task.Task; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import com.ruoyi.aftersales.mapper.AftersalesOrderMapper; |
|
|
@ -52,28 +42,6 @@ public class AftersalesOrderServiceImpl implements IAftersalesOrderService |
|
|
|
private ISysAttachFileService attachFileService; |
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
private IProcessService processService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private SysAttachMapper sysAttachMapper; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private RedisCache redisCache; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private ISysRoleService roleService; |
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
private SysUserMapper userMapper; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private TaskService taskService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private BizTodoItemMapper todoItemMapper; |
|
|
|
|
|
|
|
/** |
|
|
|
* 查询售后单 |
|
|
|
* |
|
|
@ -81,7 +49,7 @@ public class AftersalesOrderServiceImpl implements IAftersalesOrderService |
|
|
|
* @return 售后单 |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public AftersalesOrderVO selectAftersalesOrderById(Long aftersalesOrderId) |
|
|
|
public AftersalesOrder selectAftersalesOrderById(Long aftersalesOrderId) |
|
|
|
{ |
|
|
|
return aftersalesOrderMapper.selectAftersalesOrderById(aftersalesOrderId); |
|
|
|
} |
|
|
@ -109,60 +77,9 @@ public class AftersalesOrderServiceImpl implements IAftersalesOrderService |
|
|
|
* @return 售后单 |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public List<AftersalesOrderVO> selectAftersalesOrderList(AftersalesOrderVO aftersalesOrderVO) |
|
|
|
public List<AftersalesOrder> selectAftersalesOrderList(AftersalesOrder aftersalesOrder) |
|
|
|
{ |
|
|
|
PageDomain pageDomain = TableSupport.buildPageRequest(); |
|
|
|
Integer pageNum = pageDomain.getPageNum(); |
|
|
|
Integer pageSize = pageDomain.getPageSize(); |
|
|
|
|
|
|
|
// PageHelper 仅对第一个 List 分页
|
|
|
|
Page<AftersalesOrderVO> list = (Page<AftersalesOrderVO>) aftersalesOrderMapper.selectAftersalesOrderList(aftersalesOrderVO); |
|
|
|
Page<AftersalesOrderVO> returnList = new Page<>(); |
|
|
|
for (AftersalesOrderVO tempAftersalesOrderVO: list) { |
|
|
|
SysUser sysUser = userMapper.selectUserByLoginName(tempAftersalesOrderVO.getCreateBy()); |
|
|
|
if (sysUser != null) { |
|
|
|
tempAftersalesOrderVO.setCreateUserName(sysUser.getUserName()); |
|
|
|
} |
|
|
|
SysUser sysUser2 = userMapper.selectUserByLoginName(tempAftersalesOrderVO.getApplyUser()); |
|
|
|
if (sysUser2 != null) { |
|
|
|
tempAftersalesOrderVO.setApplyUserName(sysUser2.getUserName()); |
|
|
|
} |
|
|
|
String instanceId = tempAftersalesOrderVO.getInstanceId(); |
|
|
|
// 当前环节
|
|
|
|
if (StringUtils.isNotBlank(instanceId)) { |
|
|
|
List<Task> taskList = taskService.createTaskQuery() |
|
|
|
.processInstanceId(instanceId) |
|
|
|
// .singleResult();
|
|
|
|
.list(); // 例如请假会签,会同时拥有多个任务
|
|
|
|
if (!org.springframework.util.CollectionUtils.isEmpty(taskList)) { |
|
|
|
TaskEntityImpl task = (TaskEntityImpl) taskList.get(0); |
|
|
|
String taskId = task.getId(); |
|
|
|
tempAftersalesOrderVO.setTaskId(taskId); |
|
|
|
// 设置待办用户
|
|
|
|
List<String> todoUserList = todoItemMapper.selectUndealTodoUserList(taskId); |
|
|
|
if(!org.springframework.util.CollectionUtils.isEmpty(taskList)){ |
|
|
|
tempAftersalesOrderVO.setTodoUserId(String.join(",",todoUserList)); |
|
|
|
} |
|
|
|
if (task.getSuspensionState() == 2) { |
|
|
|
tempAftersalesOrderVO.setTaskName("已挂起"); |
|
|
|
tempAftersalesOrderVO.setSuspendState("2"); |
|
|
|
} else { |
|
|
|
tempAftersalesOrderVO.setTaskName(task.getName()); |
|
|
|
tempAftersalesOrderVO.setSuspendState("1"); |
|
|
|
} |
|
|
|
} else { |
|
|
|
// 已办结或者已撤销
|
|
|
|
tempAftersalesOrderVO.setTaskName("已结束"); |
|
|
|
} |
|
|
|
} else { |
|
|
|
tempAftersalesOrderVO.setTaskName("未启动"); |
|
|
|
} |
|
|
|
returnList.add(tempAftersalesOrderVO); |
|
|
|
} |
|
|
|
returnList.setTotal(org.springframework.util.CollectionUtils.isEmpty(list) ? 0 : list.getTotal()); |
|
|
|
returnList.setPageNum(pageNum); |
|
|
|
returnList.setPageSize(pageSize); |
|
|
|
return returnList; |
|
|
|
return aftersalesOrderMapper.selectAftersalesOrderList(aftersalesOrder); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
@ -276,72 +193,4 @@ public class AftersalesOrderServiceImpl implements IAftersalesOrderService |
|
|
|
return aftersalesOrderMapper.restoreAftersalesOrderById(aftersalesOrderId); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 审批流程启动 |
|
|
|
* */ |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
@Override |
|
|
|
public ProcessInstance submitApply(AftersalesOrder aftersalesOrder) { |
|
|
|
|
|
|
|
SysUser user = ShiroUtils.getSysUser(); |
|
|
|
aftersalesOrder.setApplyUser(user.getLoginName()); |
|
|
|
aftersalesOrder.setApplyTime(DateUtils.getNowDate()); |
|
|
|
aftersalesOrder.setAftersalesOrderCode(redisCache.generateBillNo("SH")); |
|
|
|
// 保存
|
|
|
|
insertAftersalesOrder(aftersalesOrder); |
|
|
|
// 启动流程
|
|
|
|
String applyTitle = user.getUserName()+"发起了售后单提交审批-"+DateUtils.dateTimeNow(); |
|
|
|
String instanceType = "submit"; |
|
|
|
ProcessInstance processInstance = startProcessInstance(applyTitle,instanceType,aftersalesOrder, user); |
|
|
|
String processInstanceId = processInstance.getProcessInstanceId(); |
|
|
|
// 提交实例id
|
|
|
|
aftersalesOrder.setSubmitInstanceId(processInstanceId); |
|
|
|
// 存在提交完就流程结束的情况
|
|
|
|
boolean processIsFinish = processService.judgeProcessIsFinish(processInstanceId); |
|
|
|
if(processIsFinish){ |
|
|
|
// 审核状态-审核通过
|
|
|
|
aftersalesOrder.setAuditStatus("1"); |
|
|
|
} |
|
|
|
aftersalesOrderMapper.updateAftersalesOrder(aftersalesOrder); |
|
|
|
return processInstance; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* 创建售后单审核流程 |
|
|
|
* @param applyTitle |
|
|
|
* @param instanceType |
|
|
|
* @param user |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
private ProcessInstance startProcessInstance(String applyTitle, String instanceType, AftersalesOrder aftersalesOrder, SysUser user) { |
|
|
|
Long aftersalesOrderId = aftersalesOrder.getAftersalesOrderId(); |
|
|
|
String businessKey = aftersalesOrderId.toString(); // 实体类 ID,作为流程的业务 key
|
|
|
|
String key = "aftersalesOrder"; |
|
|
|
Map<String,Object> variables = new HashMap<>(); |
|
|
|
// 构造authority传参
|
|
|
|
buildAuthority(user, variables); |
|
|
|
aftersalesOrder.setApplyTitle(applyTitle); |
|
|
|
// 启动流程
|
|
|
|
ProcessInstance processInstance = processService.submitApply(user.getLoginName(), businessKey, applyTitle, aftersalesOrder.getAftersalesOrderCode(), key, variables); |
|
|
|
String processInstanceId = processInstance.getId(); |
|
|
|
aftersalesOrder.setInstanceId(processInstanceId); // 建立双向关系
|
|
|
|
aftersalesOrder.setInstanceType(instanceType); |
|
|
|
return processInstance; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 发起人节点判断 |
|
|
|
* */ |
|
|
|
private void buildAuthority(SysUser user, Map<String, Object> variables) { |
|
|
|
Set<String> roleKeys = roleService.selectRoleKeys(user.getUserId()); |
|
|
|
// 角色不同审核人不同
|
|
|
|
if(roleKeys.contains("ywyRole")){ |
|
|
|
variables.put("authority",1); |
|
|
|
}else if(roleKeys.contains("ywjlRole")){ |
|
|
|
variables.put("authority",2); |
|
|
|
}else if(roleKeys.contains("ywzgRole")){ |
|
|
|
variables.put("authority",3); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|