错误:
[iwater-workbench:192.168.0.62:4003] 2022-09-12 17:49:52.785 ERROR 83708 [] [http-nio-4003-exec-8] o.a.c.c.C.[.[.[/].[dispatcherServlet] Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.dao.DuplicateKeyException: com.iwater.workbench.device.mapper.WatermeterMapper.insert (batch index #1) failed. Cause: java.sql.BatchUpdateException: Duplicate entry '00000000000001' for key 'unique_meter_code'
; Duplicate entry '00000000000001' for key 'unique_meter_code'; nested exception is java.sql.BatchUpdateException: Duplicate entry '00000000000001' for key 'unique_meter_code'] with root cause
java.sql.SQLIntegrityConstraintViolationException: Duplicate entry '00000000000001' for key 'unique_meter_code'
3: {collectorId: "1552571726646190081", areaId: "1346359691185631297",…}
areaId: "1346359691185631297"
collectorCode: "869915042257492"
collectorId: "1552571726646190081"
collectorTypeId: "1430098888866766873"
deviceCode: "00000000000001"
installPosition: "测试"
manufacturerId: "1456573455584894992"
meterModelId: "1386518446262947846"
moduleCode: "00000000000001"
transferCode: "03"
type: 0
valveCode: ""
原因:
meter_code在表中是唯一性索引
解决:
修改代码在新增数据之前进行唯一性判定,并返回提示给前端。
POST
URL:http://192.168.0.XX/api-serve/api-workbench/deviceValve/synchronizationDevice
入参:
[
{
"areaId": "1346359691185631297",
"collectorCode": "869915042257492",
"collectorId": "1552571726646190081",
"collectorTypeId": "1430098888866766873",
"deviceCode": "90000000000004",
"installPosition": "测试",
"manufacturerId": "1456573455584894992",
"moduleCode": "90000000000004",
"transferCode": "02",
"type": 1
},
{
"areaId": "1346359691185631297",
"collectorCode": "869915042257492",
"collectorId": "1552571726646190081",
"collectorTypeId": "1430098888866766873",
"deviceCode": "00000000000001",
"installPosition": "测试",
"manufacturerId": "1456573455584894992",
"meterModelId": "1386518446262947846",
"moduleCode": "00000000000001",
"transferCode": "03",
"type": 0,
"valveCode": ""
}
]
出参:
{
"datas": [
"90000000000004",
"00000000000001"
],
"resp_code": 0,
"resp_msg": "设备编码已经存在"
}