fix:设备台账增加“设备编码”的唯一校验,设备台账导入报错问题解决
This commit is contained in:
parent
f9de0aaba3
commit
cb1fbc8c91
@ -77,9 +77,7 @@ public class DvMachineryController extends BaseController
|
||||
@PostMapping
|
||||
public AjaxResult add(@RequestBody DvMachinery dvMachinery)
|
||||
{
|
||||
dvMachineryService.insertDvMachinery(dvMachinery);
|
||||
wmBarCodeUtil.generateBarCode(UserConstants.BARCODE_TYPE_MACHINERY,dvMachinery.getMachineryId(),dvMachinery.getMachineryCode(),dvMachinery.getMachineryName());
|
||||
return AjaxResult.success(dvMachinery.getMachineryId());
|
||||
return dvMachineryService.insertDvMachinery(dvMachinery);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -90,7 +88,7 @@ public class DvMachineryController extends BaseController
|
||||
@PutMapping
|
||||
public AjaxResult edit(@RequestBody DvMachinery dvMachinery)
|
||||
{
|
||||
return toAjax(dvMachineryService.updateDvMachinery(dvMachinery));
|
||||
return dvMachineryService.updateDvMachinery(dvMachinery);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -23,10 +23,10 @@ public interface DvMachineryMapper
|
||||
/**
|
||||
* 依据设备编码查询设备
|
||||
*
|
||||
* @param machineryCode 设备编码
|
||||
* @return 设备
|
||||
* @param machineryCode 设备编码
|
||||
* @return 设备
|
||||
*/
|
||||
public DvMachinery selectByMachineryCode( String machineryCode);
|
||||
public List<DvMachinery> selectByMachineryCode(String machineryCode);
|
||||
|
||||
/**
|
||||
* 查询设备列表
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.ktg.mes.dv.service;
|
||||
|
||||
import com.ktg.common.core.domain.AjaxResult;
|
||||
import com.ktg.mes.dv.domain.DvMachinery;
|
||||
|
||||
import java.util.List;
|
||||
@ -30,19 +31,19 @@ public interface IDvMachineryService
|
||||
|
||||
/**
|
||||
* 新增设备
|
||||
*
|
||||
*
|
||||
* @param dvMachinery 设备
|
||||
* @return 结果
|
||||
*/
|
||||
public int insertDvMachinery(DvMachinery dvMachinery);
|
||||
public AjaxResult insertDvMachinery(DvMachinery dvMachinery);
|
||||
|
||||
/**
|
||||
* 修改设备
|
||||
*
|
||||
*
|
||||
* @param dvMachinery 设备
|
||||
* @return 结果
|
||||
*/
|
||||
public int updateDvMachinery(DvMachinery dvMachinery);
|
||||
public AjaxResult updateDvMachinery(DvMachinery dvMachinery);
|
||||
|
||||
/**
|
||||
* 批量删除设备
|
||||
|
@ -1,9 +1,12 @@
|
||||
package com.ktg.mes.dv.service.impl;
|
||||
|
||||
import com.ktg.common.constant.UserConstants;
|
||||
import com.ktg.common.core.domain.AjaxResult;
|
||||
import com.ktg.common.utils.DateUtils;
|
||||
import com.ktg.mes.dv.domain.DvMachinery;
|
||||
import com.ktg.mes.dv.mapper.DvMachineryMapper;
|
||||
import com.ktg.mes.dv.service.IDvMachineryService;
|
||||
import com.ktg.mes.wm.utils.WmBarCodeUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@ -21,6 +24,10 @@ public class DvMachineryServiceImpl implements IDvMachineryService
|
||||
@Autowired
|
||||
private DvMachineryMapper dvMachineryMapper;
|
||||
|
||||
|
||||
@Autowired
|
||||
private WmBarCodeUtil wmBarCodeUtil;
|
||||
|
||||
/**
|
||||
* 查询设备
|
||||
*
|
||||
@ -47,28 +54,33 @@ public class DvMachineryServiceImpl implements IDvMachineryService
|
||||
|
||||
/**
|
||||
* 新增设备
|
||||
*
|
||||
*
|
||||
* @param dvMachinery 设备
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int insertDvMachinery(DvMachinery dvMachinery)
|
||||
public AjaxResult insertDvMachinery(DvMachinery dvMachinery)
|
||||
{
|
||||
List<DvMachinery> existing = dvMachineryMapper.selectByMachineryCode(dvMachinery.getMachineryCode());
|
||||
if (existing != null && existing.size() > 0) {
|
||||
return AjaxResult.error("设备编码重复");
|
||||
}
|
||||
dvMachinery.setCreateTime(DateUtils.getNowDate());
|
||||
return dvMachineryMapper.insertDvMachinery(dvMachinery);
|
||||
wmBarCodeUtil.generateBarCode(UserConstants.BARCODE_TYPE_MACHINERY,dvMachinery.getMachineryId(),dvMachinery.getMachineryCode(),dvMachinery.getMachineryName());
|
||||
return AjaxResult.success(dvMachineryMapper.insertDvMachinery(dvMachinery));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改设备
|
||||
*
|
||||
*
|
||||
* @param dvMachinery 设备
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int updateDvMachinery(DvMachinery dvMachinery)
|
||||
public AjaxResult updateDvMachinery(DvMachinery dvMachinery)
|
||||
{
|
||||
dvMachinery.setUpdateTime(DateUtils.getNowDate());
|
||||
return dvMachineryMapper.updateDvMachinery(dvMachinery);
|
||||
return AjaxResult.success(dvMachineryMapper.updateDvMachinery(dvMachinery));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -108,11 +120,11 @@ public class DvMachineryServiceImpl implements IDvMachineryService
|
||||
for (DvMachinery machinery : machineryList) {
|
||||
// 去除空格
|
||||
String machineryCode = machinery.getMachineryCode().trim();
|
||||
DvMachinery existing = dvMachineryMapper.selectByMachineryCode(machineryCode);
|
||||
if (existing != null) {
|
||||
List<DvMachinery> existing = dvMachineryMapper.selectByMachineryCode(machineryCode);
|
||||
if (existing != null && existing.size() > 0) {
|
||||
if (isUpdateSupport) {
|
||||
// 更新数据
|
||||
machinery.setMachineryId(existing.getMachineryId()); // 确保使用现有 ID 进行更新
|
||||
machinery.setMachineryId(existing.get(0).getMachineryId()); // 确保使用现有 ID 进行更新
|
||||
dvMachineryMapper.updateDvMachinery(machinery);
|
||||
successCount++;
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user