![](https://i-blog.csdnimg.cn/blog_migrate/ad8f17135a883994830a3035109c7b52.png)
![](https://i-blog.csdnimg.cn/blog_migrate/63f3d883a7ad7aefcaded030da745c32.png)
![](https://i-blog.csdnimg.cn/blog_migrate/808d68f940eee405b8a286e4665e9762.png)
![](https://i-blog.csdnimg.cn/blog_migrate/8560f872f4cfd7acbd62e33ce58ad5a4.png)
<td o="<%=orgId%>" n="<%=orgName%>">
<!--<a class="btn btn-xs btn-primary org_menu_kp org_kp_<%= orgId%>" orgId="<%= orgId%>" href="#uploadPage"><i class="icon-upload"></i> 知识点/能力点</a>-->
<%if(status==1){%>
<a class="btn btn-xs btn-info org_menu_start"><i class="icon-trash"></i> 启用</a>
<a class="btn btn-xs btn-danger org_menu_delete"><i class="icon-trash"></i> 删除</a>
<%}else{%>
<a href="javascript:;" class="btn btn-xs btn-success btn_import org_menu_modify btn_modify_<%=orgId%>"><i class="icon-pencil"></i> 修改</a>
<a href="javascript:;" class="btn btn-xs btn-primary org_menu_detail"><i class="icon-pushpin"></i> 详情</a>
<a class="btn btn-xs btn-default org_menu_accounts" href="#uploadOrgActPage"><i class="icon-trash"></i> 导入账户</a>
<a class="btn btn-xs btn-warning org_menu_stop"><i class="icon-trash"></i> 停用</a>
<a class="btn btn-xs btn-danger org_menu_delete"><i class="icon-trash"></i> 删除</a>
<%}%>
</td>
//删除操作
$(".org_table_tbody").delegate(".org_menu_delete", "click", function(){
var $row = $(this).parents('tr');
// if( school_Table.data().length <=1){
// return false;
// }
var orgName = $(this).parent().attr("n"),
orgId = $(this).parent().attr("o");
$.confirm({
text: "确定要删除这个机构吗?",
title: "系统提示",
confirm: function(button) {
//url, dataType, success_callback, failed_callback
CUBE.getDataByAjax(
'../union/org/delete/' + orgId,
'json',
function(res){
if(res.code == 0){
org_Table.row( $row ).remove().draw();
alert('删除机构成功.');
}else{
alert('删除机构失败, 原因: '+res.data);
}
}
);
},
cancel: function(button) {
// do something
},
confirmButton: "确认",
cancelButton: "放弃"
});
});
/**
* 删除机构信息
* @param id 机构Id
* @return 操作结果
*/
@RequestMapping(value="/delete/{id}", method=RequestMethod.GET)
@ResponseBody
public JSONObject delOrg(@PathVariable("id") Long id){
try {
return getSuccessResult(orgBO.delete(id));
} catch (com.zxt.framework.exception.BOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
@Override
public JSONObject delete(Long id) throws BOException {
String ret;
try {
String url = Constants.DTC_BIZ_CUBE_URI + PropertiesConfigUtils.getString("url.org.delOrgs")
+ id;
ret = HttpClientUtil.getInstance("UTF-8", Constants.HTTPCLIENT_TIMEOUT).getResponseBodyAsString(url, null);
} catch (Exception e) {
e.printStackTrace();
throw new BOException(e.getMessage());
}
JSONObject jo = JSON.parseObject(ret);
return jo;
}
package com.doofen.biz.cube.org;
/**
*
* @Package com.doofen.biz.cube.org
* @ClassName: IDelOrgs
* @Description: 批量删除机构接口
* @author Jeffrey
* @date 2016年7月7日
*
*/
public interface IDelOrgs {
/**
*
* @Title: del
* @Description: 删除机构
* @param value = [orgId,...]
* @throws Exception 参数
* @return void
* @throws
*/
public void del(String value) throws Exception;
}
package com.doofen.biz.cube.org.impl;
import java.util.ArrayList;
import java.util.List;
import org.elasticsearch.index.query.QueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.doofen.DAEConst;
import com.doofen.IndexBox;
import com.doofen.base.core.es.IBboData;
import com.doofen.base.core.es.IBeoData;
import com.doofen.base.core.es.impl.BboDataImpl;
import com.doofen.base.core.es.impl.BeoDataImpl;
import com.doofen.base.eao.EsOperation;
import com.doofen.base.exception.DAEException;
import com.doofen.base.rest.RestMsgConst;
import com.doofen.base.tools.DAEStringUtils;
import com.doofen.biz.cube.org.IAMDStaff;
import com.doofen.biz.cube.org.IDelOrgs;
import com.doofen.dict.core.bbo.BBOConst;
import com.doofen.dict.core.bbo.dto.BBOOrg;
import com.doofen.dict.core.bco.BCOConst;
import com.doofen.dict.core.beo.BEOConst;
/**
*
* @Package com.doofen.biz.cube.org.impl
* @ClassName: DelOrgsImpl
* @Description: 批量删除机构
* @author Jeffrey
* @date 2016年7月7日
*
*/
public class DelOrgsImpl implements IDelOrgs {
@Override
/**
*
* @Title: del
* @Description: 删除机构
* @param value = [orgId,...]
* @throws Exception 参数
* @return void
* @throws
*/
public void del(String value) throws Exception {
//检查url
//Long[] orgIds = checkUrl(value);
Long[] orgIds = new Long[1];
orgIds[0] = Long.parseLong(value);
IBboData bboH = new BboDataImpl();
//拿取org
JSONObject orgs = get_es_org(bboH, orgIds);
//检查org状态
check_status(orgs);
//检查机构是否被考试引用,如果引用则无法删除
check_exam_org(orgIds);
//删除或更新机构人员
IAMDStaff amdStaff = new AMDStaffImpl();
for(Long orgId: orgIds)
amdStaff.delOrg(orgId);
//删除机构信息(包括关联的知识点、能力点体系,机构本身)
deleteES(orgIds);
}
/**
*
* @Title: checkUrl
* @Description: 检查url
* @param values
* @return [orgId, ...]
* @throws Exception 参数
* @return Long[]
* @throws
*/
private Long[] checkUrl(String values) throws Exception {
JSONArray ja = new JSONArray();
try{
ja = JSONArray.parseArray(values);
}catch(Exception e){
throw new DAEException(RestMsgConst.PARAM_ERROR, "JSONArray解析失败");
}
if(ja == null || ja.isEmpty()){
throw new DAEException(RestMsgConst.PARAM_ERROR, "没有需删除的数据");
}
List<Long> orgIds = new ArrayList<Long>();
List<Long> dups = new ArrayList<Long>();
for(int i=0; i<ja.size(); i++){
Long orgId = ja.getLong(i);
if(orgIds.contains(orgId)){
dups.add(orgId);
}else{
orgIds.add(orgId);
}
}
if(dups.size() != 0){
throw new DAEException(RestMsgConst.PARAM_ERROR, "orgId重复:"+DAEStringUtils.Arr2String(dups, ","));
}
Long[] _orgIds = new Long[orgIds.size()];
orgIds.toArray(_orgIds);
return _orgIds;
}
/**
*
* @Title: get_es_org
* @Description: 拿取es中的机构信息
* @param bboH
* @param orgIds
* @return {orgId: BBOOrg, ...}
* @throws Exception 参数
* @return JSONObject
* @throws
*/
private JSONObject get_es_org(IBboData bboH, Long[] orgIds) throws Exception{
JSONObject orgs = bboH.getBBOOrg(orgIds);
if(orgs == null || orgs.isEmpty()){
throw new DAEException(RestMsgConst.ORG_LACK_ERROR, "机构不存在:"+DAEStringUtils.List2String(orgIds, ","));
}else if(orgs.size() != orgIds.length){
List<Long> lacks = new ArrayList<Long>();
for(Long orgId: orgIds){
if(!orgs.containsKey(orgId.toString())) lacks.add(orgId);
}
throw new DAEException(RestMsgConst.ORG_LACK_ERROR, "机构不存在:"+DAEStringUtils.Arr2String(lacks, ","));
}
return orgs;
}
/**
*
* @Title: check_status
* @Description: 检查机构状态,如果是正常状态,不允许删除
* @param orgs
* @throws Exception 参数
* @return void
* @throws
*/
private void check_status(JSONObject orgs) throws Exception{
for(String orgIdStr: orgs.keySet()){
BBOOrg org = orgs.getObject(orgIdStr, BBOOrg.class);
if(org.getStatus().equals(DAEConst.STATUS_NORMAL)){
throw new DAEException(RestMsgConst.ORG_USE_ERROR, "机构状态为‘正常’,无法删除");
}
}
}
/**
*
* @Title: check_exam_org
* @Description: 检查机构是否被考试引用,如果引用则无法删除
* @param orgIds
* @throws Exception 参数
* @return void
* @throws
*/
private void check_exam_org(Long[] orgIds) throws Exception{
IBeoData beoH = new BeoDataImpl();
JSONObject exams = beoH.getBEOExamByOrg(orgIds);
if(exams != null && !exams.isEmpty()){
throw new DAEException(RestMsgConst.ORG_USE_ERROR, "机构被考试引用:"+DAEStringUtils.Set2String(exams.keySet(), ","));
}
}
/**
*
* @Title: deleteES
* @Description: 删除机构
* @param orgIds
* @throws Exception 参数
* @return void
* @throws
*/
private void deleteES(Long[] orgIds) throws Exception {
EsOperation es = new EsOperation();
QueryBuilder del_org = QueryBuilders.termsQuery("orgId", (Object[]) orgIds);
QueryBuilder qry2 = QueryBuilders.termsQuery("schId", (Object[]) orgIds);
QueryBuilder qry3 = QueryBuilders.termQuery("idType", DAEConst.ID_TYPE_ORG);
QueryBuilder del_set = QueryBuilders.boolQuery().must(qry2).must(qry3);
try{
//bbo
es.delete_by_query(IndexBox.INDEX_BASE_BUSINESS_OBJECT,
new String[]{BBOConst.BBO_SCH_AB_SET, BBOConst.BBO_SCH_KP_SET},
del_set);
//bco
es.delete_by_query(IndexBox.INDEX_BASE_CONFIG_OBJECT, BCOConst.BCO_ORG, del_org);
//beo
es.delete_by_query(IndexBox.INDEX_BASE_EXAM_OBJECT,
BEOConst.BEO_EXAM_STATUS,
del_set);
//org
es.delete_by_query(IndexBox.INDEX_BASE_BUSINESS_OBJECT, BBOConst.BBO_ORG, del_org);
}catch (Exception e){
throw new DAEException(RestMsgConst.ES_DEL_ROW_ERROR, e);
}finally{
es.close();
}
}
}