java.sql.BatchUpdateException: Duplicate entry ‘00000000000001‘ for key ‘unique_meter_code‘

错误:

[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": "设备编码已经存在"
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值