TParametersController.java 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. package com.szwl.controller;
  2. import cn.com.crbank.ommo.bean.ResultMessage;
  3. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  4. import com.baomidou.mybatisplus.core.toolkit.Wrappers;
  5. import com.sun.corba.se.impl.protocol.giopmsgheaders.RequestMessage;
  6. import com.szwl.constant.ResponseCodesEnum;
  7. import com.szwl.model.bean.CommonParamVo;
  8. import com.szwl.model.bo.R;
  9. import com.szwl.model.bo.ResponseModel;
  10. import com.szwl.model.entity.TEquipment;
  11. import com.szwl.model.entity.TEquipmentDesc;
  12. import com.szwl.model.entity.TParameters;
  13. import com.szwl.model.entity.TProduct;
  14. import com.szwl.model.utils.PushUtils;
  15. import com.szwl.service.TEquipmentDescService;
  16. import com.szwl.service.TEquipmentService;
  17. import com.szwl.service.TParametersService;
  18. import io.swagger.annotations.Api;
  19. import io.swagger.annotations.ApiOperation;
  20. import org.apache.commons.lang.StringUtils;
  21. import org.springframework.beans.factory.annotation.Autowired;
  22. import org.springframework.http.HttpStatus;
  23. import org.springframework.http.ResponseEntity;
  24. import org.springframework.web.bind.annotation.PostMapping;
  25. import org.springframework.web.bind.annotation.RequestBody;
  26. import org.springframework.web.bind.annotation.RequestMapping;
  27. import org.springframework.web.bind.annotation.RestController;
  28. import javax.annotation.Resource;
  29. import java.util.List;
  30. import java.util.Objects;
  31. /**
  32. * <p>
  33. * 机器参数表 前端控制器
  34. * </p>
  35. *
  36. * @author wuhs
  37. * @since 2022-04-23
  38. */
  39. @Api(value = "/tParameters", tags = {"参数"})
  40. @RestController
  41. @RequestMapping("/tParameters")
  42. public class TParametersController {
  43. @Autowired
  44. private TParametersService tParametersService;
  45. @Autowired
  46. private TEquipmentService tEquipmentService;
  47. @Resource
  48. private TEquipmentDescService equipmentDescService;
  49. /**
  50. * 获取设备参数
  51. *
  52. * @param
  53. * @return
  54. */
  55. @PostMapping("/getParameters")
  56. public ResponseEntity<?> getParameters(@RequestBody TParameters parameters) {
  57. Long equipmentId = parameters.getId();
  58. String status = parameters.getStatus();
  59. String clientId = parameters.getClientId();
  60. LambdaQueryWrapper<TParameters> query = Wrappers.lambdaQuery();
  61. query.eq(TParameters::getEquipmentId,equipmentId);
  62. query.eq(TParameters::getClientId,clientId);
  63. query.eq(TParameters::getStatus,status);
  64. List<TParameters> parametersList = tParametersService.list(query);
  65. if(parametersList.size()==0){
  66. return ResponseEntity
  67. .status(HttpStatus.OK)
  68. .body(new ResultMessage()
  69. .setCode(false)
  70. .setData(parametersList)
  71. .setMessage("暂无参数数据"));
  72. }
  73. return ResponseEntity
  74. .status(HttpStatus.OK)
  75. .body(new ResultMessage()
  76. .setCode(true)
  77. .setData(parametersList)
  78. .setMessage("SUCCESS"));
  79. }
  80. /**
  81. * 推送设备共同以及/设备参数
  82. *
  83. * @param
  84. * @return
  85. */
  86. @PostMapping("/updateParameters")
  87. public ResponseEntity<?> updateCommonParam(@RequestBody CommonParamVo commonParamVo) {
  88. String equipmentId = commonParamVo.getId();
  89. TEquipment equipment = tEquipmentService.getById(Long.valueOf(equipmentId));
  90. tEquipmentService.sentMessage(equipment.getClientId(), PushUtils.buildJson("Param", commonParamVo.getName() + ":" + commonParamVo.getVal()).toString());
  91. return ResponseEntity
  92. .status(HttpStatus.OK)
  93. .body(new ResultMessage()
  94. .setCode(true)
  95. .setData("SUCCESS")
  96. .setMessage("SUCCESS"));
  97. }
  98. @ApiOperation(value = "启用物料监控")
  99. @PostMapping("/enableMaterial")
  100. public ResponseModel<?> enableMaterial(@RequestBody TParameters parameters) {
  101. Long equipmentId = parameters.getEquipmentId();
  102. if (equipmentId == null) {
  103. return R.fail(ResponseCodesEnum.A0001,"设备id不能为空");
  104. }
  105. // TParameters tParameters = tParametersService.getById(equipmentId);
  106. // if (Objects.isNull(tParameters)) {
  107. // TParameters tParameters1 = new TParameters();
  108. // }
  109. TEquipmentDesc equipmentDesc = equipmentDescService.getById(equipmentId);
  110. if (Objects.isNull(equipmentDesc)) {
  111. TEquipmentDesc tEquipmentDesc = new TEquipmentDesc();
  112. tEquipmentDesc.setEquipmentId(equipmentId);
  113. tEquipmentDesc.setIsMaterialUse("1");
  114. equipmentDescService.saveOrUpdate(tEquipmentDesc);
  115. } else {
  116. String isMaterialUse = equipmentDesc.getIsMaterialUse();
  117. if (StringUtils.isNotEmpty(isMaterialUse) && "1".equals(isMaterialUse)) {
  118. return R.ok(ResponseCodesEnum.ALL_OK,"已开启ENABLED");
  119. }
  120. equipmentDesc.setIsMaterialUse("1");
  121. equipmentDescService.saveOrUpdate(equipmentDesc);
  122. }
  123. TEquipment equipment = tEquipmentService.getById(equipmentId);
  124. tEquipmentService.sentMessage(equipment.getClientId(), PushUtils.buildJson("Param", "M502" + ":" + "1").toString());
  125. return R.ok(ResponseCodesEnum.ALL_OK,"开启物料监控功能成功SUCCESS");
  126. }
  127. }