|
@@ -1,10 +1,35 @@
|
|
|
package com.szwl.controller;
|
|
|
|
|
|
|
|
|
+import cn.com.crbank.ommo.bean.ResultMessage;
|
|
|
+import cn.com.crbank.ommo.esUtil.BeanUtils;
|
|
|
+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.model.bean.TEquipmentDTO;
|
|
|
+import com.szwl.model.bo.R;
|
|
|
+import com.szwl.model.bo.ResponseModel;
|
|
|
+import com.szwl.model.entity.*;
|
|
|
+import com.szwl.model.utils.PushUtils;
|
|
|
+import com.szwl.service.*;
|
|
|
+import com.szwl.service.es.EsTEquipmentService;
|
|
|
+import io.swagger.annotations.Api;
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
+import org.apache.commons.lang.StringUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.http.HttpStatus;
|
|
|
+import org.springframework.http.ResponseEntity;
|
|
|
+import org.springframework.web.bind.annotation.GetMapping;
|
|
|
+import org.springframework.web.bind.annotation.PostMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
/**
|
|
|
* <p>
|
|
|
* 设备连接申请表 前端控制器
|
|
@@ -14,8 +39,341 @@ import org.springframework.web.bind.annotation.RestController;
|
|
|
* @since 2022-04-21
|
|
|
*/
|
|
|
@RestController
|
|
|
+@Api(value = "/tEquipmentApply", tags = {"设备连接申请表"})
|
|
|
@RequestMapping("/tEquipmentApply")
|
|
|
public class TEquipmentApplyController {
|
|
|
+ @Autowired
|
|
|
+ TAdminService adminService;
|
|
|
+ @Autowired
|
|
|
+ TEquipmentApplyService equipmentApplyService;
|
|
|
+ @Autowired
|
|
|
+ TEquipmentService equipmentService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ TProductService productService;
|
|
|
+ @Autowired
|
|
|
+ TEquipmentDescService equipmentDescService;
|
|
|
+ @Autowired
|
|
|
+ EsTEquipmentService esTEquipmentService;
|
|
|
+
|
|
|
+ @ApiOperation(value = "查找机器审核列表")
|
|
|
+ @GetMapping("/pageTEquipmentApply")
|
|
|
+ public ResponseModel<IPage<?>> pageTEquipmentApply(String clientId, String userName,String managerId,String type, long current, long size ) {
|
|
|
+
|
|
|
+ LambdaQueryWrapper<TEquipmentApply> query = Wrappers.lambdaQuery();
|
|
|
+ if(StringUtils.isNotEmpty(clientId)){
|
|
|
+ query.like(TEquipmentApply::getClientId,clientId);
|
|
|
+ }
|
|
|
+ if(StringUtils.isNotEmpty(userName)){
|
|
|
+ LambdaQueryWrapper<TAdmin> adminQuery = Wrappers.lambdaQuery();
|
|
|
+ adminQuery.eq(TAdmin::getUsername,userName);
|
|
|
+ List<TAdmin> list = adminService.list(adminQuery);
|
|
|
+ if(list.size()>0){
|
|
|
+ query.eq(TEquipmentApply::getAdminId,list.get(0).getId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(StringUtils.isNotEmpty(type)){
|
|
|
+ query.eq(TEquipmentApply::getType,type);
|
|
|
+ }
|
|
|
+ if(StringUtils.isNotEmpty(managerId)){
|
|
|
+ query.like(TEquipmentApply::getManagerId,managerId);
|
|
|
+ }
|
|
|
+ Page<TEquipmentApply> page = new Page<>(current, size, true);
|
|
|
+ IPage<TEquipmentApply> iPage = equipmentApplyService.page(page, query);
|
|
|
+ return R.ok(iPage);
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 更新申请状态
|
|
|
+ */
|
|
|
+ @ApiOperation(value = "更新申请状态")
|
|
|
+ @GetMapping("/changeStatus")
|
|
|
+ public ResponseModel<?> changeStatus(Long id, String status) {
|
|
|
+
|
|
|
+ if (null != id) {
|
|
|
+ TEquipmentApply equipmentApply = equipmentApplyService.getById(id);
|
|
|
+ if (equipmentApply != null) {
|
|
|
+ if (!StringUtils.isEmpty(status)) {
|
|
|
+ if (status.equals("agreed")) {
|
|
|
+ String clientId = equipmentApply.getClientId();
|
|
|
+
|
|
|
+ //判断是否设备初始化
|
|
|
+
|
|
|
+ Long adminId = equipmentApply.getAdminId();
|
|
|
+ String adminLevel = equipmentApply.getAdminLevel();
|
|
|
+ String adminUserName = equipmentApply.getAdminUserName();
|
|
|
+ Integer type = equipmentApply.getType();
|
|
|
+ String gtClientId = equipmentApply.getGtClientId();
|
|
|
+ String equimentType = equipmentApply.getEquimentType();
|
|
|
+
|
|
|
+ String old = "";
|
|
|
+// ArrayList<Filter> filters = new ArrayList<>();
|
|
|
+// filters.add(Filter.eq("clientId", clientId + "xxx"));
|
|
|
+// List<Equipment> list = equipmentService.findList(null, filters, null);
|
|
|
+ LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
|
|
|
+ query.like(TEquipment::getClientId,clientId+"xxx");
|
|
|
+ List<TEquipment> list = equipmentService.list(query);
|
|
|
+ equipmentApply.setStatusType(3);
|
|
|
+ if (list.size() > 0) {
|
|
|
+ //表示设备第二次申请了:主要为了区分脱离以及初始化
|
|
|
+ old = "1";
|
|
|
+ //重新修改设备名称
|
|
|
+ TEquipment equipment = list.get(0);
|
|
|
+ equipment.setClientId(clientId);
|
|
|
+ equipment.setGtClientId(gtClientId);
|
|
|
+ equipment.setAdminId(adminId);
|
|
|
+ equipment.setAdminLevel(adminLevel);
|
|
|
+ equipment.setAdminUserName(adminUserName);
|
|
|
+ equipment.setType(type);
|
|
|
+ if(equipmentApply.getEquimentType().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()));
|
|
|
+// List<Product> productList = productService.findList(null, filter, null);
|
|
|
+ LambdaQueryWrapper<TProduct> queryProduct = Wrappers.lambdaQuery();
|
|
|
+ queryProduct.eq(TProduct::getEquipmentId,equipment.getId());
|
|
|
+ List<TProduct> productList = productService.list(queryProduct);
|
|
|
+ if(productList.size()==18){
|
|
|
+ //从18种变成30种花型
|
|
|
+ saveProductMG12(equipment.getId());
|
|
|
+ }
|
|
|
+ //从18种变成30种花型
|
|
|
+// saveProductMG12(equipment.getId());
|
|
|
+ }
|
|
|
+ equipment.setEquimentType("MG320");
|
|
|
+ }
|
|
|
+ if(equipmentApply.getEquimentType().equals("MG330")){
|
|
|
+ equipment.setEquimentType("MG330");
|
|
|
+ }
|
|
|
+
|
|
|
+ equipmentService.updateById(equipment);
|
|
|
+ String data = com.alibaba.fastjson.JSON.toJSONString(equipment);
|
|
|
+ try {
|
|
|
+ esTEquipmentService.updateDataById(equipment);
|
|
|
+ }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());
|
|
|
+ equipmentApplyService.updateById(equipmentApply);
|
|
|
+ equipmentService.sentMessage(equipmentApply.getClientId(),PushUtils.buildJson("endDate",String.valueOf(equipment.getEndDate().getTime()) ).toString());
|
|
|
+ PushUtils.push(equipmentApply.getGtClientId(), "", "", PushUtils.buildJson("endDate",String.valueOf(equipment.getEndDate().getTime()) ).toString());
|
|
|
+ return R.ok();
|
|
|
+ }
|
|
|
+
|
|
|
+ TEquipment equipment = new TEquipment();
|
|
|
+ equipment.setClientId(clientId);
|
|
|
+ equipment.setManagerId(equipmentApply.getManagerId());
|
|
|
+ equipment.setAdminId(adminId);
|
|
|
+ equipment.setAdminLevel(adminLevel);
|
|
|
+ equipment.setGtClientId(gtClientId);
|
|
|
+ equipment.setAdminUserName(adminUserName);
|
|
|
+ equipment.setIsUsing(true);
|
|
|
+ equipment.setIsNetWork(true);
|
|
|
+ equipment.setGuestPwd("123456");
|
|
|
+ equipment.setAdminPwd("123456");
|
|
|
+ equipment.setChannel("1");
|
|
|
+ equipment.setProductTotal(0);
|
|
|
+ equipment.setType(type);
|
|
|
+ //设置默认规则
|
|
|
+ equipment.setTimeRuleId(Long.valueOf(1));
|
|
|
+ if(equimentType.equals("MG320-1")){
|
|
|
+ equipment.setEquimentType("MG320");
|
|
|
+ }else {
|
|
|
+ equipment.setEquimentType(equimentType);
|
|
|
+ }
|
|
|
+ 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();
|
|
|
+ if(time<monthBegin){
|
|
|
+ equipment.setEndDate(new Date(monthBegin));
|
|
|
+ }else{
|
|
|
+ Date date = nextMonthDate();
|
|
|
+ equipment.setEndDate(date);
|
|
|
+ }
|
|
|
+ equipmentService.sentMessage(equipmentApply.getClientId(), PushUtils.buildJson("endDate",String.valueOf(equipment.getEndDate().getTime()) ).toString());
|
|
|
+ PushUtils.push(equipmentApply.getGtClientId(), "", "", PushUtils.buildJson("endDate",String.valueOf(equipment.getEndDate().getTime()) ).toString());
|
|
|
+ }
|
|
|
+ equipmentService.save(equipment);
|
|
|
+ equipmentService.sentMessage(equipmentApply.getClientId(), PushUtils.buildJson("statusType", "agreed" + old).toString());
|
|
|
+ PushUtils.push(equipmentApply.getGtClientId(), "【棉花糖】设备初始化申请", "同意", PushUtils.buildJson("statusType", "agreed" + old).toString());
|
|
|
+ //获取设备的id
|
|
|
+ Long equipmentId = equipment.getId();
|
|
|
+ if(equipmentApply.getEquimentType()!=null&&equipmentApply.getEquimentType().equals("MG280")){
|
|
|
+ saveProductMG280(equipmentId);
|
|
|
+ } else if(equipmentApply.getEquimentType()!=null&&equipmentApply.getEquimentType().equals("MG320-1")){
|
|
|
+ saveProductMG1(equipmentId);
|
|
|
+ } else{
|
|
|
+ saveProduct(equipmentId);
|
|
|
+ }
|
|
|
+ LambdaQueryWrapper<TEquipment> query1 = Wrappers.lambdaQuery();
|
|
|
+ query1.eq(TEquipment::getClientId,clientId);
|
|
|
+ List<TEquipment> list1 = equipmentService.list(query1);
|
|
|
+ try {
|
|
|
+ if(list1.size()>0){
|
|
|
+ TEquipment tEquipment = list1.get(0);
|
|
|
+ esTEquipmentService.insertData(tEquipment);
|
|
|
+ }
|
|
|
+ }catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ TEquipmentDesc equipmentDesc = new TEquipmentDesc();
|
|
|
+ equipmentDesc.setEquipmentId(list1.get(0).getId());
|
|
|
+ equipmentDescService.save(equipmentDesc);
|
|
|
+
|
|
|
+ } else if (status.equals("rejected")) {
|
|
|
+ equipmentApply.setStatusType(2);
|
|
|
+ equipmentService.sentMessage(equipmentApply.getClientId(),PushUtils.buildJson("statusType", "rejected").toString());
|
|
|
+ PushUtils.push(equipmentApply.getGtClientId(), "【棉花糖】设备初始化申请", "拒绝", PushUtils.buildJson("statusType", "rejected").toString());
|
|
|
+ }
|
|
|
+ equipmentApplyService.updateById(equipmentApply);
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return R.ok();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 添加产品
|
|
|
+ *
|
|
|
+ * @param id
|
|
|
+ */
|
|
|
+
|
|
|
+ private void saveProduct(Long id) {
|
|
|
+ String[] str = {"玫瑰精灵-A01", "童心未泯-A02", "五彩缤纷-A03", "天雪恋舞-A04", "水中芙蓉-A05", "烈焰红唇-A06", "美梦成真-A07", "一见钟情-A08", "幽兰爱恋-A09", "心之守护-A10",
|
|
|
+ "夏日爱恋-A11", "冰美人-A12", "国色天香-A13", "赤子之心-A14", "海洋之心-A15", "水晶之恋-A16", "彩色精灵-A17", "小棉袄-A18"};
|
|
|
+
|
|
|
+ for (int i = 0; i < str.length; i++) {
|
|
|
+ TProduct product = new TProduct();
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ private void saveProductMG280(Long id) {
|
|
|
+ String[] str = { "水中芙蓉-A05", "水中芙蓉mini-A31", "烈焰红唇-A06", "烈焰红唇mini-A32", "夏日爱恋-A11", "夏日爱恋mini-A33", "冰美人-A12", "冰美人mini-A34", "彩色精灵-A17", "彩色精灵mini-A35"};
|
|
|
+
|
|
|
+ for (int i = 0; i < str.length; i++) {
|
|
|
+ TProduct product = new TProduct();
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ private void saveProductMG1(Long id) {
|
|
|
+ String[] str = {"玫瑰精灵-A01", "童心未泯-A02", "五彩缤纷-A03", "天雪恋舞-A04", "水中芙蓉-A05", "烈焰红唇-A06", "美梦成真-A07", "一见钟情-A08", "幽兰爱恋-A09",
|
|
|
+ "心之守护-A10", "夏日爱恋-A11", "冰美人-A12", "国色天香-A13", "赤子之心-A14", "海洋之心-A15", "水晶之恋-A16", "彩色精灵-A17", "小棉袄-A18",
|
|
|
+ "精灵蝶梦-A19","夏日倾城-A20","百花齐放-A21","蜂缠蝶恋-A22","豆蔻年华-A23","星空幻想-A24","坠入星空-A25","雪花飞舞-A26","春暖花开-A27","花飞蝶舞-A28",
|
|
|
+ "花样年华-A29","心花怒放-A30"};
|
|
|
+
|
|
|
+ for (int i = 0; i < str.length; i++) {
|
|
|
+ TProduct product = new TProduct();
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ private void saveProductMG12(Long id) {
|
|
|
+ String[] str = { "精灵蝶梦-A19","夏日倾城-A20","百花齐放-A21","蜂缠蝶恋-A22","豆蔻年华-A23","星空幻想-A24"
|
|
|
+ ,"坠入星空-A25","雪花飞舞-A26","春暖花开-A27","花飞蝶舞-A28","花样年华-A29","心花怒放-A30"};
|
|
|
+ for (int i = 0; i < str.length; i++) {
|
|
|
+ TProduct product = new TProduct();
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ private void saveProductMG22(Long id) {
|
|
|
+ String[] str = {"玫瑰精灵-A01", "童心未泯-A02", "五彩缤纷-A03", "天雪恋舞-A04", "水中芙蓉-A05", "烈焰红唇-A06", "美梦成真-A07", "一见钟情-A08", "幽兰爱恋-A09", "心之守护-A10",
|
|
|
+ "夏日爱恋-A11", "冰美人-A12", "国色天香-A13", "赤子之心-A14", "海洋之心-A15", "水晶之恋-A16", "彩色精灵-A17", "小棉袄-A18", "精灵蝶梦-A19","蜂缠蝶恋-A22","坠入星空-A25","花飞蝶舞-A28"};
|
|
|
+
|
|
|
+ for (int i = 0; i < str.length; i++) {
|
|
|
+ TProduct product = new TProduct();
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ private void saveProductMG26(Long id) {
|
|
|
+ String[] str = {"玫瑰精灵-A01", "童心未泯-A02", "五彩缤纷-A03", "天雪恋舞-A04", "水中芙蓉-A05", "烈焰红唇-A06", "美梦成真-A07", "一见钟情-A08", "幽兰爱恋-A09", "心之守护-A10",
|
|
|
+ "夏日爱恋-A11", "冰美人-A12", "国色天香-A13", "赤子之心-A14", "海洋之心-A15", "水晶之恋-A16", "彩色精灵-A17", "小棉袄-A18", "精灵蝶梦-A19","蜂缠蝶恋-A22","坠入星空-A25","花飞蝶舞-A28",
|
|
|
+ "夏日倾城-A20", "雪花飞舞-A26", "豆蔻年华-A23", "花样年华-A29"};
|
|
|
+ for (int i = 0; i < str.length; i++) {
|
|
|
+ TProduct product = new TProduct();
|
|
|
+ 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 指定日期
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public static Long getMonthBegin(Date date) {
|
|
|
+ Calendar c = Calendar.getInstance();
|
|
|
+ c.setTime(date);
|
|
|
+
|
|
|
+ //设置为10号,当前日期既为本月10号
|
|
|
+ c.set(Calendar.DAY_OF_MONTH, 10);
|
|
|
+ //将小时至0
|
|
|
+ c.set(Calendar.HOUR_OF_DAY, 0);
|
|
|
+ //将分钟至0
|
|
|
+ c.set(Calendar.MINUTE, 0);
|
|
|
+ //将秒至0
|
|
|
+ c.set(Calendar.SECOND,0);
|
|
|
+ //将毫秒至0
|
|
|
+ c.set(Calendar.MILLISECOND, 0);
|
|
|
+ // 获取本月第一天的时间戳
|
|
|
+ return c.getTimeInMillis();
|
|
|
+ }
|
|
|
+ public static Date nextMonthDate() {
|
|
|
+ Calendar calendar = Calendar.getInstance();
|
|
|
+ calendar.set(Calendar.DAY_OF_MONTH,10);
|
|
|
+ //将小时至0
|
|
|
+ calendar.set(Calendar.HOUR_OF_DAY, 0);
|
|
|
+ //将分钟至0
|
|
|
+ calendar.set(Calendar.MINUTE, 0);
|
|
|
+ //将秒至0
|
|
|
+ calendar.set(Calendar.SECOND,0);
|
|
|
+ //将毫秒至0
|
|
|
+ calendar.set(Calendar.MILLISECOND, 0);
|
|
|
+ calendar.add(Calendar.MONTH,1);
|
|
|
+ return calendar.getTime();
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
|