新增动态表单列表操作
This commit is contained in:
parent
7c4a058ee9
commit
1a4f53fb25
@ -3,14 +3,15 @@ package com.cm.common.plugin.controller.apis.dynamic.form;
|
||||
import com.cm.common.base.AbstractController;
|
||||
import com.cm.common.constants.ISystemConstant;
|
||||
import com.cm.common.plugin.service.dynamic.IDynamicDataService;
|
||||
import com.cm.common.pojo.ListPage;
|
||||
import com.cm.common.result.ErrorResult;
|
||||
import com.cm.common.result.SuccessResult;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiResponse;
|
||||
import io.swagger.annotations.ApiResponses;
|
||||
import com.cm.common.result.SuccessResultList;
|
||||
import io.swagger.annotations.*;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
@ -31,10 +32,69 @@ public class DynamicDataController extends AbstractController {
|
||||
private IDynamicDataService dynamicDataService;
|
||||
|
||||
@ApiOperation(value = "保存动态数据", notes = "保存动态数据接口")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "tableName", value = "表名", paramType = "path")
|
||||
})
|
||||
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
|
||||
@PostMapping("savedynamicdata/{tableName}")
|
||||
public SuccessResult saveDynamicData(@PathVariable("tableName") String tableName, @RequestBody Map<String, Object> params) {
|
||||
return dynamicDataService.saveDynamicData(tableName, params);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "删除动态数据", notes = "删除动态数据接口")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "tableName", value = "表名", paramType = "path"),
|
||||
@ApiImplicitParam(name = "ids", value = "数据ID列表,用下划线分隔", paramType = "path", example = "1_2_3")
|
||||
})
|
||||
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
|
||||
@DeleteMapping("removedynamicdata/{tableName}/{ids}")
|
||||
public SuccessResult removeDynamicData(@PathVariable("tableName") String tableName, @PathVariable("ids") String ids) {
|
||||
return dynamicDataService.removeDynamicData(tableName, ids);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "修改动态数据", notes = "修改动态数据接口")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "tableName", value = "表名", paramType = "path"),
|
||||
@ApiImplicitParam(name = "id", value = "id", paramType = "path")
|
||||
})
|
||||
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
|
||||
@PutMapping("updatedynamicdata/{tableName}/{id}")
|
||||
public SuccessResult updateDynamicData(@PathVariable("tableName") String tableName, @PathVariable("id") String id, @RequestBody Map<String, Object> params) {
|
||||
return dynamicDataService.updateDynamicData(tableName, id, params);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "动态数据列表", notes = "动态数据列表接口")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "tableName", value = "表名", paramType = "path")
|
||||
})
|
||||
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
|
||||
@GetMapping("listdynamicdata/{tableName}")
|
||||
public List<Map<String, Object>> listDynamicData(@PathVariable("tableName") String tableName) {
|
||||
Map<String, Object> params = getParams();
|
||||
return dynamicDataService.listDynamicData(tableName, params);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "分页动态数据列表", notes = "分页动态数据列表接口")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "tableName", value = "表名", paramType = "path")
|
||||
})
|
||||
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
|
||||
@GetMapping("listpagedynamicdata/{tableName}")
|
||||
public SuccessResultList<List<Map<String, Object>>> listPageDynamicData(@PathVariable("tableName") String tableName, ListPage listPage) {
|
||||
Map<String, Object> params = getParams();
|
||||
listPage.setParams(params);
|
||||
return dynamicDataService.listPageDynamicData(tableName, listPage);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "动态数据详情", notes = "动态数据详情接口")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "tableName", value = "表名", paramType = "path"),
|
||||
@ApiImplicitParam(name = "id", value = "id", paramType = "path"),
|
||||
})
|
||||
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
|
||||
@GetMapping("getdynamicdata/{tableName}/{id}")
|
||||
public Map<String, Object> getDynamicData(@PathVariable("tableName") String tableName, @PathVariable("id") String id) {
|
||||
return dynamicDataService.getDynamicData(tableName, id);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -7,12 +7,11 @@ import com.cm.common.plugin.pojo.vos.dynamicform.DynamicFormVO;
|
||||
import com.cm.common.plugin.service.dynamic.IDynamicFormService;
|
||||
import com.cm.common.result.ErrorResult;
|
||||
import com.cm.common.result.SuccessResult;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiResponse;
|
||||
import io.swagger.annotations.ApiResponses;
|
||||
import io.swagger.annotations.*;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
@ -40,4 +39,15 @@ public class DynamicFormController extends AbstractController {
|
||||
return dynamicFormService.saveDynamicForm(dynamicFormVO);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "列表显示的字段", notes = "列表显示的字段接口")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "tableName", value = "表名", paramType = "path"),
|
||||
})
|
||||
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
|
||||
@GetMapping("listlistshowfield/{tableName}")
|
||||
public List<String> listListShowFieldOfPage(@PathVariable("tableName") String tableName) {
|
||||
// return dynamicFormService.listListShowFieldOfPage(tableName);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,51 @@
|
||||
package com.cm.common.plugin.controller.routes.dynamic.form;
|
||||
|
||||
import com.cm.common.base.AbstractController;
|
||||
import com.cm.common.constants.ISystemConstant;
|
||||
import com.cm.common.plugin.pojo.dtos.dynamic.DynamicFormDTO;
|
||||
import com.cm.common.plugin.service.dynamic.IDynamicFormService;
|
||||
import com.cm.common.result.ErrorResult;
|
||||
import io.swagger.annotations.*;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* When you feel like quitting. Think about why you started
|
||||
* 当你想要放弃的时候,想想当初你为何开始
|
||||
*
|
||||
* @ClassName: DynamicFormRouteController
|
||||
* @Description: 动态表单
|
||||
* @Author: WangGeng
|
||||
* @Date: 2019/12/5 17:19
|
||||
* @Version: 1.0
|
||||
**/
|
||||
@Api(tags = ISystemConstant.API_TAGS_SYSTEM_PREFIX + "动态表单页面接口")
|
||||
@Controller
|
||||
@RequestMapping(ISystemConstant.ROUTE_PREFIX + "/dynamicform")
|
||||
public class DynamicFormRouteController extends AbstractController {
|
||||
|
||||
@Autowired
|
||||
private IDynamicFormService dynamicFormService;
|
||||
|
||||
@ApiOperation(value = "动态表单列表页面", notes = "动态表单列表页面接口")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "tableName", value = "表名", paramType = "path")
|
||||
})
|
||||
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
|
||||
@GetMapping("listdynamicform/{tableName}")
|
||||
public ModelAndView listDynamicForm(@PathVariable("tableName") String tableName) {
|
||||
ModelAndView mv = new ModelAndView("dynamic/form/list");
|
||||
List<String> listShowFieldList = dynamicFormService.listListShowField(tableName);
|
||||
mv.addObject("tableName", tableName);
|
||||
mv.addObject("uuidField", String.format("%sId", tableName));
|
||||
mv.addObject("listShowFieldList", listShowFieldList);
|
||||
return mv;
|
||||
}
|
||||
|
||||
}
|
@ -1,9 +1,13 @@
|
||||
package com.cm.common.plugin.dao.dynamic;
|
||||
|
||||
import com.cm.common.exception.RemoveException;
|
||||
import com.cm.common.exception.SaveException;
|
||||
import com.cm.common.exception.SearchException;
|
||||
import com.cm.common.exception.UpdateException;
|
||||
import com.cm.common.result.SuccessResult;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
@ -27,4 +31,39 @@ public interface IDynamicDataDao {
|
||||
* @throws SaveException
|
||||
*/
|
||||
void saveDynamicData(Map<String, Object> params) throws SaveException;
|
||||
|
||||
/**
|
||||
* 删除动态数据
|
||||
*
|
||||
* @param params
|
||||
* @return
|
||||
* @throws RemoveException
|
||||
*/
|
||||
void removeDynamicData(Map<String, Object> params) throws RemoveException;
|
||||
|
||||
/**
|
||||
* 修改动态数据
|
||||
*
|
||||
* @param params
|
||||
* @throws UpdateException
|
||||
*/
|
||||
void updateDynamicData(Map<String, Object> params) throws UpdateException;
|
||||
|
||||
/**
|
||||
* 动态数据列表
|
||||
*
|
||||
* @param params
|
||||
* @return
|
||||
* @throws SearchException
|
||||
*/
|
||||
List<Map<String, Object>> listDynamicData(Map<String, Object> params) throws SearchException;
|
||||
|
||||
/**
|
||||
* 动态数据详情
|
||||
*
|
||||
* @param params
|
||||
* @return
|
||||
* @throws SearchException
|
||||
*/
|
||||
Map<String, Object> getDynamicData(Map<String, Object> params) throws SearchException;
|
||||
}
|
||||
|
@ -0,0 +1,14 @@
|
||||
package com.cm.common.plugin.pojo.dtos.dynamic;
|
||||
|
||||
/**
|
||||
* When you feel like quitting. Think about why you started
|
||||
* 当你想要放弃的时候,想想当初你为何开始
|
||||
*
|
||||
* @ClassName: DynamicFormListShowFieldDTO
|
||||
* @Description: 动态表单列表显示字段
|
||||
* @Author: WangGeng
|
||||
* @Date: 2019/12/5 18:35
|
||||
* @Version: 1.0
|
||||
**/
|
||||
public class DynamicFormListShowFieldDTO {
|
||||
}
|
@ -1,9 +1,14 @@
|
||||
package com.cm.common.plugin.service.dynamic;
|
||||
|
||||
import com.cm.common.exception.RemoveException;
|
||||
import com.cm.common.exception.SaveException;
|
||||
import com.cm.common.exception.SearchException;
|
||||
import com.cm.common.exception.UpdateException;
|
||||
import com.cm.common.pojo.ListPage;
|
||||
import com.cm.common.result.SuccessResult;
|
||||
import com.cm.common.result.SuccessResultList;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
@ -27,4 +32,54 @@ public interface IDynamicDataService {
|
||||
* @throws SaveException
|
||||
*/
|
||||
SuccessResult saveDynamicData(String tableName, Map<String, Object> params) throws SearchException, SaveException;
|
||||
|
||||
/**
|
||||
* 删除动态数据
|
||||
*
|
||||
* @param tableName
|
||||
* @param ids
|
||||
* @return
|
||||
* @throws RemoveException
|
||||
*/
|
||||
SuccessResult removeDynamicData(String tableName, String ids) throws RemoveException;
|
||||
|
||||
/**
|
||||
* 修改动态数据
|
||||
*
|
||||
* @param tableName
|
||||
* @param id
|
||||
* @param params
|
||||
* @return
|
||||
* @throws UpdateException
|
||||
*/
|
||||
SuccessResult updateDynamicData(String tableName, String id, Map<String, Object> params) throws UpdateException;
|
||||
|
||||
/**
|
||||
* 动态数据列表
|
||||
*
|
||||
* @param tableName
|
||||
* @param params
|
||||
* @return
|
||||
*/
|
||||
List<Map<String, Object>> listDynamicData(String tableName, Map<String, Object> params);
|
||||
|
||||
/**
|
||||
* 分页动态数据列表
|
||||
*
|
||||
* @param tableName
|
||||
* @param listPage
|
||||
* @return
|
||||
* @throws SearchException
|
||||
*/
|
||||
SuccessResultList<List<Map<String, Object>>> listPageDynamicData(String tableName, ListPage listPage) throws SearchException;
|
||||
|
||||
/**
|
||||
* 动态数据详情
|
||||
*
|
||||
* @param tableName
|
||||
* @param id
|
||||
* @return
|
||||
* @throws SearchException
|
||||
*/
|
||||
Map<String, Object> getDynamicData(String tableName, String id) throws SearchException;
|
||||
}
|
||||
|
@ -37,4 +37,23 @@ public interface IDynamicFormService {
|
||||
* @throws SearchException
|
||||
*/
|
||||
List<DynamicFormDTO> listDynamicForm(String tableName) throws SearchException;
|
||||
|
||||
/**
|
||||
* 获取列表显示的字段
|
||||
*
|
||||
* @param tableName
|
||||
* @return
|
||||
* @throws SearchException
|
||||
*/
|
||||
List<String> listListShowField(String tableName) throws SearchException;
|
||||
|
||||
/**
|
||||
* 获取表单显示的字段
|
||||
*
|
||||
* @param tableName
|
||||
* @return
|
||||
* @throws SearchException
|
||||
*/
|
||||
List<String> listFormShowField(String tableName) throws SearchException;
|
||||
|
||||
}
|
||||
|
@ -1,28 +1,29 @@
|
||||
package com.cm.common.plugin.service.dynamic.impl;
|
||||
|
||||
import com.cm.common.base.AbstractService;
|
||||
import com.cm.common.exception.ParamsException;
|
||||
import com.cm.common.exception.SaveException;
|
||||
import com.cm.common.exception.SearchException;
|
||||
import com.cm.common.exception.*;
|
||||
import com.cm.common.plugin.dao.dynamic.IDynamicDataDao;
|
||||
import com.cm.common.plugin.enums.dynamic.FieldRequireTypeEnum;
|
||||
import com.cm.common.plugin.pojo.dtos.database.table.TableColumnDTO;
|
||||
import com.cm.common.plugin.pojo.dtos.dynamic.DynamicFormDTO;
|
||||
import com.cm.common.plugin.service.dynamic.IDynamicDataService;
|
||||
import com.cm.common.plugin.service.dynamic.IDynamicFormService;
|
||||
import com.cm.common.plugin.service.dynamic.IDynamicTableService;
|
||||
import com.cm.common.pojo.ListPage;
|
||||
import com.cm.common.result.SuccessResult;
|
||||
import com.cm.common.result.SuccessResultList;
|
||||
import com.cm.common.utils.RegexUtil;
|
||||
import com.cm.common.utils.UUIDUtil;
|
||||
import com.cm.common.utils.WStringUtil;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import org.apache.commons.collections.KeyValue;
|
||||
import org.apache.commons.collections.keyvalue.DefaultKeyValue;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.lang3.math.NumberUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
@ -56,9 +57,7 @@ public class DynamicDataServiceImpl extends AbstractService implements IDynamicD
|
||||
insertValueList.add(params.get(dynamicFormDTO.getFieldName()));
|
||||
}
|
||||
params.clear();
|
||||
String lowerUnderLineTableName = WStringUtil.lowerUpper2UnderLine(tableName);
|
||||
params.put("tableName", String.format("%s%s", IDynamicTableService.DYNAMIC_TABLE_PREFIX, lowerUnderLineTableName));
|
||||
params.put("uuidField", String.format("%s_id", lowerUnderLineTableName));
|
||||
setUpdateBaseInfo(tableName, params);
|
||||
params.put("uuidValue", UUIDUtil.getUUID());
|
||||
params.put("insertFieldList", insertFieldList);
|
||||
params.put("insertValueList", insertValueList);
|
||||
@ -67,6 +66,141 @@ public class DynamicDataServiceImpl extends AbstractService implements IDynamicD
|
||||
return new SuccessResult();
|
||||
}
|
||||
|
||||
@Override
|
||||
public SuccessResult removeDynamicData(String tableName, String ids) throws RemoveException {
|
||||
Map<String, Object> params = getHashMap(7);
|
||||
setUpdateBaseInfo(tableName, params);
|
||||
params.put("idArray", Arrays.asList(ids.split("_")));
|
||||
setUpdateInfo(params);
|
||||
dynamicDataDao.removeDynamicData(params);
|
||||
return new SuccessResult();
|
||||
}
|
||||
|
||||
@Override
|
||||
public SuccessResult updateDynamicData(String tableName, String id, Map<String, Object> params) throws UpdateException {
|
||||
List<DynamicFormDTO> dynamicFormDTOs = dynamicFormService.listDynamicForm(tableName);
|
||||
LOG.debug("校验参数");
|
||||
requireData(params, dynamicFormDTOs);
|
||||
LOG.debug("获取修改键值");
|
||||
List<KeyValue> updateFieldValueList = new ArrayList<>();
|
||||
for (DynamicFormDTO dynamicFormDTO : dynamicFormDTOs) {
|
||||
updateFieldValueList.add(new DefaultKeyValue(WStringUtil.lowerUpper2UnderLine(dynamicFormDTO.getFieldName()), params.get(dynamicFormDTO.getFieldName())));
|
||||
}
|
||||
params.clear();
|
||||
setUpdateBaseInfo(tableName, params);
|
||||
params.put("uuidValue", id);
|
||||
params.put("updateFieldValueList", updateFieldValueList);
|
||||
setUpdateInfo(params);
|
||||
dynamicDataDao.updateDynamicData(params);
|
||||
return new SuccessResult();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Map<String, Object>> listDynamicData(String tableName, Map<String, Object> params) {
|
||||
setSearchBaseListInfo(tableName, params);
|
||||
List<Map<String, Object>> listDynamicData = dynamicDataDao.listDynamicData(params);
|
||||
resetDynamicDataKey2LowerUpper(listDynamicData);
|
||||
return listDynamicData;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SuccessResultList<List<Map<String, Object>>> listPageDynamicData(String tableName, ListPage listPage) throws SearchException {
|
||||
setSearchBaseListInfo(tableName, listPage.getParams());
|
||||
PageHelper.startPage(listPage.getPage(), listPage.getRows());
|
||||
List<Map<String, Object>> listDynamicData = dynamicDataDao.listDynamicData(listPage.getParams());
|
||||
resetDynamicDataKey2LowerUpper(listDynamicData);
|
||||
PageInfo<Map<String, Object>> pageInfo = new PageInfo<>(listDynamicData);
|
||||
return new SuccessResultList<>(listDynamicData, pageInfo.getPageNum(), pageInfo.getTotal());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> getDynamicData(String tableName, String id) throws SearchException {
|
||||
Map<String, Object> params = getHashMap(0);
|
||||
setSearchBaseGetInfo(tableName, params);
|
||||
params.put("uuidValue", id);
|
||||
Map<String, Object> dynamicData = dynamicDataDao.getDynamicData(params);
|
||||
resetDynamicDataKey2LowerUpper(dynamicData);
|
||||
return dynamicData;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置查询列表基础信息
|
||||
*
|
||||
* @param tableName
|
||||
* @param params
|
||||
*/
|
||||
private void setSearchBaseListInfo(String tableName, Map<String, Object> params) {
|
||||
List<String> listShowFieldList = dynamicFormService.listListShowField(tableName);
|
||||
params.put("listShowFieldList", listShowFieldList);
|
||||
setSearchBaseInfo(tableName, params);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置查询详情基础信息
|
||||
*
|
||||
* @param tableName
|
||||
* @param params
|
||||
*/
|
||||
private void setSearchBaseGetInfo(String tableName, Map<String, Object> params) {
|
||||
List<String> formShowFieldList = dynamicFormService.listFormShowField(tableName);
|
||||
params.put("formShowFieldList", formShowFieldList);
|
||||
setSearchBaseInfo(tableName, params);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置查询基础信息
|
||||
*
|
||||
* @param tableName
|
||||
* @param params
|
||||
*/
|
||||
private void setSearchBaseInfo(String tableName, Map<String, Object> params) {
|
||||
String lowerUnderLineTableName = WStringUtil.lowerUpper2UnderLine(tableName);
|
||||
params.put("tableName", String.format("%s%s", IDynamicTableService.DYNAMIC_TABLE_PREFIX, lowerUnderLineTableName));
|
||||
params.put("uuidField", String.format("%s_id", lowerUnderLineTableName));
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置更新基础信息
|
||||
*
|
||||
* @param tableName
|
||||
* @param params
|
||||
*/
|
||||
private void setUpdateBaseInfo(String tableName, Map<String, Object> params) {
|
||||
String lowerUnderLineTableName = WStringUtil.lowerUpper2UnderLine(tableName);
|
||||
params.put("tableName", String.format("%s%s", IDynamicTableService.DYNAMIC_TABLE_PREFIX, lowerUnderLineTableName));
|
||||
params.put("uuidField", String.format("%s_id", lowerUnderLineTableName));
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置表字段为驼峰式
|
||||
*
|
||||
* @param listDynamicData
|
||||
*/
|
||||
private void resetDynamicDataKey2LowerUpper(List<Map<String, Object>> listDynamicData) {
|
||||
for (Map<String, Object> dynamicData : listDynamicData) {
|
||||
resetDynamicDataKey2LowerUpper(dynamicData);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置表字段为驼峰式
|
||||
*
|
||||
* @param dynamicData
|
||||
*/
|
||||
private void resetDynamicDataKey2LowerUpper(Map<String, Object> dynamicData) {
|
||||
List<String> keyList = new ArrayList<>();
|
||||
for (Map.Entry<String, Object> keyValue : dynamicData.entrySet()) {
|
||||
keyList.add(keyValue.getKey());
|
||||
}
|
||||
for (String key : keyList) {
|
||||
String newKey = WStringUtil.underLine2LowerUpper(key);
|
||||
if (!StringUtils.equals(key, newKey)) {
|
||||
dynamicData.put(WStringUtil.underLine2LowerUpper(key), dynamicData.get(key));
|
||||
dynamicData.remove(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证数据
|
||||
*
|
||||
|
@ -64,6 +64,30 @@ public class DynamicFormServiceImpl extends AbstractService implements IDynamicF
|
||||
return dynamicFormDao.listDynamicForm(tableName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> listListShowField(String tableName) throws SearchException {
|
||||
List<DynamicFormDTO> dynamicFormDTOs = listDynamicForm(tableName);
|
||||
List<String> listShowField = new ArrayList<>();
|
||||
for (DynamicFormDTO dynamicFormDTO : dynamicFormDTOs) {
|
||||
if (dynamicFormDTO.getListShow() == 1) {
|
||||
listShowField.add(WStringUtil.lowerUpper2UnderLine(dynamicFormDTO.getFieldName()));
|
||||
}
|
||||
}
|
||||
return listShowField;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> listFormShowField(String tableName) throws SearchException {
|
||||
List<DynamicFormDTO> dynamicFormDTOs = listDynamicForm(tableName);
|
||||
List<String> listShowField = new ArrayList<>();
|
||||
for (DynamicFormDTO dynamicFormDTO : dynamicFormDTOs) {
|
||||
if (dynamicFormDTO.getFormShow() == 1) {
|
||||
listShowField.add(WStringUtil.lowerUpper2UnderLine(dynamicFormDTO.getFieldName()));
|
||||
}
|
||||
}
|
||||
return listShowField;
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存动态表单信息
|
||||
*
|
||||
|
@ -27,4 +27,63 @@
|
||||
)
|
||||
</insert>
|
||||
|
||||
<!-- 删除动态数据 -->
|
||||
<update id="removeDynamicData" parameterType="map">
|
||||
UPDATE
|
||||
${tableName}
|
||||
SET
|
||||
is_delete = 1,
|
||||
modifier = #{modifier},
|
||||
gmt_modified = #{gmtModified}
|
||||
WHERE
|
||||
${uuidField} IN
|
||||
<foreach collection="idArray" index="index" open="(" separator="," close=")">
|
||||
#{idArray[${index}]}
|
||||
</foreach>
|
||||
</update>
|
||||
|
||||
<!-- 修改动态数据 -->
|
||||
<update id="updateDynamicData" parameterType="map">
|
||||
UPDATE
|
||||
${tableName}
|
||||
SET
|
||||
<foreach collection="updateFieldValueList" item="item">
|
||||
<if test="item.value != null">
|
||||
${item.key} = #{item.value},
|
||||
</if>
|
||||
</foreach>
|
||||
modifier = #{modifier},
|
||||
gmt_modified = #{gmtModified}
|
||||
WHERE
|
||||
${uuidField} = #{uuidValue}
|
||||
</update>
|
||||
|
||||
<!-- 动态数据列表 -->
|
||||
<select id="listDynamicData" parameterType="map" resultType="map">
|
||||
SELECT
|
||||
${uuidField},
|
||||
<foreach collection="listShowFieldList" item="item" separator=",">
|
||||
${item}
|
||||
</foreach>
|
||||
FROM
|
||||
${tableName}
|
||||
WHERE
|
||||
is_delete = 0
|
||||
</select>
|
||||
|
||||
<!-- 动态数据详情 -->
|
||||
<select id="getDynamicData" parameterType="map" resultType="map">
|
||||
SELECT
|
||||
${uuidField},
|
||||
<foreach collection="formShowFieldList" item="item" separator=",">
|
||||
${item}
|
||||
</foreach>
|
||||
FROM
|
||||
${tableName}
|
||||
WHERE
|
||||
is_delete = 0
|
||||
AND
|
||||
${uuidField} = #{uuidValue}
|
||||
</select>
|
||||
|
||||
</mapper>
|
@ -0,0 +1,246 @@
|
||||
<!doctype html>
|
||||
<html lang="en" xmlns:th="http://www.thymeleaf.org">
|
||||
<head>
|
||||
<base th:href="${#httpServletRequest.getScheme() + '://' + #httpServletRequest.getServerName() + ':' + #request.getServerPort() + #request.getContextPath() + '/'} ">
|
||||
<meta charset="utf-8">
|
||||
<meta name="renderer" content="webkit">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
|
||||
<link rel="stylesheet" href="assets/fonts/font-awesome/css/font-awesome.css"/>
|
||||
<link rel="stylesheet" href="assets/layuiadmin/layui/css/layui.css" media="all">
|
||||
<link rel="stylesheet" href="assets/layuiadmin/style/admin.css" media="all">
|
||||
</head>
|
||||
<body>
|
||||
<div class="layui-fluid layui-anim layui-anim-fadein">
|
||||
<div class="layui-row layui-col-space15">
|
||||
<div class="layui-col-md12">
|
||||
<div class="layui-card">
|
||||
<div class="layui-card-body">
|
||||
<div class="test-table-reload-btn" style="margin-bottom: 10px;">
|
||||
<div class="layui-inline">
|
||||
<input type="text" id="keywords" class="layui-input search-item" placeholder="输入关键字">
|
||||
</div>
|
||||
<div class="layui-inline">
|
||||
<input type="text" id="startTime" class="layui-input search-item" placeholder="开始时间" readonly>
|
||||
</div>
|
||||
<div class="layui-inline">
|
||||
<input type="text" id="endTime" class="layui-input search-item" placeholder="结束时间" readonly>
|
||||
</div>
|
||||
<button type="button" id="search" class="layui-btn layui-btn-sm">
|
||||
<i class="fa fa-lg fa-search"></i> 搜索
|
||||
</button>
|
||||
</div>
|
||||
<table class="layui-hide" id="dataTable" lay-filter="dataTable"></table>
|
||||
<!-- 表头按钮组 -->
|
||||
<script type="text/html" id="headerToolBar">
|
||||
<div class="layui-btn-group">
|
||||
<button type="button" class="layui-btn layui-btn-sm" lay-event="saveEvent">
|
||||
<i class="fa fa-lg fa-plus"></i> 新增
|
||||
</button>
|
||||
<button type="button" class="layui-btn layui-btn-normal layui-btn-sm" lay-event="updateEvent">
|
||||
<i class="fa fa-lg fa-edit"></i> 编辑
|
||||
</button>
|
||||
<button type="button" class="layui-btn layui-btn-danger layui-btn-sm" lay-event="removeEvent">
|
||||
<i class="fa fa-lg fa-trash"></i> 删除
|
||||
</button>
|
||||
</div>
|
||||
</script>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<input type="hidden" id="tableName" th:value="${tableName}"/>
|
||||
<input type="hidden" id="uuidField" th:value="${uuidField}"/>
|
||||
<script src="assets/layuiadmin/layui/layui.js"></script>
|
||||
<script src="assets/js/vendor/viewer/viewer.min.js"></script>
|
||||
<script>
|
||||
layui.config({
|
||||
base: 'assets/layuiadmin/'
|
||||
}).extend({
|
||||
index: 'lib/index'
|
||||
}).use(['index', 'table', 'laydate'], function() {
|
||||
var $ = layui.$;
|
||||
var $win = $(window);
|
||||
var table = layui.table;
|
||||
var admin = layui.admin;
|
||||
var laydate = layui.laydate;
|
||||
var resizeTimeout = null;
|
||||
|
||||
// 初始化表格
|
||||
function initTable() {
|
||||
top.restAjax.get(top.restAjax.path('api/dynamicform/listlistshowfield/{tableName}', [$('#tableName').val()]), {}, null, function(code, data) {
|
||||
var autoCols = [
|
||||
{type:'checkbox', fixed: 'left'},
|
||||
{field:'rowNum', width:80, title: '序号', fixed: 'left', align:'center'}
|
||||
];
|
||||
table.render({
|
||||
elem: '#dataTable',
|
||||
id: 'dataTable',
|
||||
url: top.restAjax.path('api/user/listpageusers', []),
|
||||
width: admin.screen() > 1 ? '100%' : '',
|
||||
height: $win.height() - 90,
|
||||
limit: 20,
|
||||
limits: [20, 40, 60, 80, 100, 200],
|
||||
toolbar: '#headerToolBar',
|
||||
request: {
|
||||
pageName: 'page',
|
||||
limitName: 'rows'
|
||||
},
|
||||
cols: [
|
||||
[
|
||||
|
||||
]
|
||||
],
|
||||
page: true,
|
||||
parseData: function(data) {
|
||||
return {
|
||||
'code': 0,
|
||||
'msg': '',
|
||||
'count': data.total,
|
||||
'data': data.rows
|
||||
};
|
||||
}
|
||||
});
|
||||
}, function(code, data) {
|
||||
top.dialog.msg(data.msg);
|
||||
});
|
||||
}
|
||||
// 重载表格
|
||||
function reloadTable() {
|
||||
table.reload('dataTable', {
|
||||
url: top.restAjax.path('api/user/listpageusers', []),
|
||||
where: {
|
||||
keywords: $('#keywords').val(),
|
||||
startTime: $('#startTime').val(),
|
||||
endTime: $('#endTime').val()
|
||||
},
|
||||
height: $win.height() - 90,
|
||||
});
|
||||
}
|
||||
// 初始化日期
|
||||
function initDate() {
|
||||
// 日期选择
|
||||
laydate.render({
|
||||
elem: '#startTime',
|
||||
format: 'yyyy-MM-dd'
|
||||
});
|
||||
laydate.render({
|
||||
elem: '#endTime',
|
||||
format: 'yyyy-MM-dd'
|
||||
});
|
||||
}
|
||||
// 删除
|
||||
function removeData(ids) {
|
||||
top.dialog.msg(top.dataMessage.delete, {
|
||||
time: 0,
|
||||
btn: [top.dataMessage.button.yes, top.dataMessage.button.no],
|
||||
shade: 0.3,
|
||||
yes: function (index) {
|
||||
top.dialog.close(index);
|
||||
var layIndex;
|
||||
top.restAjax.delete(top.restAjax.path('api/user/removeuser/{ids}', [ids]), {}, null, function (code, data) {
|
||||
top.dialog.msg(top.dataMessage.deleteSuccess, {time: 1000}, function () {
|
||||
reloadTable();
|
||||
});
|
||||
}, function (code, data) {
|
||||
top.dialog.msg(data.msg);
|
||||
}, function () {
|
||||
layIndex = top.dialog.msg(top.dataMessage.deleting, {icon: 16, time: 0, shade: 0.3});
|
||||
}, function () {
|
||||
top.dialog.close(layIndex);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
initTable();
|
||||
initDate();
|
||||
// 事件 - 页面变化
|
||||
$win.on('resize', function() {
|
||||
clearTimeout(resizeTimeout);
|
||||
resizeTimeout = setTimeout(function() {
|
||||
reloadTable();
|
||||
}, 500);
|
||||
});
|
||||
// 事件 - 搜索
|
||||
$(document).on('click', '#search', function() {
|
||||
reloadTable();
|
||||
});
|
||||
// 事件 - 增删改
|
||||
table.on('toolbar(dataTable)', function(obj) {
|
||||
var layEvent = obj.event;
|
||||
var checkStatus = table.checkStatus('dataTable');
|
||||
var checkDatas = checkStatus.data;
|
||||
if(layEvent === 'saveEvent') {
|
||||
layer.open({
|
||||
type: 2,
|
||||
title: false,
|
||||
closeBtn: 0,
|
||||
area: ['100%', '100%'],
|
||||
shadeClose: true,
|
||||
anim: 2,
|
||||
content: top.restAjax.path('route/system/user/save.html', []),
|
||||
end: function() {
|
||||
reloadTable();
|
||||
}
|
||||
});
|
||||
} else if(layEvent === 'updateEvent') {
|
||||
if(checkDatas.length === 0) {
|
||||
top.dialog.msg(top.dataMessage.table.selectEdit);
|
||||
} else if(checkDatas.length > 1) {
|
||||
top.dialog.msg(top.dataMessage.table.selectOneEdit);
|
||||
} else {
|
||||
layer.open({
|
||||
type: 2,
|
||||
title: false,
|
||||
closeBtn: 0,
|
||||
area: ['100%', '100%'],
|
||||
shadeClose: true,
|
||||
anim: 2,
|
||||
content: top.restAjax.path('route/system/user/update.html?userId={id}', [checkDatas[0].userId]),
|
||||
end: function() {
|
||||
reloadTable();
|
||||
}
|
||||
});
|
||||
}
|
||||
} else if(layEvent === 'removeEvent') {
|
||||
if(checkDatas.length === 0) {
|
||||
top.dialog.msg(top.dataMessage.table.selectDelete);
|
||||
} else {
|
||||
var ids = '';
|
||||
for(var i = 0, item; item = checkDatas[i++];) {
|
||||
if(i > 1) {
|
||||
ids += '_';
|
||||
}
|
||||
ids += item.userId;
|
||||
}
|
||||
removeData(ids);
|
||||
}
|
||||
}
|
||||
});
|
||||
table.on('tool(dataTable)', function(obj) {
|
||||
var layEvent = obj.event;
|
||||
var data = obj.data;
|
||||
if(layEvent === 'userDeviceEvent') {
|
||||
top.dialog.open({
|
||||
url: top.restAjax.path('route/system/user/list-device.html?userId={userId}', [data.userId]),
|
||||
title: '设备列表',
|
||||
width: '300px',
|
||||
height: '150px'
|
||||
});
|
||||
}
|
||||
});
|
||||
// 事件-排序
|
||||
table.on('sort(dataTable)', function(obj) {
|
||||
table.reload('dataTable', {
|
||||
initSort: obj,
|
||||
where: {
|
||||
sort: obj.field,
|
||||
order: obj.type
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
@ -167,9 +167,13 @@ public class WStringUtil {
|
||||
if (letter.length() == 0) {
|
||||
continue;
|
||||
}
|
||||
int firstLetter = letter.charAt(0);
|
||||
firstLetter -= 32;
|
||||
sb.append((char) firstLetter).append(letter.substring(1, letter.length()));
|
||||
if(i == 0) {
|
||||
sb.append(letter);
|
||||
} else {
|
||||
int firstLetter = letter.charAt(0);
|
||||
firstLetter -= 32;
|
||||
sb.append((char) firstLetter).append(letter.substring(1));
|
||||
}
|
||||
}
|
||||
if (sb.length() > 0) {
|
||||
return sb.toString();
|
||||
|
Loading…
Reference in New Issue
Block a user