/* *

ClassName: LCCustomerImpartBL

*

Description: LCCustomerImpartSchemaBL类文件

*

Copyright: Copyright (c) 2002

*

Company: sinosoft

* @Database: LIS * @CreateDate:2002-04-01 */ package com.sinosoft.lis.bl; import com.sinosoft.lis.i18n.I18nMessage; import com.sinosoft.lis.db.LBCustomerImpartDB; import com.sinosoft.lis.db.LCCustomerImpartDB; import com.sinosoft.lis.pubfun.GlobalInput; import com.sinosoft.lis.pubfun.MMap; import com.sinosoft.lis.pubfun.PubFun; import com.sinosoft.lis.controller.Action; import com.sinosoft.lis.pubfun.PubSubmit; import com.sinosoft.lis.schema.LBCustomerImpartSchema; import com.sinosoft.lis.schema.LCCustomerImpartSchema; import com.sinosoft.lis.sql.repository.LCCustomerImpartSQL; import com.sinosoft.lis.vschema.LBCustomerImpartSet; import com.sinosoft.lis.vschema.LCCustomerImpartSet; import com.sinosoft.persistence.SQLProxy; import com.sinosoft.utility.*; import org.apache.commons.lang.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.util.List; import java.util.Objects; import java.util.regex.Pattern; public class LCCustomerImpartBL { private static final Logger logger = LoggerFactory.getLogger(LCCustomerImpartBL.class); private LCCustomerImpartSQL lCCustomerImpartSQL = SQLProxy.getInstance(LCCustomerImpartSQL.class); /** 投保单号 */ private String grpContNo; /** 错误处理类,每个需要错误处理的类中都放置该类 */ private CErrors mErrors = new CErrors(); /** 提交数据的容器 */ private MMap mMMap = new MMap(); /** 操作变量 */ private String mOperate; private String mCurrentDate; private String mCurrentTime; /** 传入数据的容器 */ private VData mInputData = new VData(); public LCCustomerImpartBL() { mCurrentDate = PubFun.getCurrentDate(); mCurrentTime = PubFun.getCurrentTime(); } // @Constructor public static LCCustomerImpartSchema get() { LCCustomerImpartSchema schema = new LCCustomerImpartSchema(); schema.setModifyDate(PubFun.getCurrentDate()); schema.setModifyDate(PubFun.getCurrentTime()); return schema; } /** * 设置默认的字段属性 */ public static void setDefaultFields(LCCustomerImpartSchema schema) { schema.setModifyDate(PubFun.getCurrentDate()); schema.setModifyTime(PubFun.getCurrentTime()); } /** * 从客户告知表和客户告知备份表读取信息 返回true或false */ public static boolean getInfo(LCCustomerImpartSchema schema) { Reflections tR = new Reflections(); LCCustomerImpartDB tDB = new LCCustomerImpartDB(); tDB.setSchema(schema); if (!tDB.getInfo()) // 如果查询失败,查询B表 { LBCustomerImpartDB tDBB = new LBCustomerImpartDB(); LBCustomerImpartSchema tLBCustomerImpartSchema = new LBCustomerImpartSchema(); tR.transFields(tLBCustomerImpartSchema, schema.getSchema()); tDBB.setSchema(tLBCustomerImpartSchema); if (!tDBB.getInfo()) { // @@错误处理 CError tError = new CError(); tError.moduleName = "LCCustomerImpartBL"; tError.functionName = "getInfo"; tError.errorMessage(new I18nMessage("没有查询到客户告知表", "LIS-14541")); schema.mErrors.addOneError(tError); return false; } else { LCCustomerImpartSchema tS = new LCCustomerImpartSchema(); tR.transFields(tS, tDBB.getSchema()); schema.setSchema(tS); } } else { schema.setSchema(tDB.getSchema()); } return true; } /** * 从客户告知表和客户告知备份表读取信息 返回LCCustomerImpartSet * */ public static LCCustomerImpartSet query(LCCustomerImpartSchema schema) { Reflections tR = new Reflections(); LCCustomerImpartSet tLCCustomerImpartSet = new LCCustomerImpartSet(); LCCustomerImpartDB tLCCustomerImpartDB = new LCCustomerImpartDB(); tLCCustomerImpartDB.setSchema(schema.getSchema()); tLCCustomerImpartSet = tLCCustomerImpartDB.query(); if (tLCCustomerImpartSet.size() == 0) { LBCustomerImpartSet tLBCustomerImpartSet = new LBCustomerImpartSet(); LBCustomerImpartDB tLBCustomerImpartDB1 = new LBCustomerImpartDB(); tR.transFields(tLBCustomerImpartDB1.getSchema(), schema.getSchema()); tLBCustomerImpartSet = tLBCustomerImpartDB1.query(); if (tLBCustomerImpartSet.size() == 0) { // @@错误处理 CError tError = new CError(); tError.moduleName = "LCCustomerImpartBL"; tError.functionName = "query"; tError.errorMessage(new I18nMessage("没有查询到客户告知表", "LIS-14541")); schema.mErrors.addOneError(tError); return tLCCustomerImpartSet; } else { tLCCustomerImpartSet.add(schema.getSchema()); tR.transFields(tLCCustomerImpartSet, tLBCustomerImpartSet); } } return tLCCustomerImpartSet; } /** * 从客户告知表和客户告知备份表读取信息 返回LCCustomerImpartSet * */ public static LCCustomerImpartSet executeQuery(LCCustomerImpartSchema schema, SQLwithBindVariables sql) { Reflections tR = new Reflections(); LCCustomerImpartSet tLCCustomerImpartSet = new LCCustomerImpartSet(); LCCustomerImpartDB tLCCustomerImpartDB = new LCCustomerImpartDB(); tLCCustomerImpartDB.setSchema(schema.getSchema()); tLCCustomerImpartSet = tLCCustomerImpartDB.executeQuery(sql); if (tLCCustomerImpartSet.size() == 0) { LBCustomerImpartSet tLBCustomerImpartSet = new LBCustomerImpartSet(); LBCustomerImpartDB tLBCustomerImpartDB1 = new LBCustomerImpartDB(); tR.transFields(tLBCustomerImpartDB1.getSchema(), schema.getSchema()); tLBCustomerImpartSet = tLBCustomerImpartDB1.executeQuery(sql); if (tLBCustomerImpartSet.size() == 0) { // @@错误处理 CError tError = new CError(); tError.moduleName = "LCCustomerImpartBL"; tError.functionName = "query"; tError.errorMessage(new I18nMessage("没有查询到客户告知表", "LIS-14541")); schema.mErrors.addOneError(tError); return tLCCustomerImpartSet; } else { tLCCustomerImpartSet.add(schema.getSchema()); tR.transFields(tLCCustomerImpartSet, tLBCustomerImpartSet); } } return tLCCustomerImpartSet; } public boolean submitData(List list,String operator) { if (!getInputData(operator)) { return false; } if (!checkData(list)) { return false; } if (!dealData(list)) { return false; } return saveData(); } private boolean saveData() { PubSubmit tPubSubmit = new PubSubmit(); mInputData.add(mMMap); if (!tPubSubmit.submitData(mInputData, Action.INSERT_ACTION)) { buildError("saveData", new I18nMessage("提交数据失败!", "LIS-08006")); return false; } return true; } private boolean dealData(List list) { LCCustomerImpartSchema lcCustomerImpartSchema = list.get(0); grpContNo = lcCustomerImpartSchema.getGrpContNo(); if (Action.INSERT_ACTION.equals(mOperate)) { SQLwithBindVariables sqLwithBindVariables = lCCustomerImpartSQL.deleteByGrpContNo(grpContNo); mMMap.put(sqLwithBindVariables, MMap.Action.DELETE); for (LCCustomerImpartSchema tLCCustomerImpartSchema : list) { tLCCustomerImpartSchema.setModifyDate(mCurrentDate); tLCCustomerImpartSchema.setMakeTime(mCurrentTime); tLCCustomerImpartSchema.setModifyDate(mCurrentDate); tLCCustomerImpartSchema.setMakeTime(mCurrentTime); mMMap.put(tLCCustomerImpartSchema, MMap.Action.INSERT); } } return true; } private boolean checkData(List list) { for (LCCustomerImpartSchema tLCCustomerImpartSchema : list) { String impartCode = tLCCustomerImpartSchema.getImpartCode(); String impartParamModle = tLCCustomerImpartSchema.getImpartParamModle(); if (StringUtils.isNotBlank(impartParamModle) && Objects.equals(impartCode, "A0101")){ String regex = "^\\d+(/\\d+){4}$"; Pattern pattern = Pattern.compile(regex); if (!pattern.matcher(impartParamModle).matches()){ buildError("checkData",new I18nMessage(impartCode+"参数错误,格式为:参数1/参数2/参数3/参数4/参数5", "LIS-72097")); return false; } } if (StringUtils.isNotBlank(impartParamModle) && Objects.equals(impartCode, "A01010")){ String regex = "^\\d+(/\\d+)$"; Pattern pattern = Pattern.compile(regex); if (!pattern.matcher(impartParamModle).matches()){ buildError("checkData",new I18nMessage(impartCode+"参数错误,格式为:参数1/参数2", "LIS-72098")); return false; } } if (StringUtils.isNotBlank(impartParamModle) && !Objects.equals(impartCode, "A01010") && !Objects.equals(impartCode, "A0101")) { if (!Objects.equals(impartParamModle, "是") && !Objects.equals(impartParamModle, "否") ){ buildError("checkData",new I18nMessage(impartCode+"参数错误,请填是或否", "LIS-72099")); return false; } } } return true; } private boolean getInputData(String operator) { this.mOperate = operator; return true; } public CErrors getErrors() { return mErrors; } /** * 错误构造方法 * @param tFunctionName * @param tErrorMessage */ private void buildError(String tFunctionName, I18nMessage tErrorMessage) { CError tCError = new CError(); tCError.moduleName = this.getClass().getSimpleName(); tCError.functionName = tFunctionName; tCError.errorMessage(tErrorMessage); mErrors.addOneError(tCError); } }