瀏覽代碼

设备审核添加爆米花

soobin 2 年之前
父節點
當前提交
39827c7166

+ 71 - 24
src/main/java/com/szwl/controller/TEquipmentApplyController.java

@@ -135,9 +135,10 @@ public class TEquipmentApplyController {
                         String companyType = tAdmin.getCompanyType();
                         String adminLevel = equipmentApply.getAdminLevel();
                         String adminUserName = equipmentApply.getAdminUserName();
-                        Integer type = equipmentApply.getType();
+                        Integer type = tAdmin.getType();
                         String gtClientId = equipmentApply.getGtClientId();
                         String equimentType = equipmentApply.getEquimentType();
+                        String machineType = equipmentApply.getMachineType();
                         String clientId1 = equipmentApply.getClientId();
                         //判断是否已经生成
                         LambdaQueryWrapper<TEquipment> query3 = Wrappers.lambdaQuery();
@@ -167,8 +168,9 @@ public class TEquipmentApplyController {
                             equipment.setAdminLevel(adminLevel);
                             equipment.setAdminUserName(adminUserName);
                             equipment.setType(type);
-                            equipment.setCompanyType(companyType); //公司平台
-                            if(equipmentApply.getEquimentType().equals("MG320-1")){
+                            equipment.setCompanyType(companyType); // 公司平台
+                            equipment.setMachineType(machineType); // 设备类型
+                            if(equimentType.equals("MG320-1")){
                                 if(!equipmentApply.getEquimentType().equals(equipment.getEquimentType())&&equipment.getEquimentType().equals("MG320")){
 //                                    List<Filter> filter = new ArrayList<>();
 //                                    filter.add(Filter.eq("equipmentId",  equipment.getId()));
@@ -184,10 +186,14 @@ public class TEquipmentApplyController {
 //                                    saveProductMG12(equipment.getId());
                                 }
                                 equipment.setEquimentType("MG320");
+                            } else {
+                                equipment.setEquimentType(equimentType);
                             }
-                            if(equipmentApply.getEquimentType().equals("MG330")){
-                                equipment.setEquimentType("MG330");
-                            }
+//                            if(equipmentApply.getEquimentType().equals("MG330")){
+//                                equipment.setEquimentType("MG330");
+//                            }
+//                            if(equipmentApply.getEquimentType().equals("POP320")) {
+//                            }
 
                             equipmentService.updateById(equipment);
                             LambdaQueryWrapper<TProportion> queryProportion = Wrappers.lambdaQuery();
@@ -204,8 +210,12 @@ public class TEquipmentApplyController {
                             }catch (Exception e) {
                                 e.printStackTrace();
                             }
-                            equipmentService.sentMessage(equipmentApply.getClientId(),PushUtils.buildJson("statusType", "agreed" + old).toString());
-                            PushUtils.push(equipmentApply.getGtClientId(), "【棉花糖】设备初始化申请", "同意", PushUtils.buildJson("statusType", "agreed" + old).toString());
+                            equipmentService.sentMessage(clientId,PushUtils.buildJson("statusType", "agreed" + old).toString());
+                            if(StringUtils.isEmpty(machineType) || machineType.equals("0")) {
+                                PushUtils.push(equipmentApply.getGtClientId(), "【棉花糖】设备初始化申请", "同意", PushUtils.buildJson("statusType", "agreed" + old).toString());
+                            } else {
+                                PushUtils.push(equipmentApply.getGtClientId(), "【爆米花】设备初始化申请", "同意", PushUtils.buildJson("statusType", "agreed" + old).toString());
+                            }
                             equipmentApplyService.updateById(equipmentApply);
                             if(equipment.getEndDate()!=null){
                                 equipmentService.sentMessage(equipmentApply.getClientId(),PushUtils.buildJson("endDate",String.valueOf(equipment.getEndDate().getTime()) ).toString());
@@ -229,7 +239,8 @@ public class TEquipmentApplyController {
                         equipment.setChannel("1");
                         equipment.setProductTotal(0);
                         equipment.setType(type);
-                        equipment.setCompanyType(companyType); //公司平台
+                        equipment.setCompanyType(companyType); // 公司平台
+                        equipment.setMachineType(machineType); // 设备类型
                         //设置默认规则
                         equipment.setTimeRuleId(Long.valueOf(1));
                         if(equimentType.equals("MG320-1")){
@@ -237,9 +248,9 @@ public class TEquipmentApplyController {
                         }else {
                             equipment.setEquimentType(equimentType);
                         }
-                        if(equipmentApply.getEquimentType().equals("MG330")){
-                            equipment.setEquimentType("MG330");
-                        }
+//                        if(equipmentApply.getEquimentType().equals("MG330")){
+//                            equipment.setEquimentType("MG330");
+//                        }
                         if(!StringUtils.isEmpty(equimentType)&&equimentType.equals("MG280")){
                             Long monthBegin = getMonthBegin(new Date());
                             long time = new Date().getTime();
@@ -255,41 +266,54 @@ public class TEquipmentApplyController {
                             }
                         }
                         equipmentService.save(equipment);
-                        equipmentService.sentMessage(equipmentApply.getClientId(), PushUtils.buildJson("statusType", "agreed" + old).toString());
-                        PushUtils.push(equipmentApply.getGtClientId(), "【棉花糖】设备初始化申请", "同意", PushUtils.buildJson("statusType", "agreed" + old).toString());
+                        equipmentService.sentMessage(clientId,PushUtils.buildJson("statusType", "agreed" + old).toString());
+                        if(StringUtils.isEmpty(machineType) || machineType.equals("0")) {
+                            PushUtils.push(equipmentApply.getGtClientId(), "【棉花糖】设备初始化申请", "同意", PushUtils.buildJson("statusType", "agreed" + old).toString());
+                        } else {
+                            PushUtils.push(equipmentApply.getGtClientId(), "【爆米花】设备初始化申请", "同意", PushUtils.buildJson("statusType", "agreed" + old).toString());
+                        }
                         //获取设备的id
                         Long equipmentId = equipment.getId();
-                        if(equipmentApply.getEquimentType()!=null&&equipmentApply.getEquimentType().equals("MG280")){
+                        if(equimentType !=null && equimentType.equals("MG280")){
                             saveProductMG280(equipmentId);
-                        } else if(equipmentApply.getEquimentType()!=null&&equipmentApply.getEquimentType().equals("MG320-1")){
+                        } else if(equimentType !=null&& equimentType.equals("MG320-1")){
                             saveProductMG1(equipmentId);
-                        } else{
-                                saveProduct(equipmentId);
+                        } else if(equimentType !=null&& equimentType.equals("POP320")){
+                            saveProductPOP320(equipmentId);
+                        } else {
+                            saveProduct(equipmentId);
                         }
                         LambdaQueryWrapper<TEquipment> query1 = Wrappers.lambdaQuery();
                         query1.eq(TEquipment::getClientId,clientId);
-                        List<TEquipment> list1 = equipmentService.list(query1);
+//                        List<TEquipment> list1 = equipmentService.list(query1);
+                        TEquipment tEquipment = equipmentService.getOne(query1);
                         try {
-                            if(list1.size()>0){
-                                TEquipment tEquipment = list1.get(0);
+//                            if(list1.size()>0){
+//                                TEquipment tEquipment = list1.get(0);
+//                                esTEquipmentService.insertData(tEquipment);
+//                            }
+                            if(tEquipment != null) {
                                 esTEquipmentService.insertData(tEquipment);
                             }
                         }catch (Exception e) {
                             e.printStackTrace();
                         }
                         TEquipmentDesc equipmentDesc = new TEquipmentDesc();
-                        equipmentDesc.setEquipmentId(list1.get(0).getId());
+                        equipmentDesc.setEquipmentId(tEquipment.getId());
                         equipmentDescService.save(equipmentDesc);
 
                     } else if (status.equals("unAgreed")) {
                         equipmentApply.setModifyDate(new Date());
                         equipmentApply.setStatusType(2);
                         equipmentService.sentMessage(equipmentApply.getClientId(),PushUtils.buildJson("statusType", "rejected").toString());
-                        PushUtils.push(equipmentApply.getGtClientId(), "【棉花糖】设备初始化申请", "拒绝", PushUtils.buildJson("statusType", "rejected").toString());
+                        if(StringUtils.isEmpty(equipmentApply.getMachineType()) || equipmentApply.getMachineType().equals("0")) {
+                            PushUtils.push(equipmentApply.getGtClientId(), "【棉花糖】设备初始化申请", "拒绝", PushUtils.buildJson("statusType", "rejected").toString());
+                        } else {
+                            PushUtils.push(equipmentApply.getGtClientId(), "【爆米花】设备初始化申请", "拒绝", PushUtils.buildJson("statusType", "rejected").toString());
+                        }
                     }
                     equipmentApplyService.updateById(equipmentApply);
 
-
                 }
             }
         }
@@ -409,6 +433,29 @@ public class TEquipmentApplyController {
         }
 
     }
+
+    /**
+     * 添加爆米花产品
+     * @param id
+     */
+    private void saveProductPOP320(Long id) {
+        String[] str = {"活力爆米花(正常糖)-B01", "活力爆米花(无糖)-B02", "活力爆米花(巧克力)-B03", "活力爆米花(焦糖)-B04", "活力爆米花(水蜜桃)-B05", "活力爆米花(蓝莓)-B06"};
+
+        for (int i = 0; i < str.length; i++) {
+            TProduct product = new TProduct();
+            product.setCreateDate(new Date());
+            product.setModifyDate(new Date());
+            product.setEquipmentId(id);
+            String[] split = str[i].split("-");
+            product.setProductName(split[0]);
+            product.setNo(split[1]);
+            product.setRmbPrice(BigDecimal.ZERO);
+            product.setCodePrice(BigDecimal.ZERO);
+            productService.save(product);
+        }
+
+    }
+
     /**
      * 获取指定日期所在月份开始的时间戳
      * @param date 指定日期

+ 9 - 16
src/main/java/com/szwl/controller/TEquipmentDeletedController.java

@@ -1,17 +1,16 @@
 package com.szwl.controller;
 
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.szwl.manager.TokenManager;
 import com.szwl.model.bo.R;
 import com.szwl.model.bo.ResponseModel;
 import com.szwl.model.bo.UserDetailBO;
-import com.szwl.model.entity.IDRequest;
-import com.szwl.model.entity.TAdmin;
-import com.szwl.model.entity.TEquipment;
-import com.szwl.model.entity.TEquipmentDeleted;
+import com.szwl.model.entity.*;
 import com.szwl.service.TAdminService;
 import com.szwl.service.TEquipmentDeletedService;
 import com.szwl.service.TEquipmentService;
+import com.szwl.service.TProductService;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import org.springframework.beans.BeanUtils;
@@ -48,6 +47,9 @@ public class TEquipmentDeletedController {
 
     @Autowired
     TAdminService tAdminService;
+
+    @Autowired
+    TProductService tProductService;
 //
 //    @Resource
 //    TokenManager tokenManager;
@@ -61,30 +63,21 @@ public class TEquipmentDeletedController {
         // 获取当前登录用户id
         String adminId = idRequest.getAdminId();
         // 根据用户id查用户类型
-//        TAdmin adminById = tAdminService.getById(adminId);
         Integer adminType = tAdminService.getById(adminId).getType();
         // 判断当前用户类型
-//        TAdmin admin = tAdminService.getById(loginUserDetails.getId());
-        // 获取缓存中的当前登录用户 loginUserDetails
-//        UserDetailBO loginUserDetails = tokenManager.getLoginUserDetails();
-        // 获取用户类型
-//        Integer type = loginUserDetails.getType();
         // 如果不为空,并且类型是 0 1 就执行以下操作
         if (adminType != null && (adminType == 0 || adminType == 1)) {
             // 查询当前设备信息
-
-//            LambdaQueryWrapper<TEquipment> lambdaQueryWrapper = Wrappers.lambdaQuery();
-//            lambdaQueryWrapper.eq(TEquipment::getId, equipmentId);
-//            TEquipment tEquipment = tEquipmentService.getOne(lambdaQueryWrapper);
-//            TEquipment tEquipment = tEquipmentService.getById(equipmentId);
             TEquipment tEquipment = tEquipmentService.getOne(Wrappers.<TEquipment>lambdaQuery().eq(TEquipment::getId, equipmentId));
             System.out.println(tEquipment);
             if (Objects.nonNull(tEquipment)) {
                 // 先把准备删除的设备信息添加到t_equipment_deleted表中
                 TEquipmentDeleted tEquipmentDeleted = new TEquipmentDeleted();
                 BeanUtils.copyProperties(tEquipment, tEquipmentDeleted);
-//            tEquipmentDeletedService.addOne(tEquipment);
                 tEquipmentDeletedService.save(tEquipmentDeleted);
+                LambdaQueryWrapper<TProduct> wrapper = new LambdaQueryWrapper<>();
+                wrapper.eq(TProduct::getEquipmentId,equipmentId);
+                tProductService.remove(wrapper);
                 // 删除设备
                 tEquipmentService.removeById(equipmentId);
                 return R.ok(null, "设备已删除!");