标签:ali deb optional tor 产品 try via art ice
一、根据主键进行删除
/**
* 按主键进行删除
* @param dctx
* @param context
* @return
*/
public static Map<String,Object> deleteUomByPrimaryKey(
DispatchContext dctx, Map<String,Object> context){
//取得实体引擎实例
GenericDelegator delegator = dctx.getDelegator();
//TODO 在这里考虑的不是很全面, 还需要讨论一下: 1) MiscMap方式 2) delegator.makePKSingle方法
Map<String,Object> pkFields = FastMap.newInstance();
pkFields.put("uomId", "BaseLineProduct"); //这里删除前面创建的基线产品信息
GenericPK primaryKey = delegator.makePK("Uom", pkFields);
try {
//执行按主键删除操作
delegator.removeByPrimaryKey(primaryKey);
} catch (GenericEntityException e) {
//则把错误信息以Error级别打印到日志文件中
Debug.logError(e, module);
//把指定的错误码对应的描述信息返回给服务调用者
return ReturnMapUtil.getErrorMap(DemoErrorMapping.BASE0002,primaryKey.toString());
}
//把表示成功的信息返回给服务调用者
return ReturnMapUtil.getSuccessMap();
}
二、根据多条件进行删除
/**
* 按多条件进行删除, 并且这些条件是‘与‘ 的关系, 一般是当删除条件为非主键时使用
* @param dctx
* @param context
* @return
*/
public static Map<String,Object> deleteUomByOtherFields(DispatchContext dctx, Map<String,Object> context){
//取得实体引擎实例
GenericDelegator delegator = dctx.getDelegator();
//TODO 在这里考虑的不是很全面, 还需要讨论一下: MiscMap方式
//这里删除前面创建的现金管理系统信息
Map<String,Object> deleteFields = FastMap.newInstance();
deleteFields.put("abbreviation", "Cashm");
deleteFields.put("description", "现金管理系统");
try {
//根据设定的条件执行删除操作
delegator.removeByAnd("Uom", deleteFields);
} catch (GenericEntityException e) {
//则把错误信息以Error级别打印到日志文件中
Debug.logError(e, module);
//把指定的错误码对应的描述信息返回给服务调用者
return ReturnMapUtil.getErrorMap(DemoErrorMapping.BASE0002,deleteFields.toString());
}
//把表示成功的信息返回给服务调用者
return ReturnMapUtil.getSuccessMap();
}
三、根据一个字段有多个值时进行删除
/**
* 根据一个字段的多个值,删除记录
* @param dctx
* @param context
* @return
*/
public static Map<String,Object> deleteUomByMoreValues(DispatchContext dctx, Map<String,Object> context){
//取得实体引擎实例
GenericDelegator delegator = dctx.getDelegator();
//这里删除前面创建的"基线产品信息"和"现金管理系统信息"
Map<String,Object> deleteFields = FastMap.newInstance();
deleteFields.put("abbreviation", "BLP");
deleteFields.put("abbreviation", "Cashm");
//收集删除条件
EntityCondition deleteBLPCon = EntityCondition.makeCondition("abbreviation", EntityOperator.EQUALS, "BLP");
EntityCondition deleteCashmCon = EntityCondition.makeCondition("abbreviation", EntityOperator.EQUALS, "Cashm");
EntityCondition deleteCondition = EntityCondition.makeCondition(deleteBLPCon, EntityOperator.OR, deleteCashmCon);
try {
System.err.println("删除条件: " + deleteCondition.toString());
//根据设定的条件执行删除操作
delegator.removeByCondition("Uom", deleteCondition);
} catch (GenericEntityException e) {
//则把错误信息以Error级别打印到日志文件中
Debug.logError(e, module);
//把指定的错误码对应的描述信息返回给服务调用者
return ReturnMapUtil.getErrorMap(DemoErrorMapping.BASE0002,deleteCondition.toString());
}
//把表示成功的信息返回给服务调用者
return ReturnMapUtil.getSuccessMap();
}
四、根据时间段进行删除
/**
* 删除一个时间段内的数据
* @param dctx
* @param context
* @return
*/
public static Map<String,Object> deleteUomByDate(DispatchContext dctx, Map<String,Object> context){
//取得实体引擎实例
GenericDelegator delegator = dctx.getDelegator();
//从输入参数中取出开始日期和结束日期
String beginDateStr = (String) context.get("beginDate");
String endDateStr = (String) context.get("endDate");
//设置查询条件: 记录时间 大于 beginDate ,记录时间 小于 endDate
List<EntityCondition> conList = FastList.newInstance();
//如果传入的开始日期不为空,则设置删除条件: 删除的记录不能早于开始日期
if( UtilValidate.isNotEmpty(beginDateStr)){
try {
//先把开始日期的字符串转成Timestamp格式
Timestamp beginDate = UtilDateTime.stringToTimeStamp(beginDateStr, InnerConstant.DATE_FORMAT, TimeZone.getDefault(), Locale.CHINA);
//再把整个日期的时间部分设置成 00:00:00.000
beginDate = UtilDateTime.getDayStart(beginDate);
//设置查询条件: 记录时间 大于 beginDate
EntityCondition startDateCon = EntityCondition.makeCondition("createdStamp", EntityOperator.GREATER_THAN_EQUAL_TO, beginDate);
conList.add(startDateCon);
} catch (ParseException e) {
//则把错误信息以Error级别打印到日志文件中
Debug.logError(e, module);
return ReturnMapUtil.getErrorMap(DemoErrorMapping.BASE0003,beginDateStr,e.getMessage());
}
}
//如果传入的结束日期不为空, 则设置删除条件: 删除的记录不能晚于结束日期
if( UtilValidate.isNotEmpty(endDateStr)){
try {
//先把结束日期的字符串转成Timestamp格式
Timestamp endDate = UtilDateTime.stringToTimeStamp(endDateStr, InnerConstant.DATE_FORMAT, TimeZone.getDefault(), Locale.CHINA);
System.err.println(endDate.toString());
//再把结束日期的时间部分设置成: 23:59:59.999
endDate = UtilDateTime.getDayEnd(UtilDateTime.nowTimestamp());
//设置查询条件: 记录时间 小于 endDate
EntityCondition endTimeCon = EntityCondition.makeCondition("createdStamp", EntityOperator.LESS_THAN_EQUAL_TO, endDate);
conList.add(endTimeCon);
} catch (ParseException e) {
//则把错误信息以Error级别打印到日志文件中
Debug.logError(e, module);
return ReturnMapUtil.getErrorMap(DemoErrorMapping.BASE0004,endDateStr,e.getMessage());
}
}
EntityCondition deleteCondition = EntityCondition.makeCondition(conList, EntityOperator.AND);
try {
//根据设定的条件执行删除操作
delegator.removeByCondition("Uom", deleteCondition);
} catch (GenericEntityException e) {
//则把错误信息以Error级别打印到日志文件中
Debug.logError(e, module);
//把指定的错误码对应的描述信息返回给服务调用者
return ReturnMapUtil.getErrorMap(DemoErrorMapping.BASE0002,deleteCondition.toString());
}
//把表示成功的信息返回给服务调用者
return ReturnMapUtil.getSuccessMap();
}
XML配置
<service name="deleteUomByDate" engine="java" location="com.giantstone.bosent.demo.delegator.DelegatorDeleteDemoService" invoke="deleteUomByDate"> <attribute name="beginDate" type="String" mode="IN" optional="true" /> <attribute name="endDate" type="String" mode="IN" optional="true" /> <attribute name="returnCode" type="Map" mode="OUT" optional="true" /> </service>
标签:ali deb optional tor 产品 try via art ice
原文地址:https://www.cnblogs.com/gzhcsu/p/11203370.html