!49 去除外键

Merge pull request !49 from 乾坤平台/master
This commit is contained in:
乾坤平台
2019-04-11 21:53:02 +08:00
committed by 季圣华
12 changed files with 322 additions and 16 deletions

View File

@@ -206,7 +206,17 @@
if(res && res.code == 200) {
$("#searchBtn").click();
} else {
$.messager.alert('删除提示', '删除计量单位失败,请稍后再试!', 'error');
if(res && res.code == 601){
var jsondata={};
jsondata.ids=unitID;
jsondata.deleteType='2';
var type='single';
batDeleteUnitForceConfirm(res,"/unit/batchDeleteUnitByIds",jsondata,type);
}else if(res && res.code == 600){
$.messager.alert('删除提示', res.msg, 'error');
}else{
$.messager.alert('删除提示', '删除计量单位异常,请稍后再试!', 'error');
}
}
},
//此处添加错误处理
@@ -251,7 +261,17 @@
$("#searchBtn").click();
$(":checkbox").attr("checked", false);
} else {
$.messager.alert('删除提示', '删除计量单位失败,请稍后再试!', 'error');
if(res && res.code == 601){
var jsondata={};
jsondata.ids=ids;
jsondata.deleteType='2';
var type='batch';
batDeleteUnitForceConfirm(res,"/unit/batchDeleteUnitByIds",jsondata,type);
}else if(res && res.code == 600){
$.messager.alert('删除提示', res.msg, 'error');
}else{
$.messager.alert('删除提示', '删除计量单位异常,请稍后再试!', 'error');
}
}
},
//此处添加错误处理
@@ -264,6 +284,38 @@
});
}
}
/**
* 确认强制删除
* */
function batDeleteUnitForceConfirm(res,url,jsondata,type) {
$.messager.confirm('删除确认', res.msg, function (r) {
if (r) {
$.ajax({
type: "post",
url: url,
dataType: "json",
data: (jsondata),
success: function (res) {
if(res && res.code == 200) {
$("#searchBtn").click();
if(type=='batch'){
$(":checkbox").attr("checked", false);
}
}else if(res && res.code == 600){
$.messager.alert('删除提示', res.msg, 'error');
}else {
$.messager.alert('删除提示', '删除计量单位异常,请稍后再试!', 'error');
}
},
//此处添加错误处理
error: function () {
$.messager.alert('删除提示', '删除计量单位异常,请稍后再试!', 'error');
return;
}
});
}
});
}
//增加
var url;

View File

@@ -196,11 +196,21 @@
ids: ids
}),
success: function (res) {
if(res.code!=200){
$.messager.alert('提示', res.msg, 'error');
return;
if(res && res.code === 200) {
$('#tt').tree('reload');
} else {
if(res && res.code == 601){
var jsondata={};
jsondata.ids=ids;
jsondata.deleteType='2';
var type='batch';
batDeleteMaterialCategoryForceConfirm(res,"/materialCategory/batchDeleteMaterialCategory",jsondata,type);
}else if(res && res.code == 600){
$.messager.alert('删除提示', res.msg, 'error');
}else{
$.messager.alert('删除提示', '删除商品信息异常,请稍后再试!', 'error');
}
}
$('#tt').tree('reload');
},
//此处添加错误处理
error: function () {
@@ -212,6 +222,35 @@
});
}
}
/**
* 确认强制删除
* */
function batDeleteMaterialCategoryForceConfirm(res,url,jsondata,type) {
$.messager.confirm('删除确认', res.msg, function (r) {
if (r) {
$.ajax({
type: "post",
url: url,
dataType: "json",
data: (jsondata),
success: function (res) {
if(res && res.code == 200) {
$('#tt').tree('reload');
}else if(res && res.code == 600){
$.messager.alert('删除提示', res.msg, 'error');
}else {
$.messager.alert('删除提示', '删除商品类别信息异常,请稍后再试!', 'error');
}
},
//此处添加错误处理
error: function () {
$.messager.alert('删除提示', '删除商品类别信息异常,请稍后再试!', 'error');
return;
}
});
}
});
}
//保存信息
$("#saveMaterialCategory").off("click").on("click", function () {

View File

@@ -1549,4 +1549,60 @@ alter table jsh_depothead add delete_Flag varchar(1) DEFAULT '0' COMMENT '删
-- 单据子表 jsh_depotitem
alter table jsh_depotitem add delete_Flag varchar(1) DEFAULT '0' COMMENT '删除标记0未删除1删除';
-- 收支项目表 jsh_inoutitem
alter table jsh_inoutitem add delete_Flag varchar(1) DEFAULT '0' COMMENT '删除标记0未删除1删除';
alter table jsh_inoutitem add delete_Flag varchar(1) DEFAULT '0' COMMENT '删除标记0未删除1删除';
-- ----------------------------
-- 时间2019年4月11日
-- version1.0.13
-- 此次更新
-- 删除所有外键
-- 特别提醒之后的sql都是在之前基础上迭代可以对已存在的系统进行数据保留更新
-- ----------------------------
-- ----------------------------
-- 删除财务主表对应外键约束
-- ----------------------------
ALTER TABLE jsh_accounthead DROP FOREIGN KEY FK9F4C0D8DAAE50527;
ALTER TABLE jsh_accounthead DROP FOREIGN KEY FK9F4C0D8DB610FC06;
ALTER TABLE jsh_accounthead DROP FOREIGN KEY FK9F4C0D8DC4170B37;
-- ----------------------------
-- 删除财务子表对应外键约束
-- ----------------------------
ALTER TABLE jsh_accountitem DROP FOREIGN KEY FK9F4CBAC0AAE50527;
ALTER TABLE jsh_accountitem DROP FOREIGN KEY FK9F4CBAC0C5FE6007;
ALTER TABLE jsh_accountitem DROP FOREIGN KEY FK9F4CBAC0D203EDC5;
-- ----------------------------
-- 删除资产记录表对应外键约束
-- ----------------------------
ALTER TABLE jsh_asset DROP FOREIGN KEY FK353690ED27D23FE4;
ALTER TABLE jsh_asset DROP FOREIGN KEY FK353690ED3E226853;
ALTER TABLE jsh_asset DROP FOREIGN KEY FK353690ED61FE182C;
ALTER TABLE jsh_asset DROP FOREIGN KEY FK353690ED9B6CB285;
ALTER TABLE jsh_asset DROP FOREIGN KEY FK353690EDAD45B659;
-- ----------------------------
-- 删除资产信息表对应外键约束
-- ----------------------------
ALTER TABLE jsh_assetname DROP FOREIGN KEY FKA4ADCCF866BC8AD3;
-- ----------------------------
-- 删除单据主表对应外键约束
-- ----------------------------
ALTER TABLE jsh_depothead DROP FOREIGN KEY FK2A80F214AAE50527;
ALTER TABLE jsh_depothead DROP FOREIGN KEY jsh_depothead_ibfk_1;
ALTER TABLE jsh_depothead DROP FOREIGN KEY jsh_depothead_ibfk_4;
ALTER TABLE jsh_depothead DROP FOREIGN KEY jsh_depothead_ibfk_5;
-- ----------------------------
-- 删除单据子表对应外键约束
-- ----------------------------
ALTER TABLE jsh_depotitem DROP FOREIGN KEY FK2A819F47729F5392;
ALTER TABLE jsh_depotitem DROP FOREIGN KEY FK2A819F479485B3F5;
ALTER TABLE jsh_depotitem DROP FOREIGN KEY jsh_depotitem_ibfk_2;
-- ----------------------------
-- 删除操作日志表对应外键约束
-- ----------------------------
ALTER TABLE jsh_log DROP FOREIGN KEY FKF2696AA13E226853;
-- ----------------------------
-- 删除产品表对应外键约束
-- ----------------------------
ALTER TABLE jsh_material DROP FOREIGN KEY FK675951272AB6672C;
ALTER TABLE jsh_material DROP FOREIGN KEY jsh_material_ibfk_1;

View File

@@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.google.gson.JsonObject;
import com.jsh.erp.constants.BusinessConstants;
import com.jsh.erp.constants.ExceptionConstants;
import com.jsh.erp.datasource.entities.MaterialCategory;
import com.jsh.erp.datasource.entities.SerialNumberEx;
@@ -151,9 +152,20 @@ public class MaterialCategoryController {
* @return java.lang.Object
*/
@RequestMapping(value = "/batchDeleteMaterialCategory")
public Object batchDeleteMaterialCategory(@RequestParam("ids") String ids) throws Exception {
public Object batchDeleteMaterialCategory(@RequestParam("ids") String ids,@RequestParam(value="deleteType",
required =false,defaultValue= BusinessConstants.DELETE_TYPE_NORMAL)String deleteType) throws Exception {
JSONObject result = ExceptionConstants.standardSuccess();
int i= materialCategoryService.batchDeleteMaterialCategoryByIds(ids);
int i=0;
if(BusinessConstants.DELETE_TYPE_NORMAL.equals(deleteType)){
i= materialCategoryService.batchDeleteMaterialCategoryByIdsNormal(ids);
}else if(BusinessConstants.DELETE_TYPE_FORCE.equals(deleteType)){
i= materialCategoryService.batchDeleteMaterialCategoryByIds(ids);
}else{
logger.error("异常码[{}],异常提示[{}],参数,ids[{}],deleteType[{}]",
ExceptionConstants.DELETE_REFUSED_CODE,ExceptionConstants.DELETE_REFUSED_MSG,ids,deleteType);
throw new BusinessRunTimeException(ExceptionConstants.DELETE_REFUSED_CODE,
ExceptionConstants.DELETE_REFUSED_MSG);
}
if(i<1){
throw new BusinessRunTimeException(ExceptionConstants.MATERIAL_CATEGORY_DELETE_FAILED_CODE,
ExceptionConstants.MATERIAL_CATEGORY_DELETE_FAILED_MSG);

View File

@@ -1,6 +1,7 @@
package com.jsh.erp.controller;
import com.alibaba.fastjson.JSONObject;
import com.jsh.erp.constants.BusinessConstants;
import com.jsh.erp.constants.ExceptionConstants;
import com.jsh.erp.exception.BusinessRunTimeException;
import com.jsh.erp.service.unit.UnitService;
@@ -34,9 +35,20 @@ public class UnitController {
* @return java.lang.Object
*/
@RequestMapping(value = "/batchDeleteUnitByIds")
public Object batchDeleteUnitByIds(@RequestParam("ids") String ids) throws Exception {
public Object batchDeleteUnitByIds(@RequestParam("ids") String ids,@RequestParam(value="deleteType",
required =false,defaultValue= BusinessConstants.DELETE_TYPE_NORMAL)String deleteType) throws Exception {
JSONObject result = ExceptionConstants.standardSuccess();
int i= unitService.batchDeleteUnitByIds(ids);
int i=0;
if(BusinessConstants.DELETE_TYPE_NORMAL.equals(deleteType)){
i= unitService.batchDeleteUnitByIdsNormal(ids);
}else if(BusinessConstants.DELETE_TYPE_FORCE.equals(deleteType)){
i= unitService.batchDeleteUnitByIds(ids);
}else{
logger.error("异常码[{}],异常提示[{}],参数,ids[{}],deleteType[{}]",
ExceptionConstants.DELETE_REFUSED_CODE,ExceptionConstants.DELETE_REFUSED_MSG,ids,deleteType);
throw new BusinessRunTimeException(ExceptionConstants.DELETE_REFUSED_CODE,
ExceptionConstants.DELETE_REFUSED_MSG);
}
if(i<1){
logger.error("异常码[{}],异常提示[{}],参数,ids[{}]",
ExceptionConstants.UNIT_DELETE_FAILED_CODE,ExceptionConstants.UNIT_DELETE_FAILED_MSG,ids);

View File

@@ -35,4 +35,6 @@ public interface MaterialCategoryMapperEx {
int editMaterialCategory(MaterialCategory mc);
List<MaterialCategory> getMaterialCategoryBySerialNo(@Param("serialNo") String serialNo);
List<MaterialCategory> getMaterialCategoryListByCategoryIds(@Param("parentIds") String[] categoryIds);
}

View File

@@ -1,5 +1,6 @@
package com.jsh.erp.datasource.mappers;
import com.jsh.erp.datasource.entities.AccountHead;
import com.jsh.erp.datasource.entities.Material;
import com.jsh.erp.datasource.entities.MaterialVo4Unit;
import org.apache.ibatis.annotations.Param;
@@ -57,4 +58,8 @@ public interface MaterialMapperEx {
List<Material> getMaterialEnableSerialNumberList(Map<String, Object> parameterMap);
int batchDeleteMaterialByIds(@Param("updateTime") Date updateTime, @Param("updater") Long updater, @Param("ids") String ids[]);
List<Material> getMaterialListByCategoryIds(@Param("categoryIds") String[] categoryIds);
List<Material> getMaterialListByUnitIds(@Param("unitIds") String[] unitIds);
}

View File

@@ -1,13 +1,13 @@
package com.jsh.erp.service.materialCategory;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.jsh.erp.constants.BusinessConstants;
import com.jsh.erp.constants.ExceptionConstants;
import com.jsh.erp.datasource.entities.MaterialCategory;
import com.jsh.erp.datasource.entities.MaterialCategoryExample;
import com.jsh.erp.datasource.entities.User;
import com.jsh.erp.datasource.entities.*;
import com.jsh.erp.datasource.mappers.MaterialCategoryMapper;
import com.jsh.erp.datasource.mappers.MaterialCategoryMapperEx;
import com.jsh.erp.datasource.mappers.MaterialMapperEx;
import com.jsh.erp.datasource.vo.TreeNode;
import com.jsh.erp.exception.BusinessRunTimeException;
import com.jsh.erp.service.log.LogService;
@@ -37,6 +37,8 @@ public class MaterialCategoryService {
private UserService userService;
@Resource
private LogService logService;
@Resource
private MaterialMapperEx materialMapperEx;
public MaterialCategory getMaterialCategory(long id) {
return materialCategoryMapper.selectByPrimaryKey(id);
@@ -216,5 +218,52 @@ public class MaterialCategoryService {
}
}
/**
* create by: qiankunpingtai
* websitehttps://qiankunpingtai.cn
* description:
* 正常删除,要考虑数据完整性,进行完整性校验
* create time: 2019/4/11 9:26
* @Param: ids
* @return int
*/
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int batchDeleteMaterialCategoryByIdsNormal(String ids) throws Exception {
/**
* 校验
* 1、产品表 jsh_material
* 2、产品类型表 jsh_materialcategory
* 是否有相关数据
* */
int deleteTotal=0;
if(StringUtils.isEmpty(ids)){
return deleteTotal;
}
String [] idArray=ids.split(",");
/**
* 校验产品表 jsh_material
* */
List<Material> materialList=materialMapperEx.getMaterialListByCategoryIds(idArray);
if(materialList!=null&&materialList.size()>0){
logger.error("异常码[{}],异常提示[{}],参数,CategoryIds[{}]",
ExceptionConstants.DELETE_FORCE_CONFIRM_CODE,ExceptionConstants.DELETE_FORCE_CONFIRM_MSG,ids);
throw new BusinessRunTimeException(ExceptionConstants.DELETE_FORCE_CONFIRM_CODE,
ExceptionConstants.DELETE_FORCE_CONFIRM_MSG);
}
/**
* 校验产品类型表 jsh_materialcategory
* */
List<MaterialCategory> materialCategoryList=materialCategoryMapperEx.getMaterialCategoryListByCategoryIds(idArray);
if(materialCategoryList!=null&&materialCategoryList.size()>0){
logger.error("异常码[{}],异常提示[{}],参数,CategoryIds[{}]",
ExceptionConstants.DELETE_FORCE_CONFIRM_CODE,ExceptionConstants.DELETE_FORCE_CONFIRM_MSG,ids);
throw new BusinessRunTimeException(ExceptionConstants.DELETE_FORCE_CONFIRM_CODE,
ExceptionConstants.DELETE_FORCE_CONFIRM_MSG);
}
/**
* 校验通过执行删除操作
* */
deleteTotal= batchDeleteMaterialCategoryByIds(ids);
return deleteTotal;
}
}

View File

@@ -1,12 +1,17 @@
package com.jsh.erp.service.unit;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.jsh.erp.constants.BusinessConstants;
import com.jsh.erp.constants.ExceptionConstants;
import com.jsh.erp.datasource.entities.Material;
import com.jsh.erp.datasource.entities.Unit;
import com.jsh.erp.datasource.entities.UnitExample;
import com.jsh.erp.datasource.entities.User;
import com.jsh.erp.datasource.mappers.MaterialMapperEx;
import com.jsh.erp.datasource.mappers.UnitMapper;
import com.jsh.erp.datasource.mappers.UnitMapperEx;
import com.jsh.erp.exception.BusinessRunTimeException;
import com.jsh.erp.service.log.LogService;
import com.jsh.erp.service.user.UserService;
import com.jsh.erp.utils.StringUtil;
@@ -35,6 +40,8 @@ public class UnitService {
private UserService userService;
@Resource
private LogService logService;
@Resource
private MaterialMapperEx materialMapperEx;
public Unit getUnit(long id) {
return unitMapper.selectByPrimaryKey(id);
@@ -95,5 +102,41 @@ public class UnitService {
return unitMapperEx.batchDeleteUnitByIds(new Date(),userInfo==null?null:userInfo.getId(),idArray);
}
/**
* create by: qiankunpingtai
* websitehttps://qiankunpingtai.cn
* description:
* 正常删除,要考虑数据完整性,进行完整性校验
* create time: 2019/4/11 10:20
* @Param: ids
* @return int
*/
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int batchDeleteUnitByIdsNormal(String ids) throws Exception {
/**
* 校验
* 1、产品表 jsh_material
* 是否有相关数据
* */
int deleteTotal=0;
if(StringUtils.isEmpty(ids)){
return deleteTotal;
}
String [] idArray=ids.split(",");
/**
* 校验产品表 jsh_material
* */
List<Material> materialList=materialMapperEx.getMaterialListByUnitIds(idArray);
if(materialList!=null&&materialList.size()>0){
logger.error("异常码[{}],异常提示[{}],参数,UnitIds[{}]",
ExceptionConstants.DELETE_FORCE_CONFIRM_CODE,ExceptionConstants.DELETE_FORCE_CONFIRM_MSG,ids);
throw new BusinessRunTimeException(ExceptionConstants.DELETE_FORCE_CONFIRM_CODE,
ExceptionConstants.DELETE_FORCE_CONFIRM_MSG);
}
/**
* 校验通过执行删除操作
* */
deleteTotal= batchDeleteUnitByIds(ids);
return deleteTotal;
}
}

View File

@@ -107,5 +107,17 @@
and serial_no=#{serialNo}
and ifnull(status,'0') !='2'
</select>
<select id="getMaterialCategoryListByCategoryIds" resultMap="com.jsh.erp.datasource.mappers.MaterialCategoryMapper.BaseResultMap">
select
<include refid="com.jsh.erp.datasource.mappers.MaterialCategoryMapper.Base_Column_List" />
from jsh_materialcategory
where 1=1
and parentId in (
<foreach collection="parentIds" item="parentId" separator=",">
#{parentId}
</foreach>
)
and ifnull(status,'0') !='2'
</select>
</mapper>

View File

@@ -149,6 +149,30 @@
</foreach>
)
</update>
<select id="getMaterialListByCategoryIds" resultMap="com.jsh.erp.datasource.mappers.MaterialMapper.BaseResultMap">
select
<include refid="com.jsh.erp.datasource.mappers.MaterialMapper.Base_Column_List" />
from jsh_material
where 1=1
and categoryId in (
<foreach collection="categoryIds" item="categoryId" separator=",">
#{categoryId}
</foreach>
)
and ifnull(delete_Flag,'0') !='1'
</select>
<select id="getMaterialListByUnitIds" resultMap="com.jsh.erp.datasource.mappers.MaterialMapper.BaseResultMap">
select
<include refid="com.jsh.erp.datasource.mappers.MaterialMapper.Base_Column_List" />
from jsh_material
where 1=1
and unitId in (
<foreach collection="unitIds" item="unitId" separator=",">
#{unitId}
</foreach>
)
and ifnull(delete_Flag,'0') !='1'
</select>
</mapper>