| New file |
| | |
| | | package com.zy.third.task; |
| | | |
| | | import com.zy.third.entity.ExdMaterial; |
| | | import com.zy.third.entity.ExdUser; |
| | | import com.zy.third.mapper.ExdMaterialMapper; |
| | | import com.zy.third.mapper.ExdUserMapper; |
| | | import com.zy.third.task.handler.BaseDataHandler; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.scheduling.annotation.Scheduled; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | @Component |
| | | @Slf4j |
| | | public class BaseDataScheduler { |
| | | |
| | | |
| | | @Autowired |
| | | private BaseDataHandler baseDataHandler; |
| | | |
| | | |
| | | @Autowired |
| | | private ExdUserMapper exdUserMapper; |
| | | |
| | | |
| | | @Autowired |
| | | private ExdMaterialMapper exdMaterialMapper; |
| | | |
| | | |
| | | /** |
| | | * 读取用户信息 |
| | | */ |
| | | @Scheduled(cron = "0/30 * * * * ? ") |
| | | public void readUser() { |
| | | log.info("读取用户信息"); |
| | | List<ExdUser> exdUsers = exdUserMapper.listAll(); |
| | | for (ExdUser exdUser : exdUsers) { |
| | | try { |
| | | if (baseDataHandler.readUser(exdUser).isSuccess()) { |
| | | exdUser.setStatus(1); |
| | | } else { |
| | | exdUser.setStatus(2); |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("读取用户信息失败:{},{}", exdUser, e.getMessage()); |
| | | exdUser.setStatus(2); |
| | | exdUser.setReadormsg(e.getMessage()); |
| | | } finally { |
| | | exdUser.setReadtime(new Date()); |
| | | exdUserMapper.updateById(exdUser); |
| | | } |
| | | |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 读取物料信息 |
| | | */ |
| | | @Scheduled(cron = "0/3 * * * * ? ") |
| | | public void readMat() { |
| | | log.info("读取物料信息"); |
| | | List<ExdMaterial> exdMaterials = exdMaterialMapper.listAll(); |
| | | for (ExdMaterial exdMaterial : exdMaterials) { |
| | | try { |
| | | if (baseDataHandler.readMat(exdMaterial).isSuccess()) { |
| | | exdMaterial.setStatus(1); |
| | | } else { |
| | | exdMaterial.setStatus(2); |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("读取物料信息失败:{},{}", exdMaterial, e.getMessage()); |
| | | exdMaterial.setStatus(2); |
| | | exdMaterial.setReadormsg(e.getMessage()); |
| | | } finally { |
| | | exdMaterial.setReadtime(new Date()); |
| | | exdMaterialMapper.updateById(exdMaterial); |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 读取部门信息 |
| | | */ |
| | | @Scheduled(cron = "0/30 * * * * ? ") |
| | | public void readDept() { |
| | | log.info("读取部门信息"); |
| | | |
| | | } |
| | | } |