Commit 0d3cc3a0 authored by 马33's avatar 马33

上报错误处理

parent d8adfd43
......@@ -11,6 +11,8 @@ import iot.sixiang.license.service.TerminalDeviceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@RequestMapping("/iot_license/terminal_device")
@Api(value = "终端设备模块", tags = {"终端设备模块"})
......@@ -26,7 +28,7 @@ public class TerminalDeviceController {
@PostMapping("/report_error_msg")
@ApiOperation(value = "终端设备上报错误信息", notes = "终端设备上报错误信息")
public BaseResult reportErrorMsg(@RequestBody ReportErrorMsgDTO reportErrorMsgDTO) {
public BaseResult reportErrorMsg(@RequestBody List<ReportErrorMsgDTO> reportErrorMsgDTO) {
return terminalDeviceService.reportErrorMsg(reportErrorMsgDTO);
}
......
......@@ -19,4 +19,6 @@ public interface PmsUseService {
PageInfoModel<PmsUseLog> getPmsUseLogList(int pageNo, int pageSize, String sn, Integer status);
boolean reportErrorMsg(ReportErrorMsgDTO reportErrorMsgDTO);
boolean deletePmsUseLogById(Integer id);
}
......@@ -6,10 +6,12 @@ import iot.sixiang.license.model.dto.GetTerminalDeviceTokenDTO;
import iot.sixiang.license.model.dto.ReportErrorMsgDTO;
import iot.sixiang.license.model.dto.TerminalDevieBindDTO;
import java.util.List;
public interface TerminalDeviceService {
ResResult getToken(GetTerminalDeviceTokenDTO getTerminalDeviceTokenDTO);
BaseResult reportErrorMsg(ReportErrorMsgDTO reportErrorMsgDTO);
BaseResult reportErrorMsg(List<ReportErrorMsgDTO> reportErrorMsgDTO);
BaseResult terminalDevieBind(TerminalDevieBindDTO terminalDevieBindDTO);
}
......@@ -76,11 +76,18 @@ public class PmsUseServiceImpl implements PmsUseService {
pmsUseLog.setMessage(errorMsg);
pmsUseLog.setUpdateTime(new Date());
int res = pmsUseLogMapper.updateById(pmsUseLog);
if (res >= 0) {
return true;
} else {
return false;
return res > 0;
}
@Override
public boolean deletePmsUseLogById(Integer id) {
PmsUseLog pmsUseLog = new PmsUseLog();
pmsUseLog.setId(id);
pmsUseLog.setStatus(0);
pmsUseLog.setUpdateTime(new Date());
pmsUseLog.setDeleted(0);
int res = pmsUseLogMapper.updateById(pmsUseLog);
return res > 0;
}
private PmsUseLog getPmsUseLog(String sn) {
......
......@@ -17,6 +17,9 @@ import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Comparator;
import java.util.List;
@Slf4j
@Service
public class TerminalDeviceServiceImpl implements TerminalDeviceService {
......@@ -54,12 +57,27 @@ public class TerminalDeviceServiceImpl implements TerminalDeviceService {
}
@Override
public BaseResult reportErrorMsg(ReportErrorMsgDTO reportErrorMsgDTO) {
public BaseResult reportErrorMsg(List<ReportErrorMsgDTO> reportErrorMsgDTOs) {
if (reportErrorMsgDTOs == null || reportErrorMsgDTOs.size() == 0) {
return BaseResult.validate_failed();
}
reportErrorMsgDTOs.sort(Comparator.comparingInt(ReportErrorMsgDTO::getId));
for (int i = 0; i < reportErrorMsgDTOs.size() - 1; i++) {
ReportErrorMsgDTO reportErrorMsgDTO = reportErrorMsgDTOs.get(i);
Integer id = reportErrorMsgDTO.getId();
log.info("============ 上报错误信息, id : {},errorCode: {}, msg: {} =================",id, reportErrorMsgDTO.getErrorCode(), reportErrorMsgDTO.getErrorMsg());
if (id == null || id == 0) {
return BaseResult.validate_failed();
}
pmsUseService.deletePmsUseLogById(id);
}
ReportErrorMsgDTO reportErrorMsgDTO = reportErrorMsgDTOs.get(reportErrorMsgDTOs.size() - 1);
if (reportErrorMsgDTO.getId() == null || reportErrorMsgDTO.getId() == 0 || reportErrorMsgDTO.getErrorCode() == null) {
return BaseResult.validate_failed();
} else {
if ("0".equals(reportErrorMsgDTO.getErrorCode())) {
pmsUseService.success(reportErrorMsgDTO.getId());
return BaseResult.success();
} else {
boolean res = pmsUseService.reportErrorMsg(reportErrorMsgDTO);
if (res) {
return BaseResult.success();
......@@ -67,6 +85,8 @@ public class TerminalDeviceServiceImpl implements TerminalDeviceService {
return BaseResult.failed();
}
}
}
}
@Override
public BaseResult terminalDevieBind(TerminalDevieBindDTO terminalDevieBindDTO) {
......
......@@ -10,6 +10,7 @@
<if test="null != status">
and status = #{status}
</if>
and deleted = 0
order by create_time desc
</select>
</mapper>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment