|
|
@@ -6,6 +6,7 @@ import com.alibaba.excel.ExcelWriter;
|
|
|
import com.alibaba.excel.support.ExcelTypeEnum;
|
|
|
import com.alibaba.excel.write.metadata.WriteSheet;
|
|
|
import com.alibaba.excel.write.metadata.fill.FillConfig;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import jakarta.annotation.Resource;
|
|
|
@@ -75,17 +76,34 @@ public class CgJsbzServiceImpl extends BaseServiceImpl<CgJsbzMapper, CgJsbzEntit
|
|
|
}
|
|
|
jsbzDTO.setXmId(xmId);
|
|
|
}
|
|
|
- this.save(jsbzDTO);
|
|
|
+ if (isDuplicate(jsbzDTO)) {
|
|
|
+ throw new ServiceException("标准号/标准名称已存在");
|
|
|
+ }
|
|
|
+// List<CgJsbzEntity> dbList = baseMapper.selectList(Wrappers.<CgJsbzEntity>lambdaQuery().eq(CgJsbzEntity::getZbmc, excel.getZbmc()).or().eq(CgJsbzEntity::getZbh, excel.getZbh()));
|
|
|
+// if (dbList.isEmpty()) {
|
|
|
+// this.save(jsbzDTO);
|
|
|
+// } else if (dbList.size() == 1) {
|
|
|
+// jsbzDTO.setId(dbList.get(0).getId());
|
|
|
+// this.updateById(jsbzDTO);
|
|
|
+// } else {
|
|
|
+// throw new ServiceException("标准号/标准名称已存在");
|
|
|
+// }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public boolean save(CgJsbzEntity cgJsbz) {
|
|
|
+ if (isDuplicate(cgJsbz)) {
|
|
|
+ throw new ServiceException("标准号/标准名称已存在");
|
|
|
+ }
|
|
|
return super.save(cgJsbz);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public boolean update(CgJsbzEntity cgJsbz) {
|
|
|
+ if (isDuplicate(cgJsbz)) {
|
|
|
+ throw new ServiceException("标准号/标准名称已存在");
|
|
|
+ }
|
|
|
CgJsbzEntity dbJsbz = this.getById(cgJsbz.getId());
|
|
|
if (!Objects.equals(dbJsbz.getXmbh(), cgJsbz.getXmbh())) {
|
|
|
XmEntity dbXm = xmMapper.selectOne(Wrappers.<XmEntity>lambdaQuery().eq(XmEntity::getXmbh, cgJsbz.getXmbh()));
|
|
|
@@ -95,6 +113,19 @@ public class CgJsbzServiceImpl extends BaseServiceImpl<CgJsbzMapper, CgJsbzEntit
|
|
|
return updateById(cgJsbz);
|
|
|
}
|
|
|
|
|
|
+ private boolean isDuplicate(CgJsbzEntity cgJsbz) {
|
|
|
+ LambdaQueryWrapper<CgJsbzEntity> wrapper = Wrappers.<CgJsbzEntity>lambdaQuery()
|
|
|
+ .eq(CgJsbzEntity::getZbh, cgJsbz.getZbh()).or().eq(CgJsbzEntity::getZbmc, cgJsbz.getZbmc());
|
|
|
+ List<CgJsbzEntity> list = baseMapper.selectList(wrapper);
|
|
|
+ if (Func.isEmpty(list)) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ if (list.size() == 1) {
|
|
|
+ return cgJsbz.getId() == null || !Func.equals(cgJsbz.getId(), list.get(0).getId());
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public boolean physicalDeleteByIds(List<Long> ids) {
|
|
|
return baseMapper.physicalDeleteByIds(ids);
|