Pārlūkot izejas kodu

feat:“添加数据查询接口供客户使用"

soobin 7 mēneši atpakaļ
vecāks
revīzija
049629807b

+ 1 - 1
src/main/java/com/szwl/controller/AlarmRecordIndexController.java

@@ -146,7 +146,7 @@ public class AlarmRecordIndexController {
         }
         if (ifForeign.equals("1")) {
             String machineType = equipment.getMachineType();
-            if (StringUtils.isNotEmpty(machineType)) {
+            if (StringUtils.isEmpty(machineType)) {
                 machineType = "0";
             }
             if (StringUtils.isNotEmpty(messageReceiver)) {

+ 231 - 0
src/main/java/com/szwl/controller/ApiInterfaceController.java

@@ -0,0 +1,231 @@
+package com.szwl.controller;
+
+
+import cn.com.crbank.ommo.esUtil.BeanUtils;
+import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.szwl.constant.ResponseCodesEnum;
+import com.szwl.model.bo.R;
+import com.szwl.model.bo.ResponseModel;
+import com.szwl.model.entity.TAdmin;
+import com.szwl.model.entity.TEquipment;
+import com.szwl.model.entity.TProduct;
+import com.szwl.model.entity.TSugarDo;
+import com.szwl.model.param.InterfaceParam;
+import com.szwl.model.utils.PushUtils;
+import com.szwl.model.vo.MachineVo;
+import com.szwl.service.TAdminService;
+import com.szwl.service.TEquipmentService;
+import com.szwl.service.TProductService;
+import com.szwl.service.TSugarDoService;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import org.apache.commons.lang.StringUtils;
+import org.springframework.web.bind.annotation.*;
+
+import javax.annotation.Resource;
+import java.util.*;
+
+
+@Api(value = "/api", tags = {"第三方接口"})
+@RestController("ApiInterfaceController")
+@RequestMapping("/api")
+public class ApiInterfaceController {
+
+    @Resource
+    TAdminService adminService;
+
+    @Resource
+    TEquipmentService equipmentService;
+
+    @Resource
+    TProductService productService;
+
+    @Resource
+    TSugarDoService sugarDoService;
+
+    @ApiOperation("查询设备信息列表")
+    @PostMapping("/getMachineList")
+    public ResponseModel<?> getMachineList(@RequestHeader(value = "x-api-key") String apiKey, @RequestBody InterfaceParam interfaceParam) {
+        // 校验apiKey是否为空
+        if (StringUtils.isEmpty(apiKey)) {
+            return R.fail(ResponseCodesEnum.A0001, "apiKey is null");
+        }
+        // 校验参数是否为空
+        String username = interfaceParam.getUsername();
+        if (StringUtils.isEmpty(username)) {
+            return R.fail(ResponseCodesEnum.A0001, "username is null");
+        }
+        // 校验apiKey是否正确
+        LambdaQueryWrapper<TAdmin> wrapper = new LambdaQueryWrapper<>();
+        wrapper.eq(TAdmin::getUsername, username);
+        wrapper.eq(TAdmin::getApiKey, apiKey);
+        TAdmin admin = adminService.getOne(wrapper);
+        if (admin == null) {
+            return R.fail(ResponseCodesEnum.A0001, "Invalid apiKey or username is not exist");
+        }
+        Long size = interfaceParam.getSize();
+        Long current = interfaceParam.getCurrent();
+        if (size == null || current == null) {
+            return R.fail(ResponseCodesEnum.A0001, "size or current is null");
+        }
+        if (size > 15) {
+            return R.fail(ResponseCodesEnum.A0001, "size is too large");
+        }
+        ArrayList<MachineVo> machineVos = new ArrayList<>();
+        LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
+        query.eq(TEquipment::getAdminId, admin.getId());
+        query.orderByDesc(TEquipment::getCreateDate);
+        Page<TEquipment> page = new Page<>(interfaceParam.getCurrent(), interfaceParam.getSize(), true);
+        IPage<TEquipment> iPage = equipmentService.page(page, query);
+        iPage.getRecords().forEach(equipment -> {
+            MachineVo machineVo = new MachineVo();
+            BeanUtils.copyPropertiesIgnoreNull(equipment, machineVo, true);
+            machineVos.add(machineVo);
+        });
+        return R.ok(machineVos);
+    }
+
+    @ApiOperation("远程操作")
+    @PostMapping("/remoteOperation")
+    public ResponseModel<?> remoteOperation(@RequestHeader("x-api-key") String apiKey, @RequestBody InterfaceParam interfaceParam) {
+        // 校验apiKey是否为空
+        if (StringUtils.isEmpty(apiKey)) {
+            return R.fail(ResponseCodesEnum.A0001, "apiKey is null");
+        }
+        // 校验参数是否为空
+        String username = interfaceParam.getUsername();
+        String clientId = interfaceParam.getClientId();
+        if (StringUtils.isEmpty(username)) {
+            return R.fail(ResponseCodesEnum.A0001, "username is null");
+        }
+        // 校验apiKey是否正确
+        LambdaQueryWrapper<TAdmin> wrapper = new LambdaQueryWrapper<>();
+        wrapper.eq(TAdmin::getUsername, username);
+        wrapper.eq(TAdmin::getApiKey, apiKey);
+        TAdmin admin = adminService.getOne(wrapper);
+        if (admin == null) {
+            return R.fail(ResponseCodesEnum.A0001, "Invalid apiKey or username is not exist");
+        }
+        // 查询设备是否存在
+        if (StringUtils.isEmpty(clientId)) {
+            return R.fail(ResponseCodesEnum.A0001, "clientId is null");
+        }
+        LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
+        query.eq(TEquipment::getClientId, clientId);
+        query.eq(TEquipment::getAdminId, admin.getId());
+        TEquipment equipment = equipmentService.getOne(query);
+        if (equipment == null) {
+            return R.fail(ResponseCodesEnum.A0001, "clientId is not exist");
+        }
+        String operationField = interfaceParam.getOperationField();
+        String operationDesc = interfaceParam.getOperationDesc();
+        if (StringUtils.isNotEmpty(operationField) && StringUtils.isNotEmpty(operationDesc)) {
+            equipmentService.sentMessage(equipment.getClientId(), PushUtils.buildJson(operationField, operationDesc).toString());
+            return R.ok("success");
+        }
+        return R.fail(ResponseCodesEnum.A0001, "operationField or operationDesc is null");
+    }
+
+
+
+    @ApiOperation("远程制作")
+    @PostMapping("/remoteProduction")
+    public ResponseModel<?> remoteProduction(@RequestHeader("x-api-key") String apiKey, @RequestBody InterfaceParam interfaceParam) {
+        // 校验apiKey是否为空
+        if (StringUtils.isEmpty(apiKey)) {
+            return R.fail(ResponseCodesEnum.A0001, "apiKey is null");
+        }
+        // 校验参数是否为空
+        String username = interfaceParam.getUsername();
+        String clientId = interfaceParam.getClientId();
+        String productName = interfaceParam.getProductName();
+        if (StringUtils.isEmpty(username)) {
+            return R.fail(ResponseCodesEnum.A0001, "username is null");
+        }
+        if (StringUtils.isEmpty(clientId)) {
+            return R.fail(ResponseCodesEnum.A0001, "clientId is null");
+        }
+        if (StringUtils.isEmpty(productName)) {
+            return R.fail(ResponseCodesEnum.A0001, "productName is null");
+        }
+        // 校验apiKey是否正确
+        LambdaQueryWrapper<TAdmin> wrapper = new LambdaQueryWrapper<>();
+        wrapper.eq(TAdmin::getUsername, username);
+        wrapper.eq(TAdmin::getApiKey, apiKey);
+        TAdmin admin = adminService.getOne(wrapper);
+        if (admin == null) {
+            return R.fail(ResponseCodesEnum.A0001, "Invalid apiKey or username is not exist");
+        }
+        // 校验clientId是否正确
+        LambdaQueryWrapper<TEquipment> equipmentWrapper = new LambdaQueryWrapper<>();
+        equipmentWrapper.eq(TEquipment::getClientId, clientId);
+        equipmentWrapper.eq(TEquipment::getAdminId, admin.getId());
+        TEquipment equipment = equipmentService.getOne(equipmentWrapper);
+        if(equipment == null) {
+            return R.fail(ResponseCodesEnum.A0001, "clientId is not exist");
+        }
+        // 校验productName是否正确
+        LambdaQueryWrapper<TProduct> productWrapper = new LambdaQueryWrapper<>();
+        productWrapper.eq(TProduct::getProductName, productName);
+        productWrapper.eq(TProduct::getEquipmentId, equipment.getId());
+        TProduct product = productService.getOne(productWrapper);
+        if(product == null) {
+            return R.fail(ResponseCodesEnum.A0001, "productName is not exist");
+        }
+
+        Long adminId = equipment.getAdminId();
+        // 校验当天是否已经生产超过20个
+        List<TSugarDo> sugarDoList = getSugarDos(adminId);
+        if (sugarDoList.size() > 20) {
+            return R.fail(ResponseCodesEnum.A0001, "There have been over 20 remote productions today, please do them again tomorrow");
+        }
+        // 远程制作
+        remoteResult(productName, equipment, adminId);
+        return R.ok();
+    }
+
+    public void remoteResult(String productName, TEquipment equipment, Long adminId) {
+        StringBuilder number = new StringBuilder();
+        Random random = new Random();
+        number.append(adminId).append("-");
+        for (int i = 0; i < 6; i++) {
+            number.append(random.nextInt(10));
+        }
+        TSugarDo sugarDo = new TSugarDo();
+        sugarDo.setAdminId(adminId);
+        sugarDo.setClientId(equipment.getClientId());
+        sugarDo.setStatus("0");
+        sugarDo.setNo(number.toString());
+        sugarDo.setProductName(productName);
+        Date date = new Date();
+        sugarDo.setCreateDate(date);
+        sugarDo.setModifyDate(date);
+        sugarDoService.save(sugarDo);
+        JSONObject kindData = new JSONObject();
+        kindData.put("productName" , productName);
+        kindData.put("no" , sugarDo.getNo());
+        equipmentService.sentMessage(equipment.getClientId(), PushUtils.buildJson("dosugar", kindData.toString()).toString());
+    }
+
+    public List<TSugarDo> getSugarDos(Long adminId) {
+        LambdaQueryWrapper<TSugarDo> query = Wrappers.lambdaQuery();
+        query.eq(TSugarDo::getAdminId, adminId);
+        Calendar todayStart = Calendar.getInstance();
+        todayStart.set(Calendar.HOUR_OF_DAY, 0);
+        todayStart.set(Calendar.MINUTE, 0);
+        todayStart.set(Calendar.SECOND, 0);
+        query.gt(TSugarDo::getCreateDate,todayStart.getTime());
+        Calendar todayEnd = Calendar.getInstance();
+        todayEnd.set(Calendar.HOUR_OF_DAY, 23);
+        todayEnd.set(Calendar.MINUTE, 59);
+        todayEnd.set(Calendar.SECOND, 59);
+        query.le(TSugarDo::getCreateDate,todayEnd.getTime());
+        query.eq(TSugarDo::getStatus,"1");
+        List<TSugarDo> sugarDoList = sugarDoService.list(query);
+        return sugarDoList;
+    }
+}

+ 17 - 2
src/main/java/com/szwl/model/param/RemoteProParam.java

@@ -6,9 +6,9 @@ import lombok.Data;
 import lombok.experimental.Accessors;
 
 @Accessors(chain = true)
-@ApiModel(description = "远程制作参数")
+@ApiModel(description = "第三方接口调用参数")
 @Data
-public class RemoteProParam {
+public class InterfaceParam {
 
     @ApiModelProperty("账号登录名")
     private String username;
@@ -18,4 +18,19 @@ public class RemoteProParam {
 
     @ApiModelProperty("商品名称")
     private String productName;
+
+    @ApiModelProperty("操作字段")
+    private String operationField;
+
+    @ApiModelProperty("操作描述")
+    private String operationDesc;
+
+    @ApiModelProperty("商家id")
+    private Long adminId;
+
+    @ApiModelProperty("当前页")
+    private Long current;
+
+    @ApiModelProperty("每页条数")
+    private Long size;
 }

+ 55 - 0
src/main/java/com/szwl/model/vo/MachineVo.java

@@ -0,0 +1,55 @@
+package com.szwl.model.vo;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.util.Date;
+
+@Data
+public class MachineVo {
+
+    @ApiModelProperty(value = "机器名称")
+    private String name;
+
+    @ApiModelProperty(value = "设备编号")
+    private String clientId;
+
+    @ApiModelProperty(value = "柜内湿度")
+    private String cabinetHd;
+
+    @ApiModelProperty(value = "柜内温度")
+    private String cabinetTm;
+
+    @ApiModelProperty(value = "炉头温度")
+    private String furnaceTm;
+
+    @ApiModelProperty(value = "最近刷新时间")
+    private Date lastUpdateTime;
+
+    @ApiModelProperty(value = "设备状态 开机为1,关机为0")
+    private Integer eqeStatus;
+
+    @ApiModelProperty(value = "睡眠状态,睡眠为true,不睡眠false")
+    private Boolean isSleep;
+
+    @ApiModelProperty(value = "白糖")
+    private String whiteSugar;
+
+    @ApiModelProperty(value = "红糖")
+    private String redSugar;
+
+    @ApiModelProperty(value = "黄糖")
+    private String yellowSugar;
+
+    @ApiModelProperty(value = "蓝糖")
+    private String blueSugar;
+
+    @ApiModelProperty(value = "棍")
+    private String stick;
+
+    @ApiModelProperty(value = "水")
+    private String water;
+
+    @ApiModelProperty(value = "废水")
+    private String wasteWater;
+}

+ 0 - 1
src/main/java/com/szwl/util/WechatSendUtil.java

@@ -83,7 +83,6 @@ public class WechatSendUtil {
         StringBuffer content = new StringBuffer();
         String str1 = " <b>Machine name: </b>";
         String str2 = "<br>" + " <b>Error message: </b>";
-//        String sContent = "Abnormal shutdown/The network is disconnected.";
         String str3 = "<br>" + " Time&Date: ";
         String timeByZoneID = TimezoneFmtUtil.getTimeByZoneID(zoneId);
         String str4 = "<br>" + "<br>" + "Dear customer:<br>";