完善主数据添加,数据回显功能
parent
041698b659
commit
1ef4975539
|
@ -128,9 +128,17 @@ public class SpTableManagerController extends BaseController {
|
|||
if (CollectionUtil.isEmpty(spTableManagerItems)) {
|
||||
Result.failure("显示的,详细的字段不可以为空");
|
||||
} else {
|
||||
iSpTableManagerService.saveOrUpdate(spTableManager);
|
||||
//先删除已有的数据,然后插入
|
||||
if (StringUtils.isNotEmpty(record.getId())) {
|
||||
iSpTableManagerItemService.deleteItemBytableNameId(record.getId());
|
||||
} else {
|
||||
for (SpTableManagerItem spTableManagerItem : spTableManagerItems) {
|
||||
spTableManagerItem.setTableNameId(spTableManager.getId());
|
||||
}
|
||||
}
|
||||
iSpTableManagerItemService.saveOrUpdateBatch(spTableManagerItems);
|
||||
}
|
||||
iSpTableManagerService.saveOrUpdate(spTableManager);
|
||||
return Result.success(record.getId());
|
||||
}
|
||||
|
||||
|
|
|
@ -1,21 +1,54 @@
|
|||
package com.songpeng.sparchetype.basedata.controller;
|
||||
|
||||
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import com.songpeng.sparchetype.basedata.entity.SpTableManagerItem;
|
||||
import com.songpeng.sparchetype.basedata.service.ISpTableManagerItemService;
|
||||
import com.songpeng.sparchetype.common.BaseController;
|
||||
import com.songpeng.sparchetype.common.Result;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiImplicitParams;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 前端控制器
|
||||
* 前端控制器
|
||||
* </p>
|
||||
*
|
||||
* @author WangZiYang
|
||||
* @since 2020-03-06
|
||||
*/
|
||||
@Controller
|
||||
@RequestMapping("/basedata/sp-table-manager-item")
|
||||
@RequestMapping("/basedata/manager/item")
|
||||
public class SpTableManagerItemController extends BaseController {
|
||||
|
||||
|
||||
/**
|
||||
* 业务表字段明细
|
||||
*/
|
||||
@Autowired
|
||||
private ISpTableManagerItemService iSpTableManagerItemService;
|
||||
|
||||
/**
|
||||
* 根据表名称查询该表的全部字段数据库明细
|
||||
*
|
||||
* @param tableNameId 主表ID
|
||||
* @return Result 执行结果
|
||||
*/
|
||||
@ApiOperation("根据表名称查询该表的全部字段数据库明细")
|
||||
@ApiImplicitParams({@ApiImplicitParam(name = "tableNameId", value = "主表ID", defaultValue = "请求参数")})
|
||||
@PostMapping("/by/tableNameId")
|
||||
@ResponseBody
|
||||
public Result queryTableFieldByName(@RequestParam(value = "tableNameId") String tableNameId) throws Exception {
|
||||
List<SpTableManagerItem> result = iSpTableManagerItemService.queryItemBytableNameId(tableNameId);
|
||||
return Result.success(result);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,16 +1,32 @@
|
|||
package com.songpeng.sparchetype.basedata.mapper;
|
||||
|
||||
import com.songpeng.sparchetype.basedata.entity.SpTableManagerItem;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.songpeng.sparchetype.basedata.entity.SpTableManagerItem;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Mapper 接口
|
||||
* Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author WangZiYang
|
||||
* @since 2020-03-06
|
||||
*/
|
||||
public interface SpTableManagerItemMapper extends BaseMapper<SpTableManagerItem> {
|
||||
/**
|
||||
* 根据主表ID 查询该表的明细
|
||||
*
|
||||
* @param tableNameId 关联主表ID
|
||||
* @return 表字段明细
|
||||
*/
|
||||
List<SpTableManagerItem> queryItemBytableNameId(@Param("tableNameId") String tableNameId);
|
||||
|
||||
/**
|
||||
* 根据主表ID 删除明细
|
||||
*
|
||||
* @param tableNameId 关联主表ID
|
||||
*/
|
||||
void deleteItemBytableNameId(@Param("tableNameId") String tableNameId);
|
||||
}
|
||||
|
|
|
@ -15,6 +15,11 @@ import java.util.List;
|
|||
* @since 2020-03-06
|
||||
*/
|
||||
public interface SpTableManagerMapper extends BaseMapper<SpTableManager> {
|
||||
/**
|
||||
* 查询表对应的字段
|
||||
*
|
||||
* @param req 表信息
|
||||
* @return 字段信息
|
||||
*/
|
||||
List<SpTableManagerItem> queryTableFieldByName(SpTableManager req);
|
||||
|
||||
}
|
||||
|
|
|
@ -1,16 +1,33 @@
|
|||
package com.songpeng.sparchetype.basedata.service;
|
||||
|
||||
import com.songpeng.sparchetype.basedata.entity.SpTableManagerItem;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.songpeng.sparchetype.basedata.entity.SpTableManagerItem;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 服务类
|
||||
* 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author WangZiYang
|
||||
* @since 2020-03-06
|
||||
*/
|
||||
public interface ISpTableManagerItemService extends IService<SpTableManagerItem> {
|
||||
/**
|
||||
* 根据主表ID 查询该表的明细
|
||||
*
|
||||
* @param tableNameId 关联主表ID
|
||||
* @return 表字段明细
|
||||
*/
|
||||
List<SpTableManagerItem> queryItemBytableNameId(String tableNameId);
|
||||
|
||||
/**
|
||||
* 根据主表ID 删除明细
|
||||
*
|
||||
* @param tableNameId 关联主表ID
|
||||
*/
|
||||
void deleteItemBytableNameId(String tableNameId);
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package com.songpeng.sparchetype.basedata.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.songpeng.sparchetype.basedata.dto.SpTableManagerDto;
|
||||
import com.songpeng.sparchetype.basedata.entity.SpTableManager;
|
||||
import com.songpeng.sparchetype.basedata.entity.SpTableManagerItem;
|
||||
|
||||
|
|
|
@ -1,14 +1,17 @@
|
|||
package com.songpeng.sparchetype.basedata.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.songpeng.sparchetype.basedata.entity.SpTableManagerItem;
|
||||
import com.songpeng.sparchetype.basedata.mapper.SpTableManagerItemMapper;
|
||||
import com.songpeng.sparchetype.basedata.service.ISpTableManagerItemService;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 服务实现类
|
||||
* 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author WangZiYang
|
||||
|
@ -16,5 +19,31 @@ import org.springframework.stereotype.Service;
|
|||
*/
|
||||
@Service
|
||||
public class SpTableManagerItemServiceImpl extends ServiceImpl<SpTableManagerItemMapper, SpTableManagerItem> implements ISpTableManagerItemService {
|
||||
/**
|
||||
* 表明细mapper
|
||||
*/
|
||||
@Autowired
|
||||
public SpTableManagerItemMapper spTableManagerItemMapper;
|
||||
|
||||
/**
|
||||
* 根据主表ID 查询该表的明细
|
||||
*
|
||||
* @param tableNameId 关联主表ID
|
||||
* @return 表字段明细
|
||||
*/
|
||||
@Override
|
||||
public List<SpTableManagerItem> queryItemBytableNameId(String tableNameId) {
|
||||
return spTableManagerItemMapper.queryItemBytableNameId(tableNameId);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 根据主表ID 删除明细
|
||||
*
|
||||
* @param tableNameId 关联主表ID
|
||||
*/
|
||||
@Override
|
||||
public void deleteItemBytableNameId(String tableNameId) {
|
||||
spTableManagerItemMapper.deleteItemBytableNameId(tableNameId);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ import com.songpeng.sparchetype.basedata.entity.SpTableManager;
|
|||
import com.songpeng.sparchetype.basedata.entity.SpTableManagerItem;
|
||||
import com.songpeng.sparchetype.basedata.mapper.SpTableManagerMapper;
|
||||
import com.songpeng.sparchetype.basedata.service.ISpTableManagerService;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
|
@ -21,10 +22,18 @@ import java.util.List;
|
|||
*/
|
||||
@Service
|
||||
public class SpTableManagerServiceImpl extends ServiceImpl<SpTableManagerMapper, SpTableManager> implements ISpTableManagerService {
|
||||
|
||||
/**
|
||||
* 基础管理表mapper
|
||||
*/
|
||||
@Autowired
|
||||
private SpTableManagerMapper spTableManagerMapper;
|
||||
|
||||
/**
|
||||
* 查询表对应的字段
|
||||
*
|
||||
* @param req 表信息
|
||||
* @return 字段信息
|
||||
*/
|
||||
@Override
|
||||
public List<SpTableManagerItem> queryTableFieldByName(SpTableManager req) throws Exception {
|
||||
List<SpTableManagerItem> spTableManagerItems = spTableManagerMapper.queryTableFieldByName(req);
|
||||
|
@ -33,4 +42,6 @@ public class SpTableManagerServiceImpl extends ServiceImpl<SpTableManagerMapper,
|
|||
}
|
||||
return spTableManagerItems;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,31 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.songpeng.sparchetype.basedata.mapper.SpTableManagerItemMapper">
|
||||
<resultMap id="BaseResultMap" type="com.songpeng.sparchetype.basedata.entity.SpTableManagerItem">
|
||||
<id column="ID" property="id" jdbcType="VARCHAR"/>
|
||||
<result column="FIELD" property="field" jdbcType="VARCHAR"/>
|
||||
<result column="field_desc" property="fieldDesc" jdbcType="VARCHAR"/>
|
||||
<result column="must_fill" property="mustFill" jdbcType="VARCHAR"/>
|
||||
</resultMap>
|
||||
|
||||
<!--查询编码规则明细分页信息-->
|
||||
<select id="queryItemBytableNameId" parameterType="string"
|
||||
resultMap="BaseResultMap">
|
||||
SELECT
|
||||
t.id,
|
||||
t.FIELD,
|
||||
t.field_desc,
|
||||
t.must_fill
|
||||
FROM
|
||||
sp_table_manager_item t
|
||||
<where>
|
||||
t.table_name_id = #{tableNameId}
|
||||
</where>
|
||||
ORDER BY sort_num
|
||||
</select>
|
||||
|
||||
<delete id="deleteItemBytableNameId" parameterType="string">
|
||||
DELETE FROM sp_table_manager_item WHERE table_name_id = #{tableNameId}
|
||||
</delete>
|
||||
|
||||
</mapper>
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
|
||||
<div class="layui-form-item">
|
||||
<div class="layui-input-inline layui-hide">
|
||||
<input type="text" id="js-table-id" lay-verify="required" autocomplete="off"
|
||||
<input type="text" id="js-table-id" autocomplete="off"
|
||||
class="layui-input" value="${result.id}">
|
||||
</div>
|
||||
</div>
|
||||
|
@ -125,7 +125,7 @@
|
|||
<script id="js-rule-detail-item-tpl" type="text/html">
|
||||
<label class="layui-form-label layui-form-label-per" style="width: 60px;">是否必填</label>
|
||||
<div class="layui-input-inline" style="width: 80px;margin-right: 2px;">
|
||||
<select id="js-must-fill-{{d.id}}" lay-verify="required">
|
||||
<select id="js-must-fill-{{d.id}}" lay-verify="required">
|
||||
<option value="">请选择</option>
|
||||
<option value="Y">是</option>
|
||||
<option value="N">否</option>
|
||||
|
@ -140,7 +140,11 @@
|
|||
ruleDetailTplDataCopy = {},
|
||||
ruleDetailTplData = {},
|
||||
ruleItemIdArr = [];
|
||||
|
||||
//数据回显操作 存在主表ID时候,重新绘制
|
||||
if ($('#js-table-id').val()) {
|
||||
ruleDetailTplData.ruleItems = ruleDetailTplData.ruleItems ? ruleDetailTplData.ruleItems : addBindData();
|
||||
ruleDetailRow();
|
||||
}
|
||||
//失去焦点时判断值为空不验证,一旦填写必须验证
|
||||
$('input[name="email"]').blur(function () {
|
||||
//这里是失去焦点时的事件
|
||||
|
@ -164,7 +168,6 @@
|
|||
tableNameId: $('#js-table-id').val()
|
||||
});
|
||||
});
|
||||
console.log(requestParmaArr);
|
||||
data.field.spTableManagerItems = requestParmaArr;
|
||||
spUtil.submitForm({
|
||||
contentType: 'application/json',
|
||||
|
@ -189,13 +192,13 @@
|
|||
if (!ruleDetailTplData.ruleItems) {
|
||||
return;
|
||||
}
|
||||
distinctSelect();
|
||||
// distinctSelect();
|
||||
addRuleDetail();
|
||||
updItemCount();
|
||||
});
|
||||
|
||||
/**
|
||||
*初始化表数据
|
||||
*初始化表信息数据
|
||||
*/
|
||||
function addBindData() {
|
||||
var ajaxResult;
|
||||
|
@ -298,6 +301,44 @@
|
|||
function updItemCount() {
|
||||
$('#js-item-count').html(ruleItemIdArr.length);
|
||||
}
|
||||
|
||||
function ruleDetailRow() {
|
||||
// layer.load() 在使用异步请求时起效,如:ajax异步请求、定时器,
|
||||
// 但是用ES6的promise不生效,所以此处采用定时器实现
|
||||
window.setTimeout(function () {
|
||||
var ruleDetailRows;
|
||||
spUtil.ajax({
|
||||
url: '${request.contextPath}/basedata/manager/item/by/tableNameId',
|
||||
async: false,
|
||||
type: 'POST',
|
||||
// 是否显示 loading
|
||||
showLoading: true,
|
||||
// 是否序列化参数
|
||||
serializable: false,
|
||||
// 参数
|
||||
data: {
|
||||
tableNameId: $('#js-table-id').val()
|
||||
},
|
||||
success: function (data) {
|
||||
ruleDetailRows = data.data;
|
||||
}
|
||||
});
|
||||
//打码规则项渲染赋值
|
||||
console.log(ruleDetailRows);
|
||||
$.each(ruleDetailRows, function (index, item) {
|
||||
var inputId = addRuleDetail();
|
||||
//必填项
|
||||
$('#js-must-fill-' + inputId).val(item.mustFill);
|
||||
//字段名称
|
||||
console.log(item.field);
|
||||
$('#js-rule-item-type-' + inputId).val(item.field);
|
||||
//字段详细名称
|
||||
$('#js-field-desc-' + inputId).val(item.fieldDesc);
|
||||
});
|
||||
form.render();
|
||||
updItemCount();
|
||||
}, 100);
|
||||
}
|
||||
});
|
||||
|
||||
</script>
|
||||
|
|
Loading…
Reference in New Issue