¶Ô±ÈÐÂÎļþ |
| | |
| | | package org.jeecg.modules.eam.service.impl; |
| | | |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.apache.shiro.SecurityUtils; |
| | | import org.flowable.engine.TaskService; |
| | | import org.flowable.task.api.Task; |
| | | import org.jeecg.common.api.vo.Result; |
| | | import org.jeecg.common.constant.CommonConstant; |
| | | import org.jeecg.common.constant.DataBaseConstant; |
| | | import org.jeecg.common.exception.JeecgBootException; |
| | | import org.jeecg.common.system.vo.LoginUser; |
| | | import org.jeecg.common.util.oConvertUtils; |
| | | import org.jeecg.modules.eam.aspect.annotation.EquipmentHistoryLog; |
| | | import org.jeecg.modules.eam.constant.AssetStatusEnum; |
| | | import org.jeecg.modules.eam.constant.EquipmentLeanOutStatusEnum; |
| | | import org.jeecg.modules.eam.constant.EquipmentOperationTagEnum; |
| | | import org.jeecg.modules.eam.entity.EamEquipment; |
| | | import org.jeecg.modules.eam.entity.EamEquipmentLeanOut; |
| | | import org.jeecg.modules.eam.mapper.EamEquipmentLeanOutMapper; |
| | | import org.jeecg.modules.eam.request.EamEquipmentLeanOutQuery; |
| | | import org.jeecg.modules.eam.request.EamEquipmentLeanOutRequest; |
| | | import org.jeecg.modules.eam.service.IEamEquipmentLeanOutService; |
| | | import org.jeecg.modules.eam.service.IEamEquipmentService; |
| | | import org.jeecg.modules.flowable.apithird.business.entity.FlowMyBusiness; |
| | | import org.jeecg.modules.flowable.apithird.business.service.IFlowMyBusinessService; |
| | | import org.jeecg.modules.flowable.apithird.service.FlowCallBackServiceI; |
| | | import org.jeecg.modules.flowable.apithird.service.FlowCommonService; |
| | | import org.jeecg.modules.flowable.service.IFlowDefinitionService; |
| | | import org.jeecg.modules.flowable.service.IFlowTaskService; |
| | | import org.jeecg.modules.system.service.ISysUserService; |
| | | 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.*; |
| | | |
| | | /** |
| | | * @Description: 设å¤ååºå½è¿ |
| | | * @Author: jeecg-boot |
| | | * @Date: 2025-05-13 |
| | | * @Version: V1.0 |
| | | */ |
| | | @Service("IEamEquipmentLeanOutService") |
| | | public class EamEquipmentLeanOutServiceImpl extends ServiceImpl<EamEquipmentLeanOutMapper, EamEquipmentLeanOut> implements IEamEquipmentLeanOutService, FlowCallBackServiceI { |
| | | @Resource |
| | | private EamEquipmentLeanOutMapper equipmentLeanOutMapper; |
| | | @Autowired |
| | | private IEamEquipmentService eamEquipmentService; |
| | | @Autowired |
| | | private FlowCommonService flowCommonService; |
| | | @Autowired |
| | | private IFlowDefinitionService flowDefinitionService; |
| | | @Autowired |
| | | private IFlowMyBusinessService flowMyBusinessService; |
| | | @Autowired |
| | | private TaskService taskService; |
| | | @Autowired |
| | | private IFlowTaskService flowTaskService; |
| | | |
| | | @Autowired |
| | | private ISysUserService sysUserService; |
| | | |
| | | @Override |
| | | public IPage<EamEquipmentLeanOut> queryPageList(Page<EamEquipmentLeanOut> page, EamEquipmentLeanOutQuery query) { |
| | | QueryWrapper<EamEquipmentLeanOut> queryWrapper = new QueryWrapper<>(); |
| | | queryWrapper.eq("wmo.del_flag", CommonConstant.DEL_FLAG_0); |
| | | //ç¨æ·æ°æ®æé |
| | | LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal(); |
| | | if (sysUser == null) { |
| | | return page; |
| | | } |
| | | if (StringUtils.isNotBlank(sysUser.getEquipmentIds())) { |
| | | //éæ©äºè®¾å¤ï¼æ ¹æ®è®¾å¤idè¿æ»¤è®¾å¤ |
| | | List<String> equipArr = Arrays.asList(sysUser.getEquipmentIds().split(",")); |
| | | queryWrapper.in("e.equipment_code", equipArr); |
| | | } else { |
| | | //没æéæ©è®¾å¤ï¼æ ¹æ®è½¦é´è¿æ»¤è®¾å¤ |
| | | queryWrapper.exists("select 1 from mdc_user_production t where t.user_id={0} and t.pro_id=e.org_id ", sysUser.getId()); |
| | | } |
| | | //æ§å¶å¾
æäº¤ç¶æçæ°æ®åªè½æ¬äººæ¥ç |
| | | queryWrapper.and(i -> i.ne("wmo.lean_status", EquipmentLeanOutStatusEnum.WAIT_SUBMIT).or().eq("wmo.lean_person", sysUser.getUsername())); |
| | | //æ¥è¯¢æ¡ä»¶è¿æ»¤ |
| | | if (query != null) { |
| | | if (StringUtils.isNotBlank(query.getEquipmentId())) { |
| | | queryWrapper.eq("wmo.equipment_id", query.getEquipmentId()); |
| | | } |
| | | if (StringUtils.isNotBlank(query.getCode())) { |
| | | queryWrapper.like("wmo.code", query.getCode()); |
| | | } |
| | | if (StringUtils.isNotBlank(query.getLeanStatus())) { |
| | | queryWrapper.eq("wmo.lean_status", query.getLeanStatus()); |
| | | } |
| | | if (query.getLeanDateBegin() != null && query.getLeanDateEnd() != null) { |
| | | queryWrapper.between("wmo.lean_start_time", query.getLeanDateBegin(), query.getLeanDateEnd()); |
| | | } |
| | | //æåº |
| | | if (StringUtils.isNotBlank(query.getColumn()) && StringUtils.isNotBlank(query.getOrder())) { |
| | | String column = query.getColumn(); |
| | | if (column.endsWith(CommonConstant.DICT_TEXT_SUFFIX)) { |
| | | column = column.substring(0, column.lastIndexOf(CommonConstant.DICT_TEXT_SUFFIX)); |
| | | } |
| | | if (DataBaseConstant.SQL_ASC.equalsIgnoreCase(query.getOrder())) { |
| | | queryWrapper.orderByAsc("wmo." + oConvertUtils.camelToUnderline(column)); |
| | | } else { |
| | | queryWrapper.orderByDesc("wmo." + oConvertUtils.camelToUnderline(column)); |
| | | } |
| | | } else { |
| | | queryWrapper.orderByDesc("wmo.create_time"); |
| | | } |
| | | } else { |
| | | queryWrapper.orderByDesc("wmo.create_time"); |
| | | } |
| | | |
| | | return equipmentLeanOutMapper.queryPageList(page, queryWrapper); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public boolean addLeanOut(EamEquipmentLeanOut request) { |
| | | //æ£æ¥è®¾å¤ |
| | | EamEquipment equipment = eamEquipmentService.getById(request.getEquipmentId()); |
| | | if (equipment == null) { |
| | | throw new JeecgBootException("设å¤ä¸åå¨ï¼"); |
| | | } |
| | | if (!AssetStatusEnum.NORMAL.name().equals(equipment.getAssetStatus())) { |
| | | throw new JeecgBootException("æ¤è®¾å¤å½åèµäº§ç¶æä¸å
许ååºï¼"); |
| | | } |
| | | if (StringUtils.isBlank(request.getLeanDepartId())) { |
| | | throw new JeecgBootException("åå
¥è½¦é´ä¸å
许为空ï¼"); |
| | | } |
| | | if (request.getLeanDepartId().equals(equipment.getOrgId())) { |
| | | throw new JeecgBootException("å½å设å¤å±äºæ¤è½¦é´ï¼ä¸éè¦åç¨ï¼"); |
| | | } |
| | | LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal(); |
| | | if (sysUser == null) { |
| | | throw new JeecgBootException("å½åç¨æ·æ æ³æ·»å åç¨è®°å½ï¼"); |
| | | } |
| | | request.setLeanPerson(sysUser.getUsername()); |
| | | return equipmentLeanOutMapper.insert(request) > 0; |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public boolean editLeanOut(EamEquipmentLeanOut request) { |
| | | EamEquipmentLeanOut entity = equipmentLeanOutMapper.selectById(request.getId()); |
| | | if (entity == null) { |
| | | throw new JeecgBootException("è¦ç¼è¾çæ°æ®ä¸åå¨ï¼è¯·å·æ°éè¯ï¼"); |
| | | } |
| | | if (!EquipmentLeanOutStatusEnum.WAIT_SUBMIT.name().equals(entity.getLeanStatus())) { |
| | | throw new JeecgBootException("å½åæ°æ®ç¶æä¸å
许ç¼è¾ï¼"); |
| | | } |
| | | //æ£æ¥è®¾å¤ |
| | | EamEquipment equipment = eamEquipmentService.getById(request.getEquipmentId()); |
| | | if (equipment == null) { |
| | | throw new JeecgBootException("设å¤ä¸åå¨ï¼"); |
| | | } |
| | | if (!AssetStatusEnum.NORMAL.name().equals(equipment.getAssetStatus())) { |
| | | throw new JeecgBootException("æ¤è®¾å¤å½åèµäº§ç¶æä¸å
许ååºï¼"); |
| | | } |
| | | if (StringUtils.isBlank(request.getLeanDepartId())) { |
| | | throw new JeecgBootException("åå
¥è½¦é´ä¸å
许为空ï¼"); |
| | | } |
| | | if (request.getLeanDepartId().equals(equipment.getOrgId())) { |
| | | throw new JeecgBootException("å½å设å¤å±äºæ¤è½¦é´ï¼ä¸éè¦åç¨ï¼"); |
| | | } |
| | | LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal(); |
| | | if (sysUser == null) { |
| | | throw new JeecgBootException("å½åç¨æ·æ æ³ç¼è¾åç¨è®°å½ï¼"); |
| | | } |
| | | UpdateWrapper<EamEquipmentLeanOut> updateWrapper = new UpdateWrapper<>(); |
| | | updateWrapper.set("equipment_id", request.getEquipmentId()); |
| | | updateWrapper.set("lean_depart_id", request.getLeanDepartId()); |
| | | updateWrapper.set("remark", request.getRemark()); |
| | | updateWrapper.set("lean_reason", request.getLeanReason()); |
| | | updateWrapper.eq("id", request.getId()); |
| | | updateWrapper.eq("lean_person", sysUser.getUsername()); |
| | | return super.update(updateWrapper); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public boolean submit(String id) { |
| | | EamEquipmentLeanOut entity = equipmentLeanOutMapper.selectById(id); |
| | | if (entity == null) { |
| | | throw new JeecgBootException("è¦æäº¤çæ°æ®ä¸åå¨ï¼è¯·å·æ°éè¯ï¼"); |
| | | } |
| | | if (!EquipmentLeanOutStatusEnum.WAIT_SUBMIT.name().equals(entity.getLeanStatus())) { |
| | | throw new JeecgBootException("å½åæ°æ®ç¶æä¸å
许ç¼è¾ï¼"); |
| | | } |
| | | //æ£æ¥è®¾å¤ |
| | | EamEquipment equipment = eamEquipmentService.getById(entity.getEquipmentId()); |
| | | if (equipment == null) { |
| | | throw new JeecgBootException("设å¤ä¸åå¨ï¼"); |
| | | } |
| | | if (!AssetStatusEnum.NORMAL.name().equals(equipment.getAssetStatus())) { |
| | | throw new JeecgBootException("æ¤è®¾å¤å½åèµäº§ç¶æä¸å
许ååºï¼"); |
| | | } |
| | | LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal(); |
| | | if (sysUser == null) { |
| | | throw new JeecgBootException("å½åç¨æ·æ æ³ç¼è¾åç¨è®°å½ï¼"); |
| | | } |
| | | UpdateWrapper<EamEquipmentLeanOut> updateWrapper = new UpdateWrapper<>(); |
| | | updateWrapper.set("lean_status", EquipmentLeanOutStatusEnum.WAIT_APPROVAL.name()); |
| | | updateWrapper.eq("id", id); |
| | | updateWrapper.eq("lean_person", sysUser.getUsername()); |
| | | boolean success = super.update(updateWrapper); |
| | | if (success) { |
| | | equipment.setAssetStatus(AssetStatusEnum.LEAN_OUT.name()); |
| | | eamEquipmentService.updateById(equipment); |
| | | } |
| | | //å¯å¨å®¡æ¹æµç¨ |
| | | flowCommonService.initActBusiness("å·¥åå·:" + entity.getCode() + ";设å¤ç¼å·: " + equipment.getEquipmentCode() + ";è¿è¡è®¾å¤åç¨", |
| | | entity.getId(), "IEamEquipmentLeanOutService", "equipment_lean_out", null); |
| | | Map<String, Object> variables = new HashMap<>(); |
| | | variables.put("dataId", entity.getId()); |
| | | if (StrUtil.isEmpty(entity.getLeanReason())) { |
| | | variables.put("organization", "æ°å¢åç¨å·¥åé»è®¤å¯å¨æµç¨"); |
| | | variables.put("comment", "æ°å¢åç¨å·¥åé»è®¤å¯å¨æµç¨"); |
| | | } else { |
| | | variables.put("organization", entity.getLeanReason()); |
| | | variables.put("comment", entity.getLeanReason()); |
| | | } |
| | | variables.put("proofreading", true); |
| | | List<String> usernames = new ArrayList<>(); |
| | | usernames.add(equipment.getEquipmentManager()); |
| | | variables.put("NextAssignee", usernames); |
| | | Result result = flowDefinitionService.startProcessInstanceByKey("equipment_lean_out", variables); |
| | | if (result != null) { |
| | | entity.setLeanStartTime(new Date()); |
| | | entity.setLeanStatus(EquipmentLeanOutStatusEnum.WAIT_APPROVAL.name()); |
| | | //ä¿åå·¥å |
| | | equipmentLeanOutMapper.updateById(entity); |
| | | return result.isSuccess(); |
| | | } |
| | | return true; |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | @EquipmentHistoryLog(operationTag = EquipmentOperationTagEnum.LEAN_OUT, businessTable = "eam_equipment_lean_out") |
| | | public EamEquipmentLeanOut approval(EamEquipmentLeanOutRequest request) { |
| | | EamEquipmentLeanOut entity = equipmentLeanOutMapper.selectById(request.getId()); |
| | | if (entity == null) { |
| | | throw new JeecgBootException("审æ¹çæ°æ®å·²å é¤ï¼è¯·å·æ°éè¯ï¼"); |
| | | } |
| | | // è·åå½åç»å½ç¨æ· |
| | | LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal(); |
| | | if (user == null || StrUtil.isBlank(user.getId())) { |
| | | throw new JeecgBootException("æªè·åå°ç»å½ç¨æ·ï¼è¯·éæ°ç»å½ååè¯ï¼"); |
| | | } |
| | | request.setApprovalUser(user.getUsername()); |
| | | // è·åæµç¨ä¸å¡è®°å½ |
| | | FlowMyBusiness flowMyBusiness = flowMyBusinessService.getFlowMyBusiness(request.getInstanceId()); |
| | | if (flowMyBusiness == null) { |
| | | throw new JeecgBootException("æµç¨å®ä¾ä¸åå¨ï¼è¯·å·æ°åéè¯ï¼"); |
| | | } |
| | | |
| | | boolean userAuthorized = isUserAuthorized(flowMyBusiness, user); |
| | | if (!userAuthorized) { |
| | | throw new JeecgBootException("ç¨æ·æ ææä½æ¤ä»»å¡ï¼è¯·å·æ°åéè¯ï¼"); |
| | | } |
| | | // 认é¢ä»»å¡ |
| | | if (!claimTask(flowMyBusiness.getTaskId(), user)) { |
| | | throw new JeecgBootException("ä»»å¡ä¸åå¨ã已宿æå·²è¢«ä»äººè®¤é¢ï¼"); |
| | | } |
| | | |
| | | EamEquipment equipment = eamEquipmentService.getById(entity.getEquipmentId()); |
| | | if (equipment == null) { |
| | | throw new JeecgBootException("设å¤ä¸åå¨ï¼è¯·æ£æ¥ï¼"); |
| | | } |
| | | |
| | | EquipmentLeanOutStatusEnum status = EquipmentLeanOutStatusEnum.getInstance(entity.getLeanStatus()); |
| | | if (status == null) { |
| | | return null; |
| | | } |
| | | //æµç¨åé |
| | | Map<String, Object> values = new HashMap<>(); |
| | | switch (status) { |
| | | // å®¡æ¹ |
| | | case WAIT_APPROVAL: |
| | | //æ§è¡å®æ |
| | | values.put("dataId", entity.getId()); |
| | | values.put("organization", request.getApprovalComment()); |
| | | values.put("comment", request.getApprovalComment()); |
| | | values.put("approvalDealType", request.getApprovalDealType()); |
| | | request.setComment(request.getApprovalComment()); |
| | | entity.setApprovalUser(user.getUsername());// å®¡æ ¸äºº |
| | | entity.setApprovalComment(request.getApprovalComment());// å®¡æ ¸æè§ |
| | | entity.setApprovalTime(new Date());// å®¡æ ¸æ¶é´ |
| | | entity.setApprovalDealType(request.getApprovalDealType()); // 审æ¹ç±»å |
| | | // éªè¯éè¿è¿æ¯é©³å |
| | | if (request.getApprovalDealType().equals("1")) { |
| | | //设置entity |
| | | entity.setLeanStatus(EquipmentLeanOutStatusEnum.WAIT_RETURN.name()); |
| | | List<String> userApprovalList = new ArrayList<>(Collections.singletonList(entity.getLeanPerson())); |
| | | values.put("NextAssignee", userApprovalList); |
| | | } else { |
| | | //设置entity |
| | | entity.setLeanStatus(EquipmentLeanOutStatusEnum.COMPLETE.name()); |
| | | // ä¿®æ¹è®¾å¤ç¶æ |
| | | equipment.setAssetStatus(AssetStatusEnum.NORMAL.name()); |
| | | eamEquipmentService.updateById(equipment); |
| | | } |
| | | break; |
| | | // å½è¿ |
| | | case WAIT_RETURN: |
| | | if (StringUtils.isBlank(equipment.getEquipmentManager())) { |
| | | throw new JeecgBootException("è®¾å¤æªåé
设å¤ç®¡çåï¼æ æ³è¿å
¥ä¸çº§å®¡æ¹ï¼"); |
| | | } |
| | | List<String> userApprovalList = new ArrayList<>(Collections.singletonList(entity.getLeanPerson())); |
| | | userApprovalList.add(equipment.getEquipmentManager()); |
| | | values.put("dataId", entity.getId()); |
| | | values.put("organization", request.getReturnComment()); |
| | | values.put("comment", request.getReturnComment()); |
| | | values.put("NextAssignee", userApprovalList); |
| | | request.setComment(request.getReturnComment()); |
| | | entity.setLeanEndTime(new Date()); //å½è¿æ¶é´ |
| | | //设置entity |
| | | entity.setLeanStatus(EquipmentLeanOutStatusEnum.WAIT_CONFIRM.name()); |
| | | entity.setApprovalUser(user.getUsername());// å®¡æ ¸äºº |
| | | entity.setLeanEndTime(new Date());// å½è¿æ¶é´ |
| | | entity.setReturnComment(request.getReturnComment());// å½è¿å¤æ³¨ |
| | | break; |
| | | // å½è¿ç¡®è®¤ |
| | | case WAIT_CONFIRM: |
| | | values.put("dataId", entity.getId()); |
| | | values.put("organization", request.getConfirmComment()); |
| | | values.put("comment", request.getConfirmComment()); |
| | | request.setComment(request.getConfirmComment()); |
| | | //设置entity |
| | | entity.setLeanStatus(EquipmentLeanOutStatusEnum.COMPLETE.name()); |
| | | entity.setConfirmUser(user.getUsername()); |
| | | entity.setConfirmComment(request.getConfirmComment()); |
| | | entity.setConfirmTime(new Date()); |
| | | // ä¿®æ¹è®¾å¤ç¶æ |
| | | equipment.setAssetStatus(AssetStatusEnum.NORMAL.name()); |
| | | eamEquipmentService.updateById(equipment); |
| | | break; |
| | | } |
| | | request.setValues(values); |
| | | |
| | | // 宿æµç¨ä»»å¡ |
| | | Result result = flowTaskService.complete(request); |
| | | if (!result.isSuccess()) { |
| | | throw new JeecgBootException("审æ¹å¤±è´¥ï¼è¯·å·æ°æ¥çï¼"); |
| | | } |
| | | //ä¿åå·¥å |
| | | equipmentLeanOutMapper.updateById(entity); |
| | | return entity; |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public void afterFlowHandle(FlowMyBusiness business) { |
| | | business.getTaskNameId();//æ¥ä¸æ¥å®¡æ¹çèç¹ |
| | | business.getValues();//åç«¯ä¼ è¿æ¥çåæ° |
| | | business.getActStatus(); |
| | | } |
| | | |
| | | private boolean claimTask(String taskId, LoginUser user) { |
| | | Task task = taskService.createTaskQuery().taskId(taskId).singleResult(); |
| | | if (task == null) { |
| | | return false; |
| | | } |
| | | if (task.getAssignee() != null && !task.getAssignee().equals(user.getUsername())) { |
| | | return false; |
| | | } |
| | | taskService.claim(taskId, user.getUsername()); |
| | | return true; |
| | | } |
| | | |
| | | /** |
| | | * å¤æç¨æ·æ¯å¦æ¥ææ¤æé |
| | | * |
| | | * @param flowMyBusiness |
| | | * @param user |
| | | * @return |
| | | */ |
| | | private boolean isUserAuthorized(FlowMyBusiness flowMyBusiness, LoginUser user) { |
| | | List<String> todoUsers = JSON.parseArray(flowMyBusiness.getTodoUsers(), String.class); |
| | | return todoUsers != null && todoUsers.contains(user.getUsername()); |
| | | } |
| | | |
| | | @Override |
| | | public Object getBusinessDataById(String dataId) { |
| | | return this.getById(dataId); |
| | | } |
| | | |
| | | @Override |
| | | public Map<String, Object> flowValuesOfTask(String taskNameId, Map<String, Object> values) { |
| | | return null; |
| | | } |
| | | |
| | | @Override |
| | | public List<String> flowCandidateUsernamesOfTask(String taskNameId, Map<String, Object> values) { |
| | | //ä¸å¡æ¯å¦å¹²é¢æµç¨ï¼ä¸å¡å¹²é¢ï¼æµç¨å¹²é¢ï¼æå®äººåè¿è¡å¤ç |
| | | //è·åä¸ä¸æ¥å¤ç人 |
| | | Object object = values.get("NextAssignee"); |
| | | return (List<String>) object; |
| | | } |
| | | } |