Commit da186756 authored by 鲁鑫's avatar 鲁鑫

资源值的增删改查

parent 3099a277
...@@ -2,7 +2,7 @@ $(document).ready(function () { ...@@ -2,7 +2,7 @@ $(document).ready(function () {
initResourceFieldGrid(); initResourceFieldGrid();
}); });
//初始化研制人员 //初始化资源
function initResourceFieldGrid(){ function initResourceFieldGrid(){
var toolbarOptions = UICtrl.getDefaultToolbarOptions({ var toolbarOptions = UICtrl.getDefaultToolbarOptions({
addHandler: function(){ addHandler: function(){
...@@ -15,7 +15,7 @@ function initResourceFieldGrid(){ ...@@ -15,7 +15,7 @@ function initResourceFieldGrid(){
param: {}, param: {},
gridManager: _grid, gridManager: _grid,
onSuccess: function () { onSuccess: function () {
reloadGrid(); reloadFieldGrid();
} }
}); });
} }
...@@ -92,7 +92,7 @@ function getGridColumns(){ ...@@ -92,7 +92,7 @@ function getGridColumns(){
return columns; return columns;
} }
function reloadGrid() { function reloadFieldGrid() {
var param = {tableName:$("#tableName").val()}; var param = {tableName:$("#tableName").val()};
$('#resourceFieldGrid').ligerGetGridManager().options.url =web_app.name + '/resource/findParentResourceTypeAndFields.ajax'; $('#resourceFieldGrid').ligerGetGridManager().options.url =web_app.name + '/resource/findParentResourceTypeAndFields.ajax';
_grid = UICtrl.getGridManager('#resourceFieldGrid'); _grid = UICtrl.getGridManager('#resourceFieldGrid');
......
...@@ -3,34 +3,21 @@ $(document).ready(function () { ...@@ -3,34 +3,21 @@ $(document).ready(function () {
}); });
function initResourceFields() { function initResourceFields() {
Public.ajax(web_app.name + "/resourceField/getResourceField.ajax", { Public.ajax(web_app.name + "/resourceField/getResourceFieldValue.ajax", {
resourceTypeId: $("#resourceTypeId").val() resourceTypeId: $("#resourceTypeId").val(),id: $("#id").val()
}, function (data) { }, function (data) {
debugger; var $d = $('#submitForm .hg-form-row');
var $d = $('#rowDiv');
for (var i = 0; i < data.length; i++) { for (var i = 0; i < data.length; i++) {
var field = data[i]; var field = data[i];
//var s = $(`<input name="${field.resourceFieldName}" label="${field.resourceFiledTitle}" labelCol="2" fieldCol="4"/>`); var ss = $(`<div class="col-xs-4 col-sm-2">
//var input = $("<x:inputC name='").append(field.resourceFieldName).append("' label='").append(field.resourceFiledTitle).append("'").append("/>");
/*var ss = $(`<div class="col-xs-4 col-sm-2">
<label class="hg-form-label" id="${field.resourceFiledTitle}_label" title="${field.resourceFiledTitle}"> <label class="hg-form-label" id="${field.resourceFiledTitle}_label" title="${field.resourceFiledTitle}">
${field.resourceFiledTitle} : ${field.resourceFiledTitle} :
</label> </label>
</div> </div>
<div class="col-xs-8 col-sm-4 col-warp col-white-bg"> <div class="col-xs-8 col-sm-4 col-warp col-white-bg">
<input type="text" name="${field.resourceFieldName}" id="${field.resourceFieldName}" label="${field.resourceFiledTitle}"> <input type="text" name="${field.resourceFieldName}" id="${field.resourceFieldName}" value="${field.resourceFieldValue}" label="${field.resourceFiledTitle}">
</div>`)*/ </div>`)
$d.append(ss);
var ss = $(`<div class="col-xs-4 col-sm-2">
<label class="hg-form-label" id="resourceFiledTitle_label" title="哈哈哈哈哈哈">
哈哈哈哈 :
</label>
</div>
`)
var s2= $(`<div class="col-xs-8 col-sm-4 col-warp col-white-bg">
<input type="text" name="name" id="name" label="hhhhhhh">
</div>`);
$d.append(ss,s2);
//input1.attr('value', data[i]); //input1.attr('value', data[i]);
} }
} }
......
...@@ -5,11 +5,10 @@ ...@@ -5,11 +5,10 @@
<x:script src='/biz/topsun/resource/fieldValueDetail.js'/> <x:script src='/biz/topsun/resource/fieldValueDetail.js'/>
</head> </head>
<form class="hg-form" method="post" action="" id="submitForm"> <form class="hg-form" method="post" action="" id="submitForm">
<x:hidden name="tableName" /> <x:hidden name="id" />
<x:hidden name="resourceTypeId"/> <x:hidden name="resourceTypeId"/>
<div class="hg-form-cols"> <div class="hg-form-cols">
<div class="hg-form-row" id="rowDiv> <div class="hg-form-row">
<x:inputC name="resourceTableTitle" required="true" label="资源名称" labelCol="2" fieldCol="4"/>
</div> </div>
</div> </div>
</form> </form>
\ No newline at end of file
...@@ -43,7 +43,7 @@ function initializeGrid() { ...@@ -43,7 +43,7 @@ function initializeGrid() {
gridManager = UICtrl.grid('#maingrid', { gridManager = UICtrl.grid('#maingrid', {
//columns: columnData, //columns: columnData,
dataAction : 'server', dataAction : 'server',
url: web_app.name+'/resourceField/getResourceFieldValue.ajax', url: web_app.name+'/resourceField/getResourceFieldValueList.ajax',
parms: {resourceTypeId: $("#resourceTypeId").val()}, parms: {resourceTypeId: $("#resourceTypeId").val()},
checkbox: true, checkbox: true,
width : '100%', width : '100%',
...@@ -114,11 +114,14 @@ function addHandler() { ...@@ -114,11 +114,14 @@ function addHandler() {
//新增保存 //新增保存
function insert() { function insert() {
var _self=this,systemId=$('#treeSystemId').val(); var _self=this;
$('#submitForm').ajaxSubmit({ $('#submitForm').ajaxSubmit({
url : web_app.name + '/ssrfPurchaseBudget/insertSsrfBudgetRecord.ajax', url : web_app.name + '/resourceField/saveResourceFiledValue.ajax',
param:{systemId:systemId}, param:{},
success : function(data) { success : function(data) {
if (data == "1"){
Public.successTip("保存成功!");
}
_self.close(); _self.close();
reloadGrid(); reloadGrid();
} }
...@@ -134,11 +137,10 @@ function updateHandler(id) { ...@@ -134,11 +137,10 @@ function updateHandler(id) {
} }
} }
UICtrl.showAjaxDialog({ UICtrl.showAjaxDialog({
title: $.i18nProp('common.field.modif.title','预算'), title: $.i18nProp('资源值'),
width: 600, width: 600,
url: web_app.name + '/ssrfPurchaseBudget/showLoadSsrfBudgetRecord.load', url: web_app.name + '/resourceField/forwardUpdateResourceFieldValue.load',
init:initDetailDialog, param: {id: id,resourceTypeId: $('#resourceTypeId').val()},
param: {id: id},
ok: update, ok: update,
close:dialogClose close:dialogClose
}); });
...@@ -148,10 +150,14 @@ function updateHandler(id) { ...@@ -148,10 +150,14 @@ function updateHandler(id) {
function update() { function update() {
var _self=this; var _self=this;
$('#submitForm').ajaxSubmit({ $('#submitForm').ajaxSubmit({
url : web_app.name + '/ssrfPurchaseBudget/updateSsrfBudgetRecord.ajax', url : web_app.name + '/resourceField/updateResourceFiledValue.ajax',
success : function() { success : function(data) {
if (data == "1"){
Public.successTip("修改成功!");
}
refreshFlag = true; refreshFlag = true;
_self.close(); _self.close();
reloadGrid();
} }
}); });
} }
...@@ -159,30 +165,16 @@ function update() { ...@@ -159,30 +165,16 @@ function update() {
//删除按钮 //删除按钮
function deleteHandler() { function deleteHandler() {
DataUtil.del({ DataUtil.del({
action: 'ssrfPurchaseBudget/deleteSsrfBudgetRecord.ajax', action: 'resourceField/deleteResourceFiledValue.ajax',
param:{
id:DataUtil.getUpdateRowId(gridManager),
resourceTypeId: $('#resourceTypeId').val()
},
gridManager: gridManager, idFieldName: 'id', gridManager: gridManager, idFieldName: 'id',
onSuccess: function () { onSuccess: function (data) {
reloadGrid(); if (data == "1"){
} Public.successTip("删除成功!");
}); }
}
//启用
function enableHandler(){
DataUtil.updateById({ action: 'ssrfPurchaseBudget/updateHaseBudgetStatus.ajax',
gridManager: gridManager,idFieldName:'id', param:{status:1},
message:'common.confirm.enable',
onSuccess:function(){
reloadGrid();
}
});
}
//禁用
function disableHandler(){
DataUtil.updateById({ action: 'ssrfPurchaseBudget/updateHaseBudgetStatus.ajax',
gridManager: gridManager,idFieldName:'id',param:{status:0},
message: 'common.confirm.disable',
onSuccess:function(){
reloadGrid(); reloadGrid();
} }
}); });
......
...@@ -97,7 +97,7 @@ public class ResourceController extends CommonController { ...@@ -97,7 +97,7 @@ public class ResourceController extends CommonController {
//@Operation(summary = "根据id查询资源") //@Operation(summary = "根据id查询资源")
public String findById(){ public String findById(){
SDO sdo = this.getSDO(); SDO sdo = this.getSDO();
Long id = sdo.getLong("id"); String id = sdo.getString("id");
ResourceTypeVo resourceTypeVo = resourceTypeService.findById(id); ResourceTypeVo resourceTypeVo = resourceTypeService.findById(id);
return toResult(resourceTypeVo); return toResult(resourceTypeVo);
} }
......
package com.huigou.topsun.resource.controller; package com.huigou.topsun.resource.controller;
import com.huigou.topsun.resource.service.ResourceFiledService; import com.huigou.topsun.resource.service.ResourceFiledService;
import com.huigou.topsun.resource.vo.ResourceFiledVo;
import com.huigou.uasp.annotation.ControllerMapping; import com.huigou.uasp.annotation.ControllerMapping;
import com.huigou.uasp.client.CommonController; import com.huigou.uasp.client.CommonController;
import com.huigou.util.SDO; import com.huigou.util.SDO;
import com.huigou.util.StringUtil;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -34,40 +37,65 @@ public class ResourceFieldController extends CommonController { ...@@ -34,40 +37,65 @@ public class ResourceFieldController extends CommonController {
return forward("fieldValueDetail"); return forward("fieldValueDetail");
} }
public String forwardUpdateResourceFieldValue(){
return forward("fieldValueDetail");
}
//@Operation(summary = "根据资源类型id,查询资源字段") //@Operation(summary = "根据资源类型id,查询资源字段")
public String getResourceField(){ public String getResourceField(){
SDO sdo = this.getSDO(); SDO sdo = this.getSDO();
Long resourceTypeId = sdo.getLong("resourceTypeId"); String resourceTypeId = sdo.getString("resourceTypeId");
return toResult(resourceFiledService.findByResourceTypeId(resourceTypeId)); return toResult(resourceFiledService.findByResourceTypeId(resourceTypeId));
} }
public String getResourceFieldValue(){
SDO sdo = this.getSDO();
String id = sdo.getString("id");
String resourceTypeId = sdo.getString("resourceTypeId");
List<ResourceFiledVo> resourceFiledVos = resourceFiledService.findFieldValueByResourceTypeIdAndId(resourceTypeId, id);
return toResult(resourceFiledVos);
}
//@Operation(summary = "保存资源字段值") //@Operation(summary = "保存资源字段值")
public String saveResourceFiledValue(@RequestBody HashMap<String,Object> map){ public String saveResourceFiledValue(){
SDO sdo = this.getSDO();
Map<String, Object> map = sdo.getProperties();
return toResult(resourceFiledService.saveResourceFiledValue(map)); return toResult(resourceFiledService.saveResourceFiledValue(map));
} }
//@Operation(summary = "修改资源字段值") //@Operation(summary = "修改资源字段值")
public String updateResourceFiledValue(@RequestBody HashMap<String,Object> map){ public String updateResourceFiledValue(){
SDO sdo = this.getSDO();
Map<String, Object> map = sdo.getProperties();
return toResult(resourceFiledService.saveResourceFiledValue(map)); return toResult(resourceFiledService.saveResourceFiledValue(map));
} }
//@Operation(summary = "根据资源类型id,获取资源值") //@Operation(summary = "根据资源类型id,获取资源值")
public String getResourceFieldValue(){ public String getResourceFieldValueList(){
SDO sdo = this.getSDO(); SDO sdo = this.getSDO();
Long resourceTypeId = sdo.getLong("resourceTypeId"); String resourceTypeId = sdo.getString("resourceTypeId");
List<Map<String, Object>> resourceFieldValue = resourceFiledService.getResourceFieldValue(resourceTypeId); List<Map<String, Object>> resourceFieldValue = null;
if (StringUtil.isBlank(resourceTypeId)){
resourceFieldValue = new ArrayList<>();
}else {
resourceFieldValue = resourceFiledService.getResourceFieldValueList(resourceTypeId);
}
HashMap<Object, Object> map = new HashMap<>(); HashMap<Object, Object> map = new HashMap<>();
map.put("Rows",resourceFieldValue); map.put("Rows",resourceFieldValue);
return toResult(map); return toResult(map);
//return success();
} }
//@Operation(summary = "根据资源类型id和数据id删除资源值") //@Operation(summary = "根据资源类型id和数据id删除资源值")
public String deleteResourceFiledValue(@RequestParam("resourceTypeId") Long resourceTypeId, @RequestParam("id") Long id){ public String deleteResourceFiledValue(){
SDO sdo = this.getSDO();
String id = sdo.getString("id");
String resourceTypeId = sdo.getString("resourceTypeId");
return toResult(resourceFiledService.deleteResourceFieldValue(resourceTypeId,id)); return toResult(resourceFiledService.deleteResourceFieldValue(resourceTypeId,id));
} }
public String getResourceFieldType(@RequestParam("id") Long id){ public String getResourceFieldType(){
SDO sdo = this.getSDO();
String id = sdo.getString("id");
return toResult(resourceFiledService.findById(id)); return toResult(resourceFiledService.findById(id));
} }
} }
...@@ -19,14 +19,14 @@ public class ResourceFiled implements Serializable { ...@@ -19,14 +19,14 @@ public class ResourceFiled implements Serializable {
*/ */
//@Schema(description = "资源字段ID") //@Schema(description = "资源字段ID")
@TableId(value = "resource_field_id") @TableId(value = "resource_field_id")
private Long resourceFieldId; private String resourceFieldId;
/** /**
* 所属资源类型 * 所属资源类型
*/ */
//@Schema(description = "所属资源类型ID") //@Schema(description = "所属资源类型ID")
@TableField(value = "resource_type_id") @TableField(value = "resource_type_id")
private Long resourceTypeId; private String resourceTypeId;
/** /**
* 字段名 * 字段名
......
...@@ -21,7 +21,7 @@ public class ResourceType implements Serializable { ...@@ -21,7 +21,7 @@ public class ResourceType implements Serializable {
*/ */
//@Schema(description = "资源库类型ID") //@Schema(description = "资源库类型ID")
@TableId(value = "resource_type_id") @TableId(value = "resource_type_id")
private Long resourceTypeId; private String resourceTypeId;
/** /**
* 资源库类型表名 * 资源库类型表名
......
...@@ -18,9 +18,9 @@ import java.util.Map; ...@@ -18,9 +18,9 @@ import java.util.Map;
*/ */
public interface ResourceFiledMapper extends BaseMapper<ResourceFiled> { public interface ResourceFiledMapper extends BaseMapper<ResourceFiled> {
void deleteByResourceTypeId(@Param("resourceTypeId") Long resourceTypeId); void deleteByResourceTypeId(@Param("resourceTypeId") String resourceTypeId);
List<ResourceFiled> findByResourceTypeId(@Param("resourceTypeId") Long resourceTypeId); List<ResourceFiled> findByResourceTypeId(@Param("resourceTypeId") String resourceTypeId);
void createTable(@Param("tableName")String tableName,@Param("tableTile")String tableTile, @Param("resourceFields")List<ResourceFiledVo> resourceFields); void createTable(@Param("tableName")String tableName,@Param("tableTile")String tableTile, @Param("resourceFields")List<ResourceFiledVo> resourceFields);
...@@ -30,13 +30,15 @@ public interface ResourceFiledMapper extends BaseMapper<ResourceFiled> { ...@@ -30,13 +30,15 @@ public interface ResourceFiledMapper extends BaseMapper<ResourceFiled> {
int insertData(@Param("tableName")String tableName,@Param("resourceFieldValues")List<ResourceFieldValue> resourceFieldValues); int insertData(@Param("tableName")String tableName,@Param("resourceFieldValues")List<ResourceFieldValue> resourceFieldValues);
int updateData(@Param("id") Long id, @Param("tableName")String tableName,@Param("resourceFieldValues")List<ResourceFieldValue> resourceFieldValues); int updateData(@Param("id") String id, @Param("tableName")String tableName,@Param("resourceFieldValues")List<ResourceFieldValue> resourceFieldValues);
List<Map<String,Object>> selectDataList(@Param("tableName")String tableName); List<Map<String,Object>> selectDataList(@Param("tableName")String tableName);
int deleteDataById(@Param("tableName")String tableName,@Param("id") Long id); int deleteDataById(@Param("tableName")String tableName,@Param("id") String id);
void dropTableByResourceTableName(@Param("tableName") String tableName); void dropTableByResourceTableName(@Param("tableName") String tableName);
Map<String, Object> findFieldValueByResourceTypeIdAndId(@Param("tableName") String tableName,@Param("id") String id);
} }
......
...@@ -28,21 +28,23 @@ public interface ResourceFiledService extends IService<ResourceFiled> { ...@@ -28,21 +28,23 @@ public interface ResourceFiledService extends IService<ResourceFiled> {
ResourceFiledVo updateResourceFiled(ResourceFiledVo resourceFiled); ResourceFiledVo updateResourceFiled(ResourceFiledVo resourceFiled);
void deleteById(Long id); void deleteById(String id);
void deleteByResourceTypeId(Long resourceFieldId); void deleteByResourceTypeId(String resourceFieldId);
ResourceFiledVo findById(Long id); ResourceFiledVo findById(String id);
List<ResourceFiledVo> findList(); List<ResourceFiledVo> findList();
List<ResourceFiledVo> findByResourceTypeId(Long resourceTypeId); List<ResourceFiledVo> findByResourceTypeId(String resourceTypeId);
int saveResourceFiledValue(HashMap<String,Object> obj); int saveResourceFiledValue(Map<String, Object> map);
List<Map<String, Object>> getResourceFieldValue(Long resourceTypeId); List<Map<String, Object>> getResourceFieldValueList(String resourceTypeId);
int deleteResourceFieldValue(Long resourceTypeId, Long id); int deleteResourceFieldValue(String resourceTypeId, String id);
List<ResourceFiledVo> findFieldValueByResourceTypeIdAndId(String resourceTypeId, String id);
void dropTableByResourceName(String tableName); void dropTableByResourceName(String tableName);
} }
...@@ -22,9 +22,9 @@ public interface ResourceTypeService extends IService<ResourceType> { ...@@ -22,9 +22,9 @@ public interface ResourceTypeService extends IService<ResourceType> {
ResourceTypeVo updateResourceTypeMain(ResourceTypeVo resourceType); ResourceTypeVo updateResourceTypeMain(ResourceTypeVo resourceType);
void deleteById(Long id); void deleteById(String id);
ResourceTypeVo findById(Long id); ResourceTypeVo findById(String id);
List<ResourceTypeVo> findList(); List<ResourceTypeVo> findList();
......
...@@ -11,8 +11,8 @@ import com.huigou.topsun.resource.domain.ResourceType; ...@@ -11,8 +11,8 @@ import com.huigou.topsun.resource.domain.ResourceType;
import com.huigou.topsun.resource.mapper.ResourceFiledMapper; import com.huigou.topsun.resource.mapper.ResourceFiledMapper;
import com.huigou.topsun.resource.mapper.ResourceTypeMapper; import com.huigou.topsun.resource.mapper.ResourceTypeMapper;
import com.huigou.topsun.resource.service.ResourceFiledService; import com.huigou.topsun.resource.service.ResourceFiledService;
//import com.huigou.topsun.resource.util.IdGenerator;
import com.huigou.topsun.resource.vo.ResourceFiledVo; import com.huigou.topsun.resource.vo.ResourceFiledVo;
import com.huigou.topsun.util.CommonUtil;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
...@@ -31,9 +31,6 @@ public class ResourceFiledServiceImpl extends ServiceImpl<ResourceFiledMapper, R ...@@ -31,9 +31,6 @@ public class ResourceFiledServiceImpl extends ServiceImpl<ResourceFiledMapper, R
private ResourceFiledMapper resourceFiledMapper; private ResourceFiledMapper resourceFiledMapper;
@Resource @Resource
private ResourceTypeMapper resourceTypeMapper; private ResourceTypeMapper resourceTypeMapper;
//@Resource
//private IdGenerator idGenerator;
@Override @Override
public ResourceFiledVo saveResourceFiled(ResourceFiledVo resourceFiledVo) { public ResourceFiledVo saveResourceFiled(ResourceFiledVo resourceFiledVo) {
ResourceFiled resourceFiled = ResourceFiledVo.getResourceFiled(resourceFiledVo); ResourceFiled resourceFiled = ResourceFiledVo.getResourceFiled(resourceFiledVo);
...@@ -87,19 +84,19 @@ public class ResourceFiledServiceImpl extends ServiceImpl<ResourceFiledMapper, R ...@@ -87,19 +84,19 @@ public class ResourceFiledServiceImpl extends ServiceImpl<ResourceFiledMapper, R
} }
@Override @Override
public void deleteById(Long id) { public void deleteById(String id) {
this.removeById(id); this.removeById(id);
} }
@Override @Override
public void deleteByResourceTypeId(Long resourceTypeId) { public void deleteByResourceTypeId(String resourceTypeId) {
LambdaQueryWrapper<ResourceFiled> queryWrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<ResourceFiled> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(ResourceFiled::getResourceTypeId,resourceTypeId); queryWrapper.eq(ResourceFiled::getResourceTypeId,resourceTypeId);
this.remove(queryWrapper); this.remove(queryWrapper);
} }
@Override @Override
public ResourceFiledVo findById(Long id) { public ResourceFiledVo findById(String id) {
ResourceFiled resourceFiled = this.getById(id); ResourceFiled resourceFiled = this.getById(id);
return ResourceFiledVo.getResourceFiledVo(resourceFiled); return ResourceFiledVo.getResourceFiledVo(resourceFiled);
} }
...@@ -111,7 +108,7 @@ public class ResourceFiledServiceImpl extends ServiceImpl<ResourceFiledMapper, R ...@@ -111,7 +108,7 @@ public class ResourceFiledServiceImpl extends ServiceImpl<ResourceFiledMapper, R
} }
@Override @Override
public List<ResourceFiledVo> findByResourceTypeId(Long resourceTypeId) { public List<ResourceFiledVo> findByResourceTypeId(String resourceTypeId) {
LambdaQueryWrapper<ResourceFiled> queryWrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<ResourceFiled> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(ResourceFiled::getResourceTypeId,resourceTypeId); queryWrapper.eq(ResourceFiled::getResourceTypeId,resourceTypeId);
List<ResourceFiled> list = this.list(queryWrapper); List<ResourceFiled> list = this.list(queryWrapper);
...@@ -128,20 +125,20 @@ public class ResourceFiledServiceImpl extends ServiceImpl<ResourceFiledMapper, R ...@@ -128,20 +125,20 @@ public class ResourceFiledServiceImpl extends ServiceImpl<ResourceFiledMapper, R
} }
@Override @Override
public int saveResourceFiledValue(HashMap<String,Object> map) { public int saveResourceFiledValue(Map<String,Object> map) {
Long resourceTypeId = (Long) map.get("resourceTypeId"); String resourceTypeId = (String) map.get("resourceTypeId");
ResourceType resourceType = resourceTypeMapper.selectById(resourceTypeId); ResourceType resourceType = resourceTypeMapper.selectById(resourceTypeId);
//获取表名 //获取表名
String tableName = resourceType.getResourceTableName(); String tableName = resourceType.getResourceTableName();
//获取字段 //获取字段
List<ResourceFiledVo> resourceFiledList = this.findByResourceTypeId(resourceTypeId); List<ResourceFiledVo> resourceFiledList = this.findByResourceTypeId(resourceTypeId);
//自动生成长整型id值 //自动生成uuid值
List<ResourceFieldValue> resourceFieldValues = this.dealFieldAndValue(resourceFiledList, map); List<ResourceFieldValue> resourceFieldValues = this.dealFieldAndValue(resourceFiledList, map);
Long id = (Long) map.get("id"); Object idObj = map.get("id");
if (id == null){ if (idObj == null || idObj == ""){
return resourceFiledMapper.insertData(tableName,resourceFieldValues); return resourceFiledMapper.insertData(tableName,resourceFieldValues);
}else { }else {
return resourceFiledMapper.updateData((Long) map.get("id"),tableName,resourceFieldValues); return resourceFiledMapper.updateData(idObj.toString(),tableName,resourceFieldValues);
} }
} }
...@@ -151,7 +148,7 @@ public class ResourceFiledServiceImpl extends ServiceImpl<ResourceFiledMapper, R ...@@ -151,7 +148,7 @@ public class ResourceFiledServiceImpl extends ServiceImpl<ResourceFiledMapper, R
* @param map * @param map
* @return * @return
*/ */
public List<ResourceFieldValue> dealFieldAndValue(List<ResourceFiledVo> resourceFiledList, HashMap<String, Object> map){ public List<ResourceFieldValue> dealFieldAndValue(List<ResourceFiledVo> resourceFiledList, Map<String, Object> map){
Set<String> keySet = map.keySet(); Set<String> keySet = map.keySet();
List<ResourceFieldValue> resourceFieldValues = new ArrayList<>(); List<ResourceFieldValue> resourceFieldValues = new ArrayList<>();
resourceFiledList resourceFiledList
...@@ -163,7 +160,7 @@ public class ResourceFiledServiceImpl extends ServiceImpl<ResourceFiledMapper, R ...@@ -163,7 +160,7 @@ public class ResourceFiledServiceImpl extends ServiceImpl<ResourceFiledMapper, R
resourceFieldValue.setField(key); resourceFieldValue.setField(key);
//如果值是字符串,文本,日期格式的需要加英文状态下的引号: '' //如果值是字符串,文本,日期格式的需要加英文状态下的引号: ''
if ("string".equals(resourceFiled.getResourceFieldType()) || if ("string".equals(resourceFiled.getResourceFieldType()) ||
"datetime".equals(resourceFiled.getResourceFieldType()) || "date".equals(resourceFiled.getResourceFieldType()) ||
"text".equals(resourceFiled.getResourceFieldType()) ){ "text".equals(resourceFiled.getResourceFieldType()) ){
resourceFieldValue.setValue("'" + map.get(key) + "'"); resourceFieldValue.setValue("'" + map.get(key) + "'");
}else { }else {
...@@ -173,20 +170,19 @@ public class ResourceFiledServiceImpl extends ServiceImpl<ResourceFiledMapper, R ...@@ -173,20 +170,19 @@ public class ResourceFiledServiceImpl extends ServiceImpl<ResourceFiledMapper, R
} }
} }
}); });
Object idObj = map.get("id");
Long id = (Long) map.get("id"); if (idObj == null || idObj == ""){
if (id == null){
ResourceFieldValue resourceFieldValue = new ResourceFieldValue(); ResourceFieldValue resourceFieldValue = new ResourceFieldValue();
resourceFieldValue.setField("id"); resourceFieldValue.setField("id");
//Long nextedId = idGenerator.nextId(resourceFieldValue); String uuid = CommonUtil.createUuid();
resourceFieldValue.setValue(null); resourceFieldValue.setValue("'"+uuid+"'");
resourceFieldValues.add(resourceFieldValue); resourceFieldValues.add(resourceFieldValue);
} }
return resourceFieldValues; return resourceFieldValues;
} }
@Override @Override
public List<Map<String, Object>> getResourceFieldValue(Long resourceTypeId){ public List<Map<String, Object>> getResourceFieldValueList(String resourceTypeId){
List<Map<String, Object>> maps = new ArrayList<>(); List<Map<String, Object>> maps = new ArrayList<>();
if (resourceTypeId == null){ if (resourceTypeId == null){
return maps; return maps;
...@@ -200,13 +196,30 @@ public class ResourceFiledServiceImpl extends ServiceImpl<ResourceFiledMapper, R ...@@ -200,13 +196,30 @@ public class ResourceFiledServiceImpl extends ServiceImpl<ResourceFiledMapper, R
} }
@Override @Override
public int deleteResourceFieldValue(Long resourceTypeId, Long id){ public int deleteResourceFieldValue(String resourceTypeId, String id){
ResourceType resourceType = resourceTypeMapper.selectById(resourceTypeId); ResourceType resourceType = resourceTypeMapper.selectById(resourceTypeId);
//获取表名 //获取表名
String tableName = resourceType.getResourceTableName(); String tableName = resourceType.getResourceTableName();
return resourceFiledMapper.deleteDataById(tableName,id); return resourceFiledMapper.deleteDataById(tableName,id);
} }
@Override
public List<ResourceFiledVo> findFieldValueByResourceTypeIdAndId(String resourceTypeId, String id) {
ResourceType resourceType = resourceTypeMapper.selectById(resourceTypeId);
//获取表名
String tableName = resourceType.getResourceTableName();
Map<String, Object> map = resourceFiledMapper.findFieldValueByResourceTypeIdAndId(tableName, id);
List<ResourceFiledVo> filedVoList = this.findByResourceTypeId(resourceTypeId);
if (map == null){
return filedVoList;
}
for (ResourceFiledVo resourceFiledVo : filedVoList) {
Object value = map.get(resourceFiledVo.getResourceFieldName());
resourceFiledVo.setResourceFieldValue(value);
}
return filedVoList;
}
@Override @Override
public void dropTableByResourceName(String tableName) { public void dropTableByResourceName(String tableName) {
resourceFiledMapper.dropTableByResourceTableName(tableName); resourceFiledMapper.dropTableByResourceTableName(tableName);
......
...@@ -7,7 +7,7 @@ import com.huigou.topsun.resource.domain.ResourceType; ...@@ -7,7 +7,7 @@ import com.huigou.topsun.resource.domain.ResourceType;
import com.huigou.topsun.resource.mapper.ResourceTypeMapper; import com.huigou.topsun.resource.mapper.ResourceTypeMapper;
import com.huigou.topsun.resource.service.ResourceFiledService; import com.huigou.topsun.resource.service.ResourceFiledService;
import com.huigou.topsun.resource.service.ResourceTypeService; import com.huigou.topsun.resource.service.ResourceTypeService;
import com.huigou.topsun.resource.util.PinyinHelperUtil; import com.huigou.topsun.util.PinyinHelperUtil;
import com.huigou.topsun.resource.vo.ResourceFiledVo; import com.huigou.topsun.resource.vo.ResourceFiledVo;
import com.huigou.topsun.resource.vo.ResourceTypeTreeVo; import com.huigou.topsun.resource.vo.ResourceTypeTreeVo;
import com.huigou.topsun.resource.vo.ResourceTypeVo; import com.huigou.topsun.resource.vo.ResourceTypeVo;
...@@ -47,7 +47,7 @@ public class ResourceTypeServiceImpl extends ServiceImpl<ResourceTypeMapper, Res ...@@ -47,7 +47,7 @@ public class ResourceTypeServiceImpl extends ServiceImpl<ResourceTypeMapper, Res
List<String> fieldList = new ArrayList<>(); List<String> fieldList = new ArrayList<>();
for (int i = 0; i < resourceFileds.size(); i++) { for (int i = 0; i < resourceFileds.size(); i++) {
ResourceFiledVo resourceFiled = resourceFileds.get(i); ResourceFiledVo resourceFiled = resourceFileds.get(i);
resourceFiled.setResourceTypeId(resourceType.getResourceTypeId().toString()); resourceFiled.setResourceTypeId(resourceType.getResourceTypeId());
resourceFiled.setResourceFieldId(null); resourceFiled.setResourceFieldId(null);
//字段名称首字母小写 //字段名称首字母小写
String pinYinHeadChar = PinyinHelperUtil.getPinYinHeadChar(resourceFiled.getResourceFiledTitle()); String pinYinHeadChar = PinyinHelperUtil.getPinYinHeadChar(resourceFiled.getResourceFiledTitle());
...@@ -91,7 +91,7 @@ public class ResourceTypeServiceImpl extends ServiceImpl<ResourceTypeMapper, Res ...@@ -91,7 +91,7 @@ public class ResourceTypeServiceImpl extends ServiceImpl<ResourceTypeMapper, Res
//字段名称首字母小写 //字段名称首字母小写
String pinYinHeadChar = PinyinHelperUtil.getPinYinHeadChar(resourceFiledVo.getResourceFieldName()); String pinYinHeadChar = PinyinHelperUtil.getPinYinHeadChar(resourceFiledVo.getResourceFieldName());
resourceFiledVo.setResourceFieldName(pinYinHeadChar); resourceFiledVo.setResourceFieldName(pinYinHeadChar);
resourceFiledVo.setResourceTypeId(resourceTypeVo.getResourceTypeId().toString()); resourceFiledVo.setResourceTypeId(resourceTypeVo.getResourceTypeId());
resourceFiledService.saveResourceFiled(resourceFiledVo); resourceFiledService.saveResourceFiled(resourceFiledVo);
} }
//更新表 //更新表
...@@ -136,7 +136,7 @@ public class ResourceTypeServiceImpl extends ServiceImpl<ResourceTypeMapper, Res ...@@ -136,7 +136,7 @@ public class ResourceTypeServiceImpl extends ServiceImpl<ResourceTypeMapper, Res
@Override @Override
public void deleteById(Long id) { public void deleteById(String id) {
ResourceType resourceType = this.getById(id); ResourceType resourceType = this.getById(id);
resourceFiledService.deleteByResourceTypeId(id); resourceFiledService.deleteByResourceTypeId(id);
resourceTypeMapper.deleteById(id); resourceTypeMapper.deleteById(id);
...@@ -144,7 +144,7 @@ public class ResourceTypeServiceImpl extends ServiceImpl<ResourceTypeMapper, Res ...@@ -144,7 +144,7 @@ public class ResourceTypeServiceImpl extends ServiceImpl<ResourceTypeMapper, Res
} }
@Override @Override
public ResourceTypeVo findById(Long id) { public ResourceTypeVo findById(String id) {
return ResourceTypeVo.getResourceTypeVo(this.getById(id)); return ResourceTypeVo.getResourceTypeVo(this.getById(id));
} }
......
//package com.huigou.topsun.resource.util;
//
//import cn.hutool.core.lang.Snowflake;
//import cn.hutool.core.util.IdUtil;
//import com.baomidou.mybatisplus.core.incrementer.IKeyGenerator;
//import com.baomidou.mybatisplus.core.incrementer.IdentifierGenerator;
//import org.hibernate.HibernateException;
//import org.hibernate.engine.spi.SessionImplementor;
//import org.hibernate.id.IdentifierGenerator;
//import org.springframework.stereotype.Component;
//
//import java.io.Serializable;
//
//@Component
//public class IdGenerator implements IdentifierGenerator {
// @Override
// public Long nextId(Object entity) {
// //使用 hutools 雪花算法生成分布式ID
// //参数1为终端ID
// //参数2为数据中心ID
// Snowflake snowflake = IdUtil.getSnowflake(1, 1);
// return snowflake.nextId();
// }
//
// @Override
// public Serializable generate(SessionImplementor sessionImplementor, Object o) throws HibernateException {
// return null;
// }
//}
...@@ -33,6 +33,11 @@ public class ResourceFiledVo implements Serializable { ...@@ -33,6 +33,11 @@ public class ResourceFiledVo implements Serializable {
//@Schema(description = "字段名") //@Schema(description = "字段名")
private String resourceFieldName; private String resourceFieldName;
/**
* 字段值
*/
private Object resourceFieldValue = "";
/** /**
* 字段显示名 * 字段显示名
*/ */
......
...@@ -18,7 +18,7 @@ public class ResourceTypeVo implements Serializable { ...@@ -18,7 +18,7 @@ public class ResourceTypeVo implements Serializable {
* 资源库类型ID * 资源库类型ID
*/ */
//@Schema(description = "资源库类型ID") //@Schema(description = "资源库类型ID")
private Long resourceTypeId; private String resourceTypeId;
/** /**
* 资源库类型表名 * 资源库类型表名
......
package com.huigou.topsun.util;
import java.util.UUID;
public class CommonUtil {
/**
* @Description TODO(自动生成uuid)
*/
public static String createUuid() {
UUID u = UUID.randomUUID();
String uuid = u.toString().replace("-", "").toUpperCase();
return uuid;
}
}
package com.huigou.topsun.resource.util; package com.huigou.topsun.util;
import net.sourceforge.pinyin4j.PinyinHelper; import net.sourceforge.pinyin4j.PinyinHelper;
public class PinyinHelperUtil { public class PinyinHelperUtil {
/** /**
......
...@@ -56,7 +56,7 @@ ...@@ -56,7 +56,7 @@
<update id="createTable"> <update id="createTable">
create table ${tableName} create table ${tableName}
( id bigint(0) COMMENT '主键ID', ( id varchar(128) COMMENT '主键ID',
<foreach collection="resourceFields" item="resourceField" separator=","> <foreach collection="resourceFields" item="resourceField" separator=",">
<include refid="matchFieldType"/> <include refid="matchFieldType"/>
</foreach> </foreach>
...@@ -108,6 +108,9 @@ ...@@ -108,6 +108,9 @@
<select id="selectDataList" resultType="java.util.Map" parameterType="java.lang.String"> <select id="selectDataList" resultType="java.util.Map" parameterType="java.lang.String">
select * from ${tableName} select * from ${tableName}
</select> </select>
<select id="findFieldValueByResourceTypeIdAndId" resultType="java.util.Map">
select * from ${tableName} where id = #{id}
</select>
<delete id="deleteDataById"> <delete id="deleteDataById">
delete from ${tableName} where id = #{id} delete from ${tableName} where id = #{id}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment