提交 16b2ca93 authored 作者: zhoushaopan's avatar zhoushaopan

feat(装备模块,缓存模块): 新增了自定义注解,增加了装备的接口,完善缓存的维护,新增缓存更新接口

新增了自定义注解,增加了装备的接口,完善缓存的维护,新增缓存更新接口
上级 3aaf1260
...@@ -112,8 +112,8 @@ public class DeviceApplyController { ...@@ -112,8 +112,8 @@ public class DeviceApplyController {
@Autowired @Autowired
private PackingController packingController; private PackingController packingController;
@Autowired // @Autowired
private DeviceLibraryDao deviceLibraryDao; // private DeviceLibraryDao deviceLibraryDao;
@ApiOperation(value = "发起装备申请", notes = "可以通过这个接口发起装备申请") @ApiOperation(value = "发起装备申请", notes = "可以通过这个接口发起装备申请")
@PostMapping("/addDeviceApplyBill") @PostMapping("/addDeviceApplyBill")
...@@ -500,7 +500,8 @@ public class DeviceApplyController { ...@@ -500,7 +500,8 @@ public class DeviceApplyController {
seqs.addAll(DeviceSeqUtil.selectDeviceSeqs(r.getSeqInterval())); seqs.addAll(DeviceSeqUtil.selectDeviceSeqs(r.getSeqInterval()));
} }
} }
deviceLibraryDao.upDateSeqNumbersApplyTaskId(taskBto.getId(), seqs); // deviceLibraryDao.upDateSeqNumbersApplyTaskId(taskBto.getId(), seqs);
deviceLibraryService.upDateSeqNumbersApplyTaskId(taskBto.getId(),seqs);
} }
} }
return ResponseEntity.ok("ok"); return ResponseEntity.ok("ok");
......
package com.tykj.dev.config;
import java.lang.annotation.*;
/**
* UpdateCache注解
*
* @author zsp
*/
@Target({ElementType.METHOD,ElementType.FIELD})
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface UpdateCache {
String type() default "";
}
...@@ -867,7 +867,7 @@ public class DeviceLibraryController { ...@@ -867,7 +867,7 @@ public class DeviceLibraryController {
@ApiOperation(value = "修改装备的存放位置") @ApiOperation(value = "修改装备的存放位置")
@PostMapping("/updateDeviceLibraryLocation") @PostMapping("/updateDeviceLibraryLocation")
@CacheEvict(value = "devicesLibraryList",key = "'device'",allEntries = true) // @CacheEvict(value = "devicesLibraryList",key = "'device'",allEntries = true)
public void updateDeviceLibraryLocation(@RequestBody DeviceStorageLocation deviceStorageLocation){ public void updateDeviceLibraryLocation(@RequestBody DeviceStorageLocation deviceStorageLocation){
DeviceLibrary deviceLibrary = deviceLibraryService.getOne(deviceStorageLocation.getDevId()); DeviceLibrary deviceLibrary = deviceLibraryService.getOne(deviceStorageLocation.getDevId());
//添加修改存放装备位置 //添加修改存放装备位置
...@@ -875,12 +875,12 @@ public class DeviceLibraryController { ...@@ -875,12 +875,12 @@ public class DeviceLibraryController {
DeviceLogDto deviceLogDto = new DeviceLogDto(deviceStorageLocation.getDevId(), "将存放位置改为"+deviceStorageLocation.getStorageLocation(), null,null,null); DeviceLogDto deviceLogDto = new DeviceLogDto(deviceStorageLocation.getDevId(), "将存放位置改为"+deviceStorageLocation.getStorageLocation(), null,null,null);
deviceLogService.addLog(deviceLogDto); deviceLogService.addLog(deviceLogDto);
deviceLibraryService.update(deviceLibrary); deviceLibraryService.update(deviceLibrary);
//异步去查询数据库 // //异步去查询数据库
executor.execute( // executor.execute(
()->{ // ()->{
cacheLibraryService.getAllDeviceLibraryList(); // cacheLibraryService.getAllDeviceLibraryList();
} // }
); // );
} }
@ApiOperation("根据装备id修改装备的序列号") @ApiOperation("根据装备id修改装备的序列号")
...@@ -944,6 +944,29 @@ public class DeviceLibraryController { ...@@ -944,6 +944,29 @@ public class DeviceLibraryController {
return deviceNewVoList; return deviceNewVoList;
} }
@ApiOperation(value = "查询可进行绑定的装备", notes = "查询可进行绑定的装备")
@GetMapping("/selectBindingDevice")
public List<DeviceLibrary> selectBindingDevice(){
List<DeviceLibrary> deviceLibraries = cacheLibraryService.getAllDeviceLibraryList().stream()
.filter(deviceLibrary -> deviceLibrary.getPartParentId() == null).collect(Collectors.toList());
// cacheLibraryService.asyncUpdateCache();
return deviceLibraries;
}
@ApiOperation(value = "解除装备绑定", notes = "解除装备绑定")
@GetMapping("/relieveDevice/{deviceId}")
public ResponseEntity relieveDevice(@PathVariable("deviceId") Integer deviceId){
deviceLibraryService.relieveDevice(deviceId);
return ResponseEntity.ok("解除成功");
}
@ApiOperation(value = "进行装备绑定", notes = "进行装备绑定")
@PostMapping("/bindingDevice")
public ResponseEntity bindingDevice(BindingDeviceVo bindingDeviceVo){
deviceLibraryService.bindingDevice(bindingDeviceVo);
return ResponseEntity.ok("绑定成功");
}
/** /**
* 测试 * 测试
*/ */
......
...@@ -191,5 +191,22 @@ public interface DeviceLibraryDao extends JpaRepository<DeviceLibrary, Integer>, ...@@ -191,5 +191,22 @@ public interface DeviceLibraryDao extends JpaRepository<DeviceLibrary, Integer>,
int updateMatchingRange2(Integer matchingRange,@Param("deviceIds") List<Integer> deviceIds); int updateMatchingRange2(Integer matchingRange,@Param("deviceIds") List<Integer> deviceIds);
List<DeviceLibrary> findByModelAndIsPart(String model,Integer isPart); List<DeviceLibrary> findByModelAndIsPart(String model,Integer isPart);
List<DeviceLibrary> findAllByPartParentId(Integer partParentId);
@Transactional
@Modifying
@Query("update DeviceLibrary o set o.model = :newModel,o.packingId = :packingId where o.id in :deviceIds")
int updateModelAndPackingId(
@Param("newModel") String newModel,
@Param("packingId") Integer packingId,
@Param("deviceIds") List<Integer> deviceIds);
@Transactional
@Modifying
@Query("update DeviceLibrary o set o.packingId = :packingId where o.id in :deviceIds")
int updatePackingId(
@Param("packingId") Integer packingId,
@Param("deviceIds") List<Integer> deviceIds);
} }
...@@ -26,4 +26,6 @@ public interface DeviceLibraryCacheService { ...@@ -26,4 +26,6 @@ public interface DeviceLibraryCacheService {
void deletAllDeviceLibraryList(); void deletAllDeviceLibraryList();
void asyncUpdateCache();
} }
package com.tykj.dev.device.library.service; package com.tykj.dev.device.library.service;
import com.tykj.dev.device.library.subject.domin.DeviceLibrary; import com.tykj.dev.device.library.subject.domin.DeviceLibrary;
import com.tykj.dev.device.library.subject.vo.BindingDeviceVo;
import com.tykj.dev.device.library.subject.vo.DeviceLibrarySelectVo; import com.tykj.dev.device.library.subject.vo.DeviceLibrarySelectVo;
import com.tykj.dev.device.library.subject.vo.DeviceStatisticsVo; import com.tykj.dev.device.library.subject.vo.DeviceStatisticsVo;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort; import org.springframework.data.domain.Sort;
import org.springframework.data.repository.query.Param;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -206,11 +208,6 @@ public interface DeviceLibraryService { ...@@ -206,11 +208,6 @@ public interface DeviceLibraryService {
*/ */
DeviceLibrary findBySeqNumber(String seqNumber); DeviceLibrary findBySeqNumber(String seqNumber);
// /**
// *
// */
// List<DeviceLibrary> findByIds2(List<Integer> ids);
/** /**
* 得到所有的装备 * 得到所有的装备
*/ */
...@@ -245,7 +242,8 @@ public interface DeviceLibraryService { ...@@ -245,7 +242,8 @@ public interface DeviceLibraryService {
void updateDevicesOwnUnit(List<Integer> deviceIds); void updateDevicesOwnUnit(List<Integer> deviceIds);
/** /**
* @param * @param localUnit 所在单位
* @param deviceIds 装备id的集合
*/ */
void updateLocalAndOwn(String localUnit,List<Integer> deviceIds); void updateLocalAndOwn(String localUnit,List<Integer> deviceIds);
...@@ -264,6 +262,173 @@ public interface DeviceLibraryService { ...@@ -264,6 +262,173 @@ public interface DeviceLibraryService {
*/ */
List<DeviceLibrary> findDevicesByPacking(Integer packing); List<DeviceLibrary> findDevicesByPacking(Integer packing);
/**
* 更新配用范围
* @param libraries 装备的集合
*/
void updateMatchingRange(List<DeviceLibrary> libraries); void updateMatchingRange(List<DeviceLibrary> libraries);
/**
* 装备的解除
* @param deviceId 装备id
*/
void relieveDevice(int deviceId);
/**
* 装备的绑定
* @param
*/
void bindingDevice(BindingDeviceVo bindingDeviceVo);
/**
* 以下接口都为缓存做铺垫
*/
/**
* 更新设备序列号
* @param taskId 任务id
* @param seqNumbers 序列号的集合
*/
void upDateSeqNumbersApplyTaskId(Integer taskId,List<String> seqNumbers);
List<DeviceLibrary> findAllByOwnUnit(String ownUnit);
List<DeviceLibrary> getAllByRfidCardId(String rfidCardId);
/**
* 根据装备id的集合更新装备的生命状态
* @param lifeStatus 生命状态
* @param idList 装备id的集合
* @return
*/
int upDateLeftStatus(Integer lifeStatus,@Param("idList") List<Integer> idList);
/**
* 根据装备id的集合更新装备的生命状态
* @param lifeStatus 生命状态
* @param seqNumbers 装备序列号的集合
* @return 影响行数
*/
int upDateSeqNumbersLeftStatus(Integer lifeStatus,@Param("seqNumbers") List<String> seqNumbers);
/**
* 根据装备id的集合更新装备的生命状态和lock
* @param lifeStatus 生命状态
* @param lock 是否解锁
* @param idList 装备id的集合
* @return 影响行数
*/
int upDateLeftStatusAndLockStatus(Integer lifeStatus,Integer lock,@Param("idList") List<Integer> idList);
/**
* 根据装备id的集合更新lock
* @param lock 解锁
* @param idList 装备id的集合
* @return 影响行数
*/
int upDateLockStatus(Integer lock,@Param("idList") List<Integer> idList);
/**
* 根据装备id的集合更新生命状态和单位名称
* @param lifeStatus
* @param unitName
* @param lock
* @param idList
* @return 影响行数
*/
int upDateLeftStatusAndUnitNameAndLockStatus(Integer lifeStatus,String unitName,Integer lock,@Param("idList") List<Integer> idList);
/**
* 根据装备的序列号的集合更新生命状态和单位名称和锁
* @param lifeStatus 生命状态
* @param unitName 单位名称
* @param lock 锁
* @param seqNumbers 装备序列号的集合
* @return 影响行数
*/
int upDateSeqNumbersLeftStatusAndUnitNameAndLockStatus(Integer lifeStatus,String unitName,Integer lock,@Param("seqNumbers") List<String> seqNumbers);
/**
* 根据装备id的集合更新生命状态和所属单位
* @param lifeStatus 生命状态
* @param unitName 所属单位
* @param idList 装备id的集合
* @return 影响行数
*/
int upDateLeftStatusAndOwnUnitName(Integer lifeStatus,String unitName,@Param("idList") List<Integer> idList);
/**
* 根据装备id的集合更新RFID表面号
* @param idList 装备id的集合
* @return 影响行数
*/
int upDateRfidSurfaceIdAsSeqNumber(@Param("idList") List<Integer> idList);
/**
* 根据列装id更新名称
* @param name 名称
* @param packingId 列装id
* @return 影响行数
*/
int upDateName(String name,Integer packingId);
/**
* 根据列装id更新配用范围
* @param matchingRange 配用范围
* @param packingId 列装id
* @return 影响函数
*/
int upDateMatchingRange(Integer matchingRange,Integer packingId);
/**
* 根据装备id更新生命状态
* @param lifeStatus 生命状态
* @param id 装备id
* @return
*/
int batchUpdate(Integer lifeStatus,Integer id);
/**
* 根据装备id更新生命状态
* @param lifeStatus 生命状态
* @param ids 装备id的集合
* @return
*/
int batchUpdate2(Integer lifeStatus,List<Integer> ids);
/**
* 根据列装id更新配用范围
* @param matchingRange 配用范围
* @param packingId 列装id
* @return 影响行数
*/
int updateMatchingRange(Integer matchingRange,Integer packingId);
/**
* 根据列装id更新配用范围
* @param matchingRange 配用范围
* @param deviceIds 装备id的集合
* @return 影响行数
*/
int updateMatchingRange2(Integer matchingRange,@Param("deviceIds") List<Integer> deviceIds);
/**
* 更新型号和列装id
* @param newModel 新的型号
* @param packingId 列装id
* @param deviceIds 装备id集合
* @return 影响行数
*/
int updateModelAndPackingId(String newModel,Integer packingId,List<Integer> deviceIds);
/**
* 根据装备id的集合更新列装id
* @param packingId 列装id
* @param deviceIds 装备id的集合
* @return 影响行数
*/
int updatePackingId(Integer packingId,List<Integer> deviceIds);
/**
* 查询所有装备
*/
List<DeviceLibrary> findAllDevices();
} }
...@@ -3,7 +3,9 @@ package com.tykj.dev.device.library.service.impl; ...@@ -3,7 +3,9 @@ package com.tykj.dev.device.library.service.impl;
import com.tykj.dev.device.library.repository.DeviceLibraryDao; import com.tykj.dev.device.library.repository.DeviceLibraryDao;
import com.tykj.dev.device.library.service.DeviceLibraryCacheService; import com.tykj.dev.device.library.service.DeviceLibraryCacheService;
import com.tykj.dev.device.library.subject.domin.DeviceLibrary; import com.tykj.dev.device.library.subject.domin.DeviceLibrary;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.cache.annotation.CacheConfig; import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict; import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut; import org.springframework.cache.annotation.CachePut;
...@@ -13,6 +15,7 @@ import org.springframework.stereotype.Service; ...@@ -13,6 +15,7 @@ import org.springframework.stereotype.Service;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.concurrent.Executor;
import java.util.function.Function; import java.util.function.Function;
import java.util.stream.Collectors; import java.util.stream.Collectors;
...@@ -22,20 +25,26 @@ import java.util.stream.Collectors; ...@@ -22,20 +25,26 @@ import java.util.stream.Collectors;
*/ */
@Service @Service
@CacheConfig(cacheNames = "devicesLibraryList") @CacheConfig(cacheNames = "devicesLibraryList")
@Slf4j
public class CacheLibraryServiceImpl implements DeviceLibraryCacheService { public class CacheLibraryServiceImpl implements DeviceLibraryCacheService {
@Autowired @Autowired
private DeviceLibraryDao deviceLibraryDao; private DeviceLibraryDao deviceLibraryDao;
@Autowired
@Qualifier("taskExecutor")
private Executor executor;
// @Autowired // @Autowired
// private ConcurrentMapCacheManager mapCacheManager; // private ConcurrentMapCacheManager mapCacheManager;
@Autowired @Autowired
private DeviceLibraryCacheService deviceLibraryCacheService; private DeviceLibraryCacheService deviceLibraryCacheService;
@Override @Override
@Cacheable(key = "'device'") @Cacheable(key = "'device'")
public List<DeviceLibrary> getAllDeviceLibraryList() { public List<DeviceLibrary> getAllDeviceLibraryList() {
long l = System.currentTimeMillis(); long start = System.currentTimeMillis();
List<DeviceLibrary> all = deviceLibraryDao.findAll(); List<DeviceLibrary> all = deviceLibraryDao.findAll();
log.info("缓存时间:{}", System.currentTimeMillis() - start);
return all; return all;
} }
...@@ -63,4 +72,14 @@ public class CacheLibraryServiceImpl implements DeviceLibraryCacheService { ...@@ -63,4 +72,14 @@ public class CacheLibraryServiceImpl implements DeviceLibraryCacheService {
// List<DeviceLibrary> all = deviceLibraryDao.findAll(); // List<DeviceLibrary> all = deviceLibraryDao.findAll();
// System.out.println("更新缓存时间"+(System.currentTimeMillis()-l)); // System.out.println("更新缓存时间"+(System.currentTimeMillis()-l));
} }
@Override
@CacheEvict(key = "'device'",allEntries=true)
public void asyncUpdateCache() {
executor.execute(()->{
deviceLibraryCacheService.getAllDeviceLibraryList();
});
}
} }
...@@ -19,11 +19,11 @@ public class DevideTask { ...@@ -19,11 +19,11 @@ public class DevideTask {
@Autowired @Autowired
DeviceLibraryCacheService deviceLibraryCacheService; DeviceLibraryCacheService deviceLibraryCacheService;
@Scheduled(cron = "30 * * * * ? ") // @Scheduled(cron = "30 * * * * ? ")
private void signUpDeadline() { // private void signUpDeadline() {
log.info("定时device更新缓存开始"); // log.info("定时device更新缓存开始");
deviceLibraryCacheService.deletAllDeviceLibraryList(); // deviceLibraryCacheService.deletAllDeviceLibraryList();
deviceLibraryCacheService.getAllDeviceLibraryList(); // deviceLibraryCacheService.getAllDeviceLibraryList();
log.info("定时device更新缓存结束"); // log.info("定时device更新缓存结束");
} // }
} }
package com.tykj.dev.union;
import com.tykj.dev.device.library.service.DeviceLibraryCacheService;
import com.tykj.dev.device.library.subject.vo.FileVo;
import com.tykj.dev.device.matching.service.MatchingDeviceBillService;
import com.tykj.dev.device.matching.subject.domin.MatchingDeviceBill;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
* 增强更新缓存aop
*
* @author zsp
*/
@Slf4j
@Aspect
@Component
public class UpdateCacheAspect {
/**
* 业务新状态
*/
@Autowired
private DeviceLibraryCacheService deviceLibraryCacheService;
/**
* 更新缓存定义切入点
*/
@Pointcut("@annotation(com.tykj.dev.config.UpdateCache)")
public void operationLog() {
}
/**
* 新增结果返回后触发
*/
@AfterReturning(pointcut = "operationLog()")
public void doAfterReturning(JoinPoint point) {
log.info("开始更新缓存");
deviceLibraryCacheService.asyncUpdateCache();
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论