| | |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.itextpdf.text.log.Logger; |
| | | import com.itextpdf.text.log.LoggerFactory; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springblade.common.constant.CommonConstant; |
| | | import org.springblade.common.constant.DictConstant; |
| | |
| | | import org.springblade.modules.place.service.IPlaceExtService; |
| | | import org.springblade.modules.place.service.IPlaceService; |
| | | import org.springblade.modules.place.vo.PlaceVO; |
| | | import org.springblade.modules.sms.service.ISmsSendService; |
| | | import org.springblade.modules.task.entity.*; |
| | | import org.springblade.modules.task.mapper.TaskMapper; |
| | | import org.springblade.modules.task.service.*; |
| | |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.time.LocalDate; |
| | | import java.time.temporal.ChronoUnit; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | |
| | | */ |
| | | @Service |
| | | public class TaskServiceImpl extends ServiceImpl<TaskMapper, TaskEntity> implements ITaskService { |
| | | |
| | | private Logger logger = LoggerFactory.getLogger(TaskServiceImpl.class); |
| | | |
| | | @Autowired |
| | | private IPlaceService placeService; |
| | |
| | | |
| | | @Autowired |
| | | private IGridWorkLogService gridWorkLogService; |
| | | |
| | | @Autowired |
| | | private ITaskResidencePermitApplyService residencePermitApplyService; |
| | | |
| | | @Autowired |
| | | private ISmsSendService smsSendService; |
| | | |
| | | // 确保该常量值正确地从配置文件中读取或以更合适的方式定义 |
| | | private static final long SMS_TEMPLATE_ID = 1775429789463142401L; |
| | | |
| | | @Override |
| | | public IPage<TaskVO> selectTaskPage(IPage<TaskVO> page, TaskVO task) { |
| | |
| | | // 消防隐患整改 |
| | | Integer xfyhzg = SpringUtils.getBean(ITaskPlaceRectificationService.class).getCount(neiCode, 1); |
| | | // 居住证申请 |
| | | Integer jzzsq = SpringUtils.getBean(ITaskResidencePermitApplyService.class).getCount(neiCode, 1); |
| | | Integer jzzsq = residencePermitApplyService.getCount(neiCode, 1); |
| | | // 无诈统计 |
| | | taskVO.setReportType(6); |
| | | Integer wztj = baseMapper.selectTaskCount(taskVO, commonParamSet.getRegionChildCodesList(), |
| | |
| | | return false; |
| | | } |
| | | |
| | | /** |
| | | * 创建居住证发送短信任务。 |
| | | * 该方法首先计算六个月前的日期,然后查询在该日期之后申请的居住证任务实体列表, |
| | | * 并对这些实体发送短信通知。 |
| | | * |
| | | * @param param 传递给发送短信任务的参数,具体用途根据实现而定。 |
| | | * @return 返回一个布尔值,通常用于指示任务是否创建成功。 |
| | | * 根据实际逻辑需要调整返回值,当前示例中返回值始终为false。 |
| | | */ |
| | | @Override |
| | | public boolean createResidenceSendSms(String param) { |
| | | try { |
| | | // 计算六个月前的日期 |
| | | LocalDate sixMonthsAgo = getSixMonthsAgo(); |
| | | // 查询需要发送短信的居住证申请实体列表 |
| | | List<TaskResidencePermitApplyEntity> entitiesToSms = queryEntitiesToSms(sixMonthsAgo); |
| | | // 发送短信并更新相关实体状态 |
| | | sendSmsAndUpdateEntities(entitiesToSms); |
| | | } catch (Exception e) { |
| | | // 处理发送短信过程中可能出现的异常,如记录日志 |
| | | logger.error("Error occurred while sending SMS: " + e.getMessage(), e); |
| | | return false; // 根据异常处理逻辑决定是否返回false或其他值 |
| | | } |
| | | return false; // 根据实际逻辑调整返回值 |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 获取六个月前的日期。 |
| | | * 该方法不接受任何参数,仅返回当前日期减去六个月的结果。 |
| | | * |
| | | * @return 返回一个LocalDate对象,表示六个月前的日期。 |
| | | */ |
| | | private LocalDate getSixMonthsAgo() { |
| | | // 获取当前日期并减去6个月 |
| | | return LocalDate.now().minus(6, ChronoUnit.MONTHS); |
| | | } |
| | | |
| | | /** |
| | | * 查询需要发送短信的居住证申请实体列表。 |
| | | * |
| | | * @param sixMonthsAgo 六个月前的日期,用于筛选确认时间在六个月之前的申请记录。 |
| | | * @return 返回一个包含所有符合条件的居住证申请实体的列表。 |
| | | */ |
| | | private List<TaskResidencePermitApplyEntity> queryEntitiesToSms(LocalDate sixMonthsAgo) { |
| | | // 使用LambdaQueryWrapper构建查询条件,筛选出确认状态为2(即确认),且未发送过短信(发送短信标志为1),确认时间在指定日期(sixMonthsAgo)之前的所有申请记录。 |
| | | return residencePermitApplyService.list(new LambdaQueryWrapper<TaskResidencePermitApplyEntity>() |
| | | .eq(TaskResidencePermitApplyEntity::getConfirmFlag, 2) |
| | | .eq(TaskResidencePermitApplyEntity::getSendSmsFlag, 1) |
| | | .le(TaskResidencePermitApplyEntity::getConfirmTime, sixMonthsAgo)); |
| | | } |
| | | |
| | | /** |
| | | * 发送短信并更新实体状态 |
| | | * |
| | | * @param entitiesToSms 需要发送短信并更新状态的实体列表,每个实体代表一个居住证申请任务。 |
| | | * 实体列表中每个元素应包含至少一个ID属性,用于标识申请任务。 |
| | | */ |
| | | private void sendSmsAndUpdateEntities(List<TaskResidencePermitApplyEntity> entitiesToSms) { |
| | | List<TaskResidencePermitApplyEntity> updatedEntities = new ArrayList<>(); // 用于收集成功发送短信并需更新状态的实体列表 |
| | | |
| | | for (TaskResidencePermitApplyEntity entity : entitiesToSms) { |
| | | // 尝试发送短信,发送成功则更新实体状态 |
| | | Boolean smsSent = smsSendService.sendNotice(SMS_TEMPLATE_ID, entity.getId()); |
| | | if (smsSent) { |
| | | entity.setSendSmsFlag(2); // 标记为已发送短信 |
| | | updatedEntities.add(entity); // 加入到需更新的实体列表中 |
| | | } |
| | | } |
| | | |
| | | // 若存在需更新的实体,则批量更新这些实体的状态 |
| | | if (!updatedEntities.isEmpty()) { |
| | | residencePermitApplyService.updateBatchById(updatedEntities); |
| | | } |
| | | } |
| | | } |