自动新增字典
This commit is contained in:
@@ -5,9 +5,11 @@ import com.gxwebsoft.common.core.annotation.OperationLog;
|
||||
import com.gxwebsoft.common.core.web.ApiResult;
|
||||
import com.gxwebsoft.common.core.web.BaseController;
|
||||
import com.gxwebsoft.common.core.web.PageResult;
|
||||
import com.gxwebsoft.common.system.entity.Dict;
|
||||
import com.gxwebsoft.common.system.entity.DictData;
|
||||
import com.gxwebsoft.common.system.param.DictDataParam;
|
||||
import com.gxwebsoft.common.system.service.DictDataService;
|
||||
import com.gxwebsoft.common.system.service.DictService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
@@ -28,6 +30,8 @@ import java.util.List;
|
||||
public class DictDataController extends BaseController {
|
||||
@Resource
|
||||
private DictDataService dictDataService;
|
||||
@Resource
|
||||
private DictService dictService;
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:dict:list')")
|
||||
@OperationLog
|
||||
@@ -68,6 +72,18 @@ public class DictDataController extends BaseController {
|
||||
.eq(DictData::getDictDataCode, dictData.getDictDataCode())) > 0) {
|
||||
return fail("字典数据标识已存在");
|
||||
}
|
||||
// 自动添加字典
|
||||
if (dictService.count(new LambdaQueryWrapper<Dict>().eq(Dict::getDictCode,dictData.getDictCode())) == 0) {
|
||||
final Dict dict = new Dict();
|
||||
dict.setDictCode(dictData.getDictCode());
|
||||
dict.setDictName(dictData.getDictCode());
|
||||
if (dictData.getDictName() != null) {
|
||||
dict.setDictName(dictData.getDictName());
|
||||
}
|
||||
if(dictService.save(dict)){
|
||||
dictData.setDictId(dict.getDictId());
|
||||
}
|
||||
}
|
||||
if (dictDataService.save(dictData)) {
|
||||
return success("添加成功");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user