* modify Condition Item and Detail
* @param request request
* @return IResult
*/
public IResult saveRuleTbDtl(IRequest request) {
AjaxFormResult result = new AjaxFormResult();
String type = request.get("type");
String divCtNo = request.get("divRlNo");
//Factor DETAIL
String[] ftGridData = request.getParamsAsStringArray("grid[]");
DivRlItm rlItm = ruleTbMntService.findByDivRlNo(divCtNo);
if ("A".equals(type)) {
if (rlItm != null) {
// 代碼重覆!
throw new CapMessageException(
CapAppContext.getMessage("ruleTb.0001"), getClass());
}
rlItm = new DivRlItm();
} else {
if (rlItm != null && !rlItm.getOid().equals(request.get("oid"))) {
// 代碼重覆!
throw new CapMessageException(
CapAppContext.getMessage("ruleTb.0001"), getClass());
} else if (rlItm == null && !CapString.isEmpty(request.get("oid"))) {
rlItm = ruleTbMntService.getById(request.get("oid"));
} else if (rlItm == null){
rlItm = new DivRlItm();
}
}
CapBeanUtil.map2Bean(request, rlItm);
if ("A".equals(type)) {
rlItm.setOid(null);
}
List<DivRlDtl> delRlDtl = new ArrayList<DivRlDtl>();
if(ftGridData!=null){
List<DivRlDtl> rlDtls = new LinkedList<DivRlDtl>();
if(rlItm.getDivRlDtls()!=null && !rlItm.getDivRlDtls().isEmpty()){
delRlDtl = rlItm.getDivRlDtls();
}
for(int i = 0; i<ftGridData.length; i++){
JSONObject jsData = JSONObject.fromObject(ftGridData[i]);
DivRlDtl rlDtl = new DivRlDtl();
// int j = 0;
// boolean haveOld = false;
// if(!CapString.isEmpty(jsData.getString("oid")) && !rlItm.getDivRlDtls().isEmpty()){
// for(DivRlDtl rlDtl2 : rlDtls){
// j++;
// if(rlDtl2.getOid().equals(jsData.opt("oid"))){
// rlDtl = rlDtl2;
// haveOld = true;
// break;
// }
// }
// }
CapBeanUtil.map2Bean(jsData, rlDtl);
rlDtl.setDivRlNo(rlItm.getDivRlNo());
rlDtl.setDivRlSor(new BigDecimal(i+1));
rlDtl.setDivCtNo(jsData.optString("divCtNo"));
DivCtItm ctItm = conditionMntService.getById(jsData.optString("divCtOid"));
// rlDtl.setDivCtItm(ctItm);
rlDtl.setDivRlItm(rlItm);
// if(haveOld){
// rlDtls.set(j, rlDtl);
// }else{
rlDtls.add(rlDtl);
// }
}
rlItm.setDivRlDtls(rlDtls);
}
String userId = CapSecurityContext.getUserId();
if(userId.length()>6)userId = userId.substring(0,6);
rlItm.setUpdater(userId);
rlItm.setUpdateTime(CapDate.getCurrentTimestamp());
String divRltyp = request.get("RadioGroup1");
rlItm.setDivRlTyp(divRltyp);
ruleTbMntService.saveDivRlItm(rlItm);
if(!delRlDtl.isEmpty())
ruleTbMntService.deleteRlDtlByList(delRlDtl);
result.set(Constants.AJAX_NOTIFY_MESSAGE, CapAppContext.getMessage("ruleTb.0002"));
return result;
}