|
@@ -45,19 +45,37 @@ public class RemoteOpcServiceImpl extends BaseServiceImpl<RemoteOpcMapper, Remot
|
|
|
* 1: avFalg=1,则点位后缀必须是_AV
|
|
|
* 2: avFalg=0,则点位后缀必须是_DV
|
|
|
* *
|
|
|
+ *
|
|
|
* @param model
|
|
|
* @return
|
|
|
*/
|
|
|
@Override
|
|
|
public RemoteOpc saveModelByDTO(RemoteOpcDTO model) {
|
|
|
- if(model.getAvFlag()==1){
|
|
|
- if(model.getPositionNum().lastIndexOf("_AV")<0){
|
|
|
+ // 新增判断点位是否已经存在了
|
|
|
+ Weekend<RemoteOpc> weekend = new Weekend<>(RemoteOpc.class);
|
|
|
+ WeekendCriteria<RemoteOpc, Object> weekendCriteria = weekend.weekendCriteria();
|
|
|
+ weekendCriteria.andEqualTo(RemoteOpc::getDescription, model.getDescription());
|
|
|
+ int count = mapper.selectCountByExample(weekend);
|
|
|
+ // 不存在在设置点位信息
|
|
|
+ if (count > 0) {
|
|
|
+ throw new BusinessException("该点位已经存在,无法新增,数量:" + count);
|
|
|
+ }
|
|
|
+ if (model.getAvFlag() == YesNoEnum.YES.getValue()) {
|
|
|
+ model.setPositionNum(model.getDescription() + "_AV");
|
|
|
+ /* if (model.getPositionNum().lastIndexOf("_AV") < 0) {
|
|
|
throw new BusinessException("模拟量的点位后缀必须是_AV,请检查");
|
|
|
- }
|
|
|
- }else{
|
|
|
- if(model.getPositionNum().lastIndexOf("_DV")<0){
|
|
|
+ }*/
|
|
|
+ } else {
|
|
|
+ model.setPositionNum(model.getDescription() + "_DV");
|
|
|
+ /* if (model.getPositionNum().lastIndexOf("_DV") < 0) {
|
|
|
throw new BusinessException("数字量的点位后缀必须是_DV,请检查");
|
|
|
- }
|
|
|
+ }*/
|
|
|
+ }
|
|
|
+ if (model.getXPosition() == null) {
|
|
|
+ model.setXPosition(50);
|
|
|
+ }
|
|
|
+ if (model.getYPosition() == null) {
|
|
|
+ model.setYPosition(50);
|
|
|
}
|
|
|
return super.saveModelByDTO(model);
|
|
|
}
|
|
@@ -67,20 +85,32 @@ public class RemoteOpcServiceImpl extends BaseServiceImpl<RemoteOpcMapper, Remot
|
|
|
* 1: avFalg=1,则点位后缀必须是_AV
|
|
|
* 2: avFalg=0,则点位后缀必须是_DV
|
|
|
* *
|
|
|
+ *
|
|
|
* @param model
|
|
|
* @return
|
|
|
*/
|
|
|
@Override
|
|
|
public void modModelByDTO(RemoteOpcDTO model) {
|
|
|
- if(model.getAvFlag()==1){
|
|
|
- if(model.getPositionNum().lastIndexOf("_AV")<0){
|
|
|
- throw new BusinessException("模拟量的点位后缀必须是_AV,请检查");
|
|
|
- }
|
|
|
- }else{
|
|
|
- if(model.getPositionNum().lastIndexOf("_DV")<0){
|
|
|
- throw new BusinessException("数字量的点位后缀必须是_DV,请检查");
|
|
|
+ // 新增判断点位是否已经存在了
|
|
|
+ Weekend<RemoteOpc> weekend = new Weekend<>(RemoteOpc.class);
|
|
|
+ WeekendCriteria<RemoteOpc, Object> weekendCriteria = weekend.weekendCriteria();
|
|
|
+ weekendCriteria.andEqualTo(RemoteOpc::getDescription, model.getDescription());
|
|
|
+ List<RemoteOpc> list = mapper.selectByExample(weekend);
|
|
|
+ // 不存在在设置点位信息
|
|
|
+ if (!CollectionUtils.isEmpty(list)) {
|
|
|
+ if (list.size() > 1) {
|
|
|
+ throw new BusinessException("该点位已经重复,无法修改:" + list.size());
|
|
|
+ } else {
|
|
|
+ if (!list.get(0).getId().equals(model.getId())) {
|
|
|
+ throw new BusinessException("该点位已经重复,无法修改");
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
+ if (model.getAvFlag() == YesNoEnum.YES.getValue()) {
|
|
|
+ model.setPositionNum(model.getDescription() + "_AV");
|
|
|
+ } else {
|
|
|
+ model.setPositionNum(model.getDescription() + "_DV");
|
|
|
+ }
|
|
|
super.modModelByDTO(model);
|
|
|
}
|
|
|
|
|
@@ -124,7 +154,7 @@ public class RemoteOpcServiceImpl extends BaseServiceImpl<RemoteOpcMapper, Remot
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public String importListByAdd(MultipartFile file, String line) {
|
|
|
- if(line == null){
|
|
|
+ if (line == null) {
|
|
|
line = "1";
|
|
|
}
|
|
|
Weekend<SysDict> weekend = new Weekend<>(SysDict.class);
|
|
@@ -160,7 +190,7 @@ public class RemoteOpcServiceImpl extends BaseServiceImpl<RemoteOpcMapper, Remot
|
|
|
throw new BusinessException("opc数据类型未配置,请配置数据字典:" + remoteOpc.getRemark());
|
|
|
}*/
|
|
|
}
|
|
|
- // sbInfoMapper.insertListforComplex(addSbInfoList);
|
|
|
+ // sbInfoMapper.insertListforComplex(addSbInfoList);
|
|
|
mapper.insertListforComplex(items);
|
|
|
}
|
|
|
return "总计新增导入:" + (items.size());
|
|
@@ -173,6 +203,7 @@ public class RemoteOpcServiceImpl extends BaseServiceImpl<RemoteOpcMapper, Remot
|
|
|
/**
|
|
|
* 批量更新
|
|
|
* updateType 1:更新模拟,其他:更新是否配置
|
|
|
+ *
|
|
|
* @param ids
|
|
|
* @param updateType
|
|
|
* @param value
|
|
@@ -183,17 +214,17 @@ public class RemoteOpcServiceImpl extends BaseServiceImpl<RemoteOpcMapper, Remot
|
|
|
WeekendCriteria<RemoteOpc, Object> weekendCriteria = weekend.weekendCriteria();
|
|
|
weekendCriteria.andIn(RemoteOpc::getId, ids);
|
|
|
RemoteOpc remoteOpc = new RemoteOpc();
|
|
|
- if(updateType==1){
|
|
|
+ if (updateType == 1) {
|
|
|
remoteOpc.setAvFlag(value);
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
remoteOpc.setCreatedFlag(value);
|
|
|
}
|
|
|
mapper.updateByExampleSelective(remoteOpc, weekend);
|
|
|
}
|
|
|
|
|
|
public static void main(String[] args) {
|
|
|
- for(int i=0;i<100;i++){
|
|
|
- System.out.println((int)((Math.random()*6)+1));
|
|
|
+ for (int i = 0; i < 100; i++) {
|
|
|
+ System.out.println((int) ((Math.random() * 6) + 1));
|
|
|
}
|
|
|
}
|
|
|
}
|