feat():设备编码不允许重复创建

master
jiyufei 2 months ago
parent 56afb9a1c1
commit 5d89f11376

@ -31,7 +31,7 @@ public interface YysDeviceService extends IService<YysDeviceEntity> {
//副表数据方法 //副表数据方法
String checkForm(YysDeviceForm form, int i); String checkForm(YysDeviceForm form, int i);
void saveOrUpdate(YysDeviceForm yysDeviceForm, String id, boolean isSave) throws Exception; String saveOrUpdate(YysDeviceForm yysDeviceForm, String id, boolean isSave);
/** /**
* code * code

@ -22,6 +22,7 @@ import jnpf.service.YysDeviceMaterialService;
import jnpf.service.YysDeviceService; import jnpf.service.YysDeviceService;
import jnpf.service.YysDeviceUpkeepService; import jnpf.service.YysDeviceUpkeepService;
import jnpf.util.*; import jnpf.util.*;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -309,7 +310,7 @@ public class YysDeviceServiceImpl extends ServiceImpl<YysDeviceMapper, YysDevice
*/ */
@Override @Override
@Transactional @Transactional
public void saveOrUpdate(YysDeviceForm yysDeviceForm, String id, boolean isSave) throws Exception { public String saveOrUpdate(YysDeviceForm yysDeviceForm, String id, boolean isSave){
UserInfo userInfo = userProvider.get(); UserInfo userInfo = userProvider.get();
UserEntity userEntity = generaterSwapUtil.getUser(userInfo.getUserId()); UserEntity userEntity = generaterSwapUtil.getUser(userInfo.getUserId());
yysDeviceForm = JsonUtil.getJsonToBean( yysDeviceForm = JsonUtil.getJsonToBean(
@ -317,6 +318,11 @@ public class YysDeviceServiceImpl extends ServiceImpl<YysDeviceMapper, YysDevice
YysDeviceEntity entity = JsonUtil.getJsonToBean(yysDeviceForm, YysDeviceEntity.class); YysDeviceEntity entity = JsonUtil.getJsonToBean(yysDeviceForm, YysDeviceEntity.class);
if (isSave) { if (isSave) {
LambdaQueryWrapper<YysDeviceMaterialEntity> wrapper1 = new LambdaQueryWrapper<>();
wrapper1.eq(YysDeviceMaterialEntity::getDeviceCode, entity.getDeviceCode());
if (CollectionUtils.isNotEmpty(yysDeviceMaterialService.list(wrapper1))) {
return "不可以重复创建";
}
String mainId = RandomUtil.uuId(); String mainId = RandomUtil.uuId();
entity.setCreatorTime(DateUtil.getNowDate()); entity.setCreatorTime(DateUtil.getNowDate());
entity.setCreatorUserId(userInfo.getUserId()); entity.setCreatorUserId(userInfo.getUserId());
@ -335,6 +341,7 @@ public class YysDeviceServiceImpl extends ServiceImpl<YysDeviceMapper, YysDevice
//向设备维保表同步数据 //向设备维保表同步数据
yysDeviceUpkeepService.syncSaveOrUpdate(entity); yysDeviceUpkeepService.syncSaveOrUpdate(entity);
} }
return "操作成功";
} }
@Override @Override

@ -116,12 +116,12 @@ public class YysDeviceController {
if (StringUtil.isNotEmpty(b)) { if (StringUtil.isNotEmpty(b)) {
return ActionResult.fail(b); return ActionResult.fail(b);
} }
try { String result = yysDeviceService.saveOrUpdate(yysDeviceForm, null, true);
yysDeviceService.saveOrUpdate(yysDeviceForm, null, true); if (result.contains("成功")) {
} catch (Exception e) {
return ActionResult.fail("新增数据失败");
}
return ActionResult.success("创建成功"); return ActionResult.success("创建成功");
} else {
return ActionResult.fail(result);
}
} }
/** /**
@ -268,15 +268,14 @@ public class YysDeviceController {
} }
YysDeviceEntity entity = yysDeviceService.getInfo(id); YysDeviceEntity entity = yysDeviceService.getInfo(id);
if (entity != null) { if (entity != null) {
try { String result = yysDeviceService.saveOrUpdate(yysDeviceForm, id, false);
yysDeviceService.saveOrUpdate(yysDeviceForm, id, false); if (result.contains("成功")) {
} catch (Exception e) { return ActionResult.success(result);
return ActionResult.fail("修改数据失败");
}
return ActionResult.success("更新成功");
} else { } else {
return ActionResult.fail("更新失败,数据不存在"); return ActionResult.fail(result);
}
} }
return ActionResult.fail("更新失败,数据不存在");
} }
/** /**

@ -1,87 +1,43 @@
<template> <template>
<el-dialog <el-dialog :title="!dataForm.id ? '新建' : '编辑'" :close-on-click-modal="false" append-to-body :visible.sync="visible"
:title="!dataForm.id ? '新建' : '编辑'" class="JNPF-dialog JNPF-dialog_center" lock-scroll width="850px">
:close-on-click-modal="false"
append-to-body
:visible.sync="visible"
class="JNPF-dialog JNPF-dialog_center"
lock-scroll
width="850px"
>
<el-row :gutter="15" class=""> <el-row :gutter="15" class="">
<el-form <el-form ref="formRef" :model="dataForm" :rules="dataRule" size="small" label-width="100px"
ref="formRef" label-position="right">
:model="dataForm"
:rules="dataRule"
size="small"
label-width="100px"
label-position="right"
>
<template v-if="!loading"> <template v-if="!loading">
<!-- 具体表单 --> <!-- 具体表单 -->
<el-col :span="24"> <el-col :span="24">
<jnpf-form-tip-item label="设备编号" prop="deviceCode"> <jnpf-form-tip-item label="设备编号" prop="deviceCode">
<JnpfInput <JnpfInput v-model="dataForm.deviceCode" @change="changeData('deviceCode', -1)" placeholder="请输入设备编号"
v-model="dataForm.deviceCode" clearable :disabled="!isDisabled" :style="{ width: '100%' }">
@change="changeData('deviceCode', -1)"
placeholder="请输入设备编号"
clearable
:style="{ width: '100%' }"
>
</JnpfInput> </JnpfInput>
</jnpf-form-tip-item> </jnpf-form-tip-item>
</el-col> </el-col>
<el-col :span="24"> <el-col :span="24">
<jnpf-form-tip-item label="设备名称" prop="deviceName"> <jnpf-form-tip-item label="设备名称" prop="deviceName">
<JnpfInput <JnpfInput v-model="dataForm.deviceName" @change="changeData('deviceName', -1)" placeholder="请输入设备名称"
v-model="dataForm.deviceName" clearable :style="{ width: '100%' }">
@change="changeData('deviceName', -1)"
placeholder="请输入设备名称"
clearable
:style="{ width: '100%' }"
>
</JnpfInput> </JnpfInput>
</jnpf-form-tip-item> </jnpf-form-tip-item>
</el-col> </el-col>
<el-col :span="24"> <el-col :span="24">
<jnpf-form-tip-item label="所属部门" prop="deviceDept"> <jnpf-form-tip-item label="所属部门" prop="deviceDept">
<JnpfDepSelect <JnpfDepSelect v-model="dataForm.deviceDept" @change="changeData('deviceDept', -1)" placeholder="请选择所属部门"
v-model="dataForm.deviceDept" selectType="all" :ableIds="ableAll.deviceDeptableIds" clearable :style="{ width: '100%' }">
@change="changeData('deviceDept', -1)"
placeholder="请选择所属部门"
selectType="all"
:ableIds="ableAll.deviceDeptableIds"
clearable
:style="{ width: '100%' }"
>
</JnpfDepSelect> </JnpfDepSelect>
</jnpf-form-tip-item> </jnpf-form-tip-item>
</el-col> </el-col>
<el-col :span="24"> <el-col :span="24">
<jnpf-form-tip-item label="设备类型" prop="deivceType"> <jnpf-form-tip-item label="设备类型" prop="deivceType">
<JnpfSelect <JnpfSelect v-model="dataForm.deivceType" @change="changeData('deivceType', -1)" placeholder="请选择"
v-model="dataForm.deivceType" clearable :style="{ width: '100%' }" :options="deivceTypeOptions" :props="deivceTypeProps">
@change="changeData('deivceType', -1)"
placeholder="请选择"
clearable
:style="{ width: '100%' }"
:options="deivceTypeOptions"
:props="deivceTypeProps"
>
</JnpfSelect> </JnpfSelect>
</jnpf-form-tip-item> </jnpf-form-tip-item>
</el-col> </el-col>
<el-col :span="24"> <el-col :span="24">
<jnpf-form-tip-item label="启用状态" prop="enabledStatus"> <jnpf-form-tip-item label="启用状态" prop="enabledStatus">
<JnpfSelect <JnpfSelect v-model="dataForm.enabledStatus" @change="changeData('enabledStatus', -1)" placeholder="请选择"
v-model="dataForm.enabledStatus" clearable :style="{ width: '100%' }" :options="enabledStatusOptions" :props="enabledStatusProps">
@change="changeData('enabledStatus', -1)"
placeholder="请选择"
clearable
:style="{ width: '100%' }"
:options="enabledStatusOptions"
:props="enabledStatusProps"
>
</JnpfSelect> </JnpfSelect>
</jnpf-form-tip-item> </jnpf-form-tip-item>
</el-col> </el-col>
@ -115,12 +71,7 @@
<h2>绑定物料列表</h2> <h2>绑定物料列表</h2>
</div> </div>
<el-table :data="dataForm.data" size="mini"> <el-table :data="dataForm.data" size="mini">
<el-table-column <el-table-column type="index" width="50" label="序号" align="center" />
type="index"
width="50"
label="序号"
align="center"
/>
<!-- <el-table-column label="序号"> <!-- <el-table-column label="序号">
<template slot-scope="scope"> <template slot-scope="scope">
{{ scope.row.deviceCode }} {{ scope.row.deviceCode }}
@ -138,31 +89,15 @@
</el-table-column> </el-table-column>
<el-table-column label="8小时产量"> <el-table-column label="8小时产量">
<template slot-scope="scope"> <template slot-scope="scope">
<JnpfInputNumber <JnpfInputNumber v-model="scope.row.eightOutput" @change="changeData('eightOutput', -1)"
v-model="scope.row.eightOutput" placeholder="请输入" clearable :style="{ width: '100%' }" :precision="2" :step="1" :min="0">
@change="changeData('eightOutput', -1)"
placeholder="请输入"
clearable
:style="{ width: '100%' }"
:precision="2"
:step="1"
:min="0"
>
</JnpfInputNumber> </JnpfInputNumber>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column label="12小时产量"> <el-table-column label="12小时产量">
<template slot-scope="scope"> <template slot-scope="scope">
<JnpfInputNumber <JnpfInputNumber v-model="scope.row.twelveOutput" @change="changeData('twelveOutput', -1)"
v-model="scope.row.twelveOutput" placeholder="请输入" clearable :style="{ width: '100%' }" :precision="2" :step="1" :min="0">
@change="changeData('twelveOutput', -1)"
placeholder="请输入"
clearable
:style="{ width: '100%' }"
:precision="2"
:step="1"
:min="0"
>
</JnpfInputNumber> </JnpfInputNumber>
</template> </template>
</el-table-column> </el-table-column>
@ -175,25 +110,15 @@
<!-- 表单结束 --> <!-- 表单结束 -->
</template> </template>
</el-form> </el-form>
<SelectDialog <SelectDialog v-if="selectDialogVisible" :config="currTableConf" :formData="dataForm" ref="selectDialog"
v-if="selectDialogVisible" @select="addForSelect" @close="selectDialogVisible = false" />
:config="currTableConf"
:formData="dataForm"
ref="selectDialog"
@select="addForSelect"
@close="selectDialogVisible = false"
/>
</el-row> </el-row>
<span slot="footer" class="dialog-footer"> <span slot="footer" class="dialog-footer">
<el-button @click="visible = false"> </el-button> <el-button @click="visible = false"> </el-button>
<el-button type="primary" @click="dataFormSubmit()" :loading="btnLoading"> <el-button type="primary" @click="dataFormSubmit()" :loading="btnLoading">
</el-button </el-button>
>
</span> </span>
<MaterialListDialog <MaterialListDialog ref="materialListDialog" @cbSltdChg="fnSltdMaterialChg" />
ref="materialListDialog"
@cbSltdChg="fnSltdMaterialChg"
/>
</el-dialog> </el-dialog>
</template> </template>
@ -302,6 +227,9 @@ export default {
}; };
}, },
computed: { computed: {
isDisabled() {
return !this.dataForm.id;
},
...mapGetters(["userInfo"]) ...mapGetters(["userInfo"])
}, },
watch: {}, watch: {},
@ -312,6 +240,7 @@ export default {
}, },
mounted() { }, mounted() { },
methods: { methods: {
fnMaterialListDialog() { fnMaterialListDialog() {
this.$nextTick(() => { this.$nextTick(() => {
this.$refs.materialListDialog.init(this.dataForm.data); this.$refs.materialListDialog.init(this.dataForm.data);

Loading…
Cancel
Save