优化第一版
This commit is contained in:
@ -21,4 +21,9 @@ public interface DishesApi {
|
||||
* @Description: 根据菜品id 获取菜品名称
|
||||
*/
|
||||
public Map<Long,String> getDishName(List<Long> ids);
|
||||
|
||||
/**
|
||||
* @Description: 根据菜品id 批量获取菜品信息
|
||||
*/
|
||||
public List<DishesRespDto> getDishInfo(List<Long> ids);
|
||||
}
|
||||
|
@ -32,5 +32,14 @@ public class DishesRespDto {
|
||||
private String dishecType;
|
||||
|
||||
private LocalDateTime createTime;
|
||||
/**
|
||||
* 总价格
|
||||
*/
|
||||
private BigDecimal dishesSumPrice;
|
||||
/**
|
||||
* 菜品总重量
|
||||
*/
|
||||
private BigDecimal dishesNumber;
|
||||
|
||||
|
||||
}
|
@ -8,7 +8,6 @@ import cn.iocoder.yudao.module.system.service.dishes.DishesService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@ -33,4 +32,10 @@ public class DishesApiImpl implements DishesApi {
|
||||
public Map<Long, String> getDishName(List<Long> ids) {
|
||||
return dishesService.getDishName(ids);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DishesRespDto> getDishInfo(List<Long> ids) {
|
||||
List<DishesDO> dishesList = dishesService.getDishesList(ids);
|
||||
return BeanUtils.toBean(dishesList, DishesRespDto.class);
|
||||
}
|
||||
}
|
@ -1,12 +1,11 @@
|
||||
package cn.iocoder.yudao.module.system.controller.admin.deviceinfo.vo;
|
||||
|
||||
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
|
||||
import com.alibaba.excel.annotation.ExcelProperty;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import java.util.*;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import com.alibaba.excel.annotation.*;
|
||||
|
||||
@Schema(description = "管理后台 - 设备信息关联门店 Response VO")
|
||||
@Data
|
||||
@ -41,4 +40,9 @@ public class DeviceInfoRespVO {
|
||||
@ExcelProperty("创建时间")
|
||||
private LocalDateTime createTime;
|
||||
|
||||
/**
|
||||
* 是否在线
|
||||
*/
|
||||
private String alive;
|
||||
|
||||
}
|
@ -8,6 +8,7 @@ import cn.iocoder.yudao.module.system.controller.app.devuce.vo.DevuceReqVO;
|
||||
import cn.iocoder.yudao.module.system.controller.app.devuce.vo.DevuceSaveReqVO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.dishes.DishesDO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.dishestype.DishesTypeDO;
|
||||
import cn.iocoder.yudao.module.system.service.deviceinfo.DeviceInfoService;
|
||||
import cn.iocoder.yudao.module.system.service.devuce.DevuceService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
@ -39,6 +40,8 @@ public class AppDevuceController {
|
||||
|
||||
@Resource
|
||||
private DevuceService devuceService;
|
||||
@Resource
|
||||
private DeviceInfoService deviceInfoService;
|
||||
|
||||
// @PostMapping("/create")
|
||||
// @Operation(summary = "创建设备")
|
||||
@ -130,4 +133,11 @@ public class AppDevuceController {
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@GetMapping("/alive")
|
||||
@Operation(summary = "在线检测")
|
||||
public void alive() {
|
||||
deviceInfoService.alive();
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -44,4 +44,9 @@ public class DeviceInfoDO extends BaseDO {
|
||||
* 门店名称
|
||||
*/
|
||||
private String carteenName;
|
||||
|
||||
/**
|
||||
* 是否在线
|
||||
*/
|
||||
private String alive;
|
||||
}
|
||||
|
@ -0,0 +1,34 @@
|
||||
package cn.iocoder.yudao.module.system.job;
|
||||
|
||||
import cn.iocoder.yudao.framework.quartz.core.handler.JobHandler;
|
||||
import cn.iocoder.yudao.framework.tenant.core.aop.TenantIgnore;
|
||||
import cn.iocoder.yudao.module.system.service.deviceinfo.DeviceInfoService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* @author zt
|
||||
* @description <description class purpose>
|
||||
* @since 2024/7/17
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class DevuceAliveJob implements JobHandler {
|
||||
|
||||
|
||||
@Resource
|
||||
private DeviceInfoService deviceInfoService;
|
||||
|
||||
|
||||
@Override
|
||||
@TenantIgnore
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public String execute(String param) {
|
||||
int size = deviceInfoService.updateAlive();
|
||||
log.info("[execute][设备在线检测任务下线数量 ({}) 个]", size);
|
||||
return String.format("设备在线检测任务下线数量 %s 个", size);
|
||||
}
|
||||
}
|
@ -52,4 +52,11 @@ public interface DeviceInfoService {
|
||||
*/
|
||||
PageResult<DeviceInfoDO> getDeviceInfoPage(DeviceInfoPageReqVO pageReqVO);
|
||||
|
||||
void alive();
|
||||
|
||||
int updateAlive();
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
@ -7,10 +7,17 @@ import cn.iocoder.yudao.module.system.controller.admin.deviceinfo.vo.DeviceInfoS
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.deviceInfo.DeviceInfoDO;
|
||||
import cn.iocoder.yudao.module.system.dal.mysql.deviceInfo.DeviceInfoMapper;
|
||||
import cn.iocoder.yudao.module.system.enums.ErrorCodeConstants;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
|
||||
@ -26,6 +33,12 @@ public class DeviceInfoServiceImpl implements DeviceInfoService {
|
||||
@Resource
|
||||
private DeviceInfoMapper deviceInfoMapper;
|
||||
|
||||
@Resource
|
||||
private StringRedisTemplate RedisTemplate;
|
||||
|
||||
@Resource
|
||||
private HttpServletRequest httpServletRequest;
|
||||
|
||||
@Override
|
||||
public Long createDeviceInfo(DeviceInfoSaveReqVO createReqVO) {
|
||||
// 插入
|
||||
@ -68,4 +81,43 @@ public class DeviceInfoServiceImpl implements DeviceInfoService {
|
||||
return deviceInfoMapper.selectPage(pageReqVO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void alive() {
|
||||
String deviceSn = getHearder();
|
||||
RedisTemplate.opsForValue().set(deviceSn, String.valueOf(System.currentTimeMillis()));
|
||||
deviceInfoMapper.update(new DeviceInfoDO(),new LambdaUpdateWrapper<DeviceInfoDO>()
|
||||
.eq(DeviceInfoDO::getDeviceIp,deviceSn)
|
||||
.set(DeviceInfoDO::getAlive,"1"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int updateAlive() {
|
||||
List<String> updateList = new ArrayList<>();
|
||||
List<DeviceInfoDO> deviceInfoDOS = deviceInfoMapper.selectList();
|
||||
List<String> devuceList = deviceInfoDOS.stream().map(DeviceInfoDO::getDeviceIp).collect(Collectors.toList());
|
||||
for (String deviceSn : devuceList){
|
||||
String time = RedisTemplate.opsForValue().get(deviceSn);
|
||||
if(StringUtils.isBlank(time)){
|
||||
updateList.add(deviceSn);
|
||||
continue;
|
||||
}
|
||||
if(System.currentTimeMillis()-Long.valueOf(time)>120000){
|
||||
updateList.add(deviceSn);
|
||||
}
|
||||
}
|
||||
|
||||
deviceInfoMapper.update(new DeviceInfoDO(),new LambdaUpdateWrapper<DeviceInfoDO>()
|
||||
.set(DeviceInfoDO::getAlive,"0")
|
||||
.in(DeviceInfoDO::getDeviceIp,updateList));
|
||||
return updateList.size();
|
||||
}
|
||||
|
||||
public String getHearder(){
|
||||
try {
|
||||
return httpServletRequest.getHeader("Authorization");
|
||||
} catch (Exception e) {
|
||||
throw exception(2000_10_001,"无法获取设备编码");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -92,4 +92,5 @@ public interface DevuceService {
|
||||
void updateWeight(DevuceReqVO updateReqVO);
|
||||
List<DevuceListVO> getList();
|
||||
|
||||
|
||||
}
|
@ -53,6 +53,8 @@ public class DevuceServiceImpl implements DevuceService {
|
||||
private DeviceInfoMapper deviceInfoMapper;
|
||||
@Resource
|
||||
private DishesNutritionMapper dishesNutritionMapper;
|
||||
|
||||
|
||||
@Override
|
||||
public Long createDevuce(DevuceSaveReqVO createReqVO) {
|
||||
// 插入
|
||||
@ -245,4 +247,5 @@ public class DevuceServiceImpl implements DevuceService {
|
||||
List<DevuceListVO> list = devuceMapper.getList();
|
||||
return list;
|
||||
}
|
||||
|
||||
}
|
@ -46,6 +46,8 @@ public interface DishesService {
|
||||
* @return 菜品管理
|
||||
*/
|
||||
DishesDO getDishes(Long id);
|
||||
|
||||
List<DishesDO> getDishesList(List<Long> ids);
|
||||
DishesRespVO getDishes1(Long id);
|
||||
|
||||
/**
|
||||
|
@ -122,6 +122,12 @@ public class DishesServiceImpl implements DishesService {
|
||||
return dishesMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DishesDO> getDishesList(List<Long> ids) {
|
||||
return dishesMapper.selectList(Wrappers.<DishesDO>lambdaQuery()
|
||||
.in(DishesDO::getId,ids));
|
||||
}
|
||||
|
||||
@Override
|
||||
public DishesRespVO getDishes1(Long id) {
|
||||
DishesRespVO bean = BeanUtils.toBean(dishesMapper.selectById(id), DishesRespVO.class);
|
||||
|
Reference in New Issue
Block a user