完善主数据添加,数据回显功能

pull/1/head
wangziyangyang 2020-03-10 14:41:07 +08:00
parent 041698b659
commit 1ef4975539
10 changed files with 206 additions and 21 deletions

View File

@ -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());
}

View File

@ -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);
}
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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;

View File

@ -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);
}
}

View File

@ -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;
}
}

View File

@ -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>

View File

@ -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>