| | |
| | | package com.aps.core.service.impl; |
| | | |
| | | import cn.hutool.core.util.IdUtil; |
| | | import com.aps.common.core.domain.R; |
| | | import com.aps.common.core.utils.DateUtils; |
| | | import com.aps.common.core.web.domain.AjaxResult; |
| | | import com.aps.common.redis.service.RedisLockUtils; |
| | | import com.aps.common.security.utils.SecurityUtils; |
| | | import com.aps.core.enums.PLAN_TASK_STATUS; |
| | | import com.aps.core.enums.PLAN_TASK_TYPE; |
| | | import com.aps.core.enums.REDIS_LOCK_KEY; |
| | | import com.aps.core.service.ApsPlate.IApsPlateStandardRequireBatchService; |
| | | import com.aps.core.service.ApsPlate.IApsPlateStandardRequireService; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.aps.core.domain.ApsPlanTask; |
| | | import com.aps.core.service.ApsPlanTaskService; |
| | | import com.aps.core.mapper.ApsPlanTaskMapper; |
| | | import jakarta.annotation.Resource; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.List; |
| | | import static com.aps.common.core.web.domain.AjaxResult.success; |
| | | import static com.aps.core.enums.REDIS_LOCK_KEY.PLATE_ORDER_PLAN; |
| | | |
| | | /** |
| | | * @author zhl |
| | | * @description é对表ãaps_plan_task(计åçææ¥å¿è¡¨)ãçæ°æ®åºæä½Serviceå®ç° |
| | | * @createDate 2025-05-16 14:41:49 |
| | | */ |
| | | |
| | | @Slf4j |
| | | @Service |
| | | public class ApsPlanTaskServiceImpl extends ServiceImpl<ApsPlanTaskMapper, ApsPlanTask> implements ApsPlanTaskService{ |
| | | |
| | | |
| | | @Autowired |
| | | ApsPlanTaskMapper mapper; |
| | | @Autowired |
| | | private IApsPlateStandardRequireService apsPlateStandardRequireService; |
| | | @Resource |
| | | IApsPlateStandardRequireBatchService requireBatchService; |
| | | |
| | | @Resource |
| | | RedisLockUtils redisLockUtils; |
| | | |
| | | @Override |
| | | public Page<ApsPlanTask> pagingList(Page<ApsPlanTask> page ,ApsPlanTask task){ |
| | | LambdaQueryWrapper<ApsPlanTask> queryWrapper=new LambdaQueryWrapper<>(); |
| | | queryWrapper.like( !task.getTaskType().isEmpty(), ApsPlanTask::getTaskType,task.getTaskType()); |
| | |
| | | .build(); |
| | | baseMapper.update(task,queryWrapper); |
| | | } |
| | | |
| | | @Override |
| | | public AjaxResult generatorPlan() |
| | | { |
| | | String plateOrderPlanKey = PLATE_ORDER_PLAN.getKey(); |
| | | boolean existsLock = redisLockUtils.existLock(plateOrderPlanKey, PLAN_TASK_TYPE.PLATE_PLAN.getCode()); |
| | | if (existsLock){ |
| | | return AjaxResult.warn("é£éå·¥å计å任塿£å¨æ§è¡ä¸!"); |
| | | } |
| | | LambdaQueryWrapper<ApsPlanTask> queryWrapper=new LambdaQueryWrapper<>(); |
| | | queryWrapper.eq(ApsPlanTask::getTaskType,PLAN_TASK_TYPE.PLATE_PLAN.getCode()); |
| | | queryWrapper.eq(ApsPlanTask::getTaskStatus,PLAN_TASK_STATUS.IN_PROCESS.getCode()); |
| | | boolean existsDbTask = mapper.exists(queryWrapper); |
| | | if (existsDbTask){ |
| | | return AjaxResult.warn("é£éå·¥å计å任塿£å¨æ§è¡ä¸!!"); |
| | | } |
| | | try { |
| | | redisLockUtils.getLock(plateOrderPlanKey,PLAN_TASK_TYPE.PLATE_PLAN.getCode(), 3*60L); |
| | | String batchNum= requireBatchService.getNewBatchNumber(); |
| | | this.savePlanTask(batchNum); |
| | | apsPlateStandardRequireService.generatorPlan(batchNum); |
| | | this.updateTaskStatus(batchNum, PLAN_TASK_STATUS.FINISHED); |
| | | log.info("计å任塿§è¡å®æ!"+batchNum); |
| | | return success(); |
| | | }catch (Exception e){ |
| | | redisLockUtils.releaseLock(plateOrderPlanKey,PLAN_TASK_TYPE.PLATE_PLAN.getCode()); |
| | | log.error("计å任塿§è¡å¤±è´¥!"+e.getMessage()); |
| | | return AjaxResult.error("计å任塿§è¡å¤±è´¥!"+e.getMessage()); |
| | | }finally { |
| | | redisLockUtils.releaseLock(plateOrderPlanKey,PLAN_TASK_TYPE.PLATE_PLAN.getCode()); |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | |