diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/device/controller/DoubleScreenMachineController.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/device/controller/DoubleScreenMachineController.java index ef48166..168f6e2 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/device/controller/DoubleScreenMachineController.java +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/device/controller/DoubleScreenMachineController.java @@ -10,6 +10,7 @@ import com.bonus.canteen.core.alloc.domain.AllocCanteen; import com.bonus.canteen.core.alloc.domain.AllocStall; import com.bonus.canteen.core.alloc.mapper.AllocCanteenMapper; import com.bonus.canteen.core.alloc.mapper.AllocStallMapper; +import com.bonus.canteen.core.device.dto.ApkDTO; import com.bonus.canteen.core.device.dto.DeviceDTO; import com.bonus.canteen.core.device.dto.DeviceSearchDTO; import com.bonus.canteen.core.device.service.IDoubleScreenMachineService; @@ -118,6 +119,11 @@ public class DoubleScreenMachineController extends BaseController { return AjaxResult.success(); } - + @ApiOperation(value = "上传APK") + @PostMapping({"/uploadApk"}) + public AjaxResult uploadApk(@RequestBody @Valid ApkDTO dto) { + this.screenMachineService.uploadApk(dto); + return AjaxResult.success(); + } } diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/device/dto/ApkDTO.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/device/dto/ApkDTO.java new file mode 100644 index 0000000..c68169a --- /dev/null +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/device/dto/ApkDTO.java @@ -0,0 +1,14 @@ +package com.bonus.canteen.core.device.dto; + +import lombok.Data; + +@Data +public class ApkDTO { + private String version; + private String versionName; + private String apkName; + private String apkPath; + private String updateContent; + private String deployUser; + private String type; +} diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/device/mapper/DoubleScreenMachineMapper.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/device/mapper/DoubleScreenMachineMapper.java index 4b2aaae..2b3a645 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/device/mapper/DoubleScreenMachineMapper.java +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/device/mapper/DoubleScreenMachineMapper.java @@ -3,6 +3,7 @@ package com.bonus.canteen.core.device.mapper; import java.util.List; import com.bonus.canteen.core.device.domain.DeviceBind; +import com.bonus.canteen.core.device.dto.ApkDTO; import com.bonus.canteen.core.device.dto.DeviceDTO; import com.bonus.canteen.core.device.dto.DeviceSearchDTO; import com.bonus.canteen.core.device.vo.DeviceFullInfoVO; @@ -81,4 +82,10 @@ public interface DoubleScreenMachineMapper { int checkIsExistDeviceName(@Param("deviceName") @NotBlank(message = "设备名称必填") String deviceName,@Param("deviceId") String deviceId); int checkIsExistDeviceSn(@Param("deviceSn") @NotBlank(message = "设备sn码必填") String deviceSn,@Param("deviceId") String deviceId); + + ApkDTO getApkByType(@Param("type") String type,@Param("version") String version); + + int updateApk(ApkDTO dto); + + int insertApk(ApkDTO dto); } diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/device/service/IDoubleScreenMachineService.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/device/service/IDoubleScreenMachineService.java index 204c16f..05d1c81 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/device/service/IDoubleScreenMachineService.java +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/device/service/IDoubleScreenMachineService.java @@ -3,6 +3,7 @@ package com.bonus.canteen.core.device.service; import java.util.List; import com.bonus.canteen.core.device.domain.DeviceBind; import com.bonus.canteen.core.device.domain.DeviceInfo; +import com.bonus.canteen.core.device.dto.ApkDTO; import com.bonus.canteen.core.device.dto.DeviceDTO; import com.bonus.canteen.core.device.dto.DeviceSearchDTO; import com.bonus.canteen.core.device.vo.DeviceFullInfoVO; @@ -49,4 +50,6 @@ public interface IDoubleScreenMachineService { * @param sn */ void updateTimeBySn(String sn); + + void uploadApk(@Valid ApkDTO dto); } diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/device/service/impl/DoubleScreenMachineServiceImpl.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/device/service/impl/DoubleScreenMachineServiceImpl.java index 9eb3aab..be2e549 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/device/service/impl/DoubleScreenMachineServiceImpl.java +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/device/service/impl/DoubleScreenMachineServiceImpl.java @@ -1,13 +1,16 @@ package com.bonus.canteen.core.device.service.impl; +import java.sql.SQLIntegrityConstraintViolationException; import java.util.List; import cn.hutool.core.util.ObjectUtil; import com.bonus.canteen.core.common.utils.MqUtil; +import com.bonus.canteen.core.device.dto.ApkDTO; import com.bonus.canteen.core.device.dto.DeviceDTO; import com.bonus.canteen.core.device.dto.DeviceSearchDTO; import com.bonus.canteen.core.device.vo.DeviceFullInfoVO; import com.bonus.canteen.core.user.domain.DeviceMqPersonalUpdateMessageDTO; +import com.bonus.common.core.exception.ServiceException; import com.bonus.common.houqin.constant.GlobalConstants; import com.bonus.common.houqin.mq.constant.LeMqConstant; import com.bonus.common.houqin.utils.id.Id; @@ -49,43 +52,43 @@ public class DoubleScreenMachineServiceImpl implements IDoubleScreenMachineServi @Override @Transactional(rollbackFor = Exception.class) public void insert(DeviceDTO dto) { - if (dto == null){ + if (dto == null) { throw new RuntimeException("参数为空"); } if (ObjectUtil.isEmpty(dto.getDeviceName()) || ObjectUtil.isEmpty(dto.getDeviceSn()) || ObjectUtil.isEmpty(dto.getDeviceName()) - || ObjectUtil.isEmpty(dto.getAreaId()) || ObjectUtil.isEmpty(dto.getCanteenId()) || ObjectUtil.isEmpty(dto.getStallId())){ + || ObjectUtil.isEmpty(dto.getAreaId()) || ObjectUtil.isEmpty(dto.getCanteenId()) || ObjectUtil.isEmpty(dto.getStallId())) { throw new RuntimeException("请先讲填写所有必填项,再提交相关数据!"); } dto.setTenantId(GlobalConstants.TENANT_ID); dto.setCreateBy(String.valueOf(SecurityUtils.getUserId())); //判断设备sn、设备编号、设备名称是否存在 - int count = mapper.checkIsExistDeviceNum(dto.getDeviceNum(),null); - if (count > 0){ + int count = mapper.checkIsExistDeviceNum(dto.getDeviceNum(), null); + if (count > 0) { throw new RuntimeException("设备编号已存在"); } - count = mapper.checkIsExistDeviceName(dto.getDeviceName(),null); - if (count > 0){ + count = mapper.checkIsExistDeviceName(dto.getDeviceName(), null); + if (count > 0) { throw new RuntimeException("设备名称已存在"); } - count = mapper.checkIsExistDeviceSn(dto.getDeviceSn(),null); - if (count > 0){ + count = mapper.checkIsExistDeviceSn(dto.getDeviceSn(), null); + if (count > 0) { throw new RuntimeException("设备sn已存在"); } int code = mapper.insertMachine(dto); - if (code == 0){ + if (code == 0) { throw new RuntimeException("设备新增失败"); } code = mapper.insertMachineBind(dto); - if (code == 0){ + if (code == 0) { throw new RuntimeException("设备绑定失败"); } dto.setId(Id.next()); code = mapper.insertDeviceRecipe(dto); - if (code == 0){ + if (code == 0) { throw new RuntimeException("添加菜谱关联失败"); } //发送mq - DeviceMqPersonalUpdateMessageDTO bean = new DeviceMqPersonalUpdateMessageDTO().setUpdatePerson(0,"update"); + DeviceMqPersonalUpdateMessageDTO bean = new DeviceMqPersonalUpdateMessageDTO().setUpdatePerson(0, "update"); MqUtil.pushToSingleDevice(bean, LeMqConstant.Topic.DEVICE_UPDATE_INFO_V4, dto.getDeviceSn()); } @@ -97,41 +100,41 @@ public class DoubleScreenMachineServiceImpl implements IDoubleScreenMachineServi */ @Override public void update(DeviceDTO dto) { - if (dto == null){ + if (dto == null) { throw new RuntimeException("参数为空"); } if (ObjectUtil.isEmpty(dto.getDeviceName()) || ObjectUtil.isEmpty(dto.getDeviceSn()) || ObjectUtil.isEmpty(dto.getDeviceName()) - || ObjectUtil.isEmpty(dto.getAreaId()) || ObjectUtil.isEmpty(dto.getCanteenId()) || ObjectUtil.isEmpty(dto.getStallId())){ + || ObjectUtil.isEmpty(dto.getAreaId()) || ObjectUtil.isEmpty(dto.getCanteenId()) || ObjectUtil.isEmpty(dto.getStallId())) { throw new RuntimeException("请先讲填写所有必填项,再提交相关数据!"); } //判断设备sn、设备编号、设备名称是否存在 int count = mapper.checkIsExistDeviceNum(dto.getDeviceNum(), dto.getDeviceId()); - if (count > 0){ + if (count > 0) { throw new RuntimeException("设备编号已存在"); } count = mapper.checkIsExistDeviceName(dto.getDeviceName(), dto.getDeviceId()); - if (count > 0){ + if (count > 0) { throw new RuntimeException("设备名称已存在"); } count = mapper.checkIsExistDeviceSn(dto.getDeviceSn(), dto.getDeviceId()); - if (count > 0){ + if (count > 0) { throw new RuntimeException("设备sn已存在"); } int code = mapper.updateMachine(dto); - if (code == 0){ + if (code == 0) { throw new RuntimeException("设备更新失败"); } code = mapper.updateMachineBind(dto); - if (code == 0){ + if (code == 0) { throw new RuntimeException("设备绑定更新失败"); } code = mapper.updateDeviceRecipe(dto); - if (code == 0){ + if (code == 0) { throw new RuntimeException("修改菜谱关联失败"); } //发送mq - DeviceMqPersonalUpdateMessageDTO bean = new DeviceMqPersonalUpdateMessageDTO().setUpdatePerson(0,"update"); + DeviceMqPersonalUpdateMessageDTO bean = new DeviceMqPersonalUpdateMessageDTO().setUpdatePerson(0, "update"); MqUtil.pushToSingleDevice(bean, LeMqConstant.Topic.DEVICE_UPDATE_INFO_V4, dto.getDeviceSn()); } @@ -145,11 +148,11 @@ public class DoubleScreenMachineServiceImpl implements IDoubleScreenMachineServi @Transactional(rollbackFor = Exception.class) public void delete(String deviceId) { int code = mapper.deleteMachine(deviceId); - if (code == 0){ + if (code == 0) { throw new RuntimeException("设备删除失败"); } code = mapper.deleteMachineBind(deviceId); - if (code == 0){ + if (code == 0) { throw new RuntimeException("设备绑定删除失败"); } } @@ -162,8 +165,22 @@ public class DoubleScreenMachineServiceImpl implements IDoubleScreenMachineServi @Override public void updateTimeBySn(String sn) { int code = mapper.updateTimeBySn(sn); - if (code == 0){ + if (code == 0) { throw new RuntimeException("更新时间失败"); } } + + @Override + public void uploadApk(ApkDTO dto) { + try { + ApkDTO apkDTO = mapper.getApkByType(dto.getType(), dto.getVersion()); + if (apkDTO != null) { + mapper.updateApk(dto); + } else { + mapper.insertApk(dto); + } + } catch (Exception e) { + throw new ServiceException("操作失败"); + } + } } diff --git a/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/device/DoubleScreenMachineMapper.xml b/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/device/DoubleScreenMachineMapper.xml index fe08430..3d45243 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/device/DoubleScreenMachineMapper.xml +++ b/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/device/DoubleScreenMachineMapper.xml @@ -180,12 +180,19 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" and device_id != #{deviceId} + insert into device_recipe(id,device_id, canteen_id,stall_id, revision) values (#{id},#{deviceId}, #{canteenId}, #{stallId},'0') + + insert into app_version(version, version_name, apk_name, apk_path, update_content, deploy_user, type) + values (#{version}, #{versionName}, #{apkName}, #{apkPath}, #{updateContent}, #{deployUser}, #{type}) + update device_recipe @@ -202,4 +209,34 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" where device_id = #{deviceId} + + update app_version + + + version = #{version}, + + + version_name = #{versionName}, + + + apk_name = #{apkName}, + + + apk_path = #{apkPath}, + + + update_content = #{updateContent}, + + + update_content = #{updateContent}, + + + deploy_user = #{deployUser}, + + + type = #{type}, + + + where version = #{version} +