7be75a238f4345bba94d7a9fbb7e619b095a618c.svn-base 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386
  1. package com.kingdee.shr.compensation.app.integrate;
  2. import com.google.common.collect.Lists;
  3. import com.kingdee.bos.BOSException;
  4. import com.kingdee.bos.Context;
  5. import com.kingdee.bos.util.BOSUuid;
  6. import com.kingdee.eas.basedata.person.PersonInfo;
  7. import com.kingdee.eas.common.EASBizException;
  8. import com.kingdee.shr.base.syssetting.app.filter.HRFilterUtils;
  9. import com.kingdee.shr.compensation.SscTypeEnum;
  10. import com.kingdee.shr.compensation.helper.CmpCurrencyHelper;
  11. import com.kingdee.shr.compensation.util.CmpDateUtil;
  12. import com.kingdee.shr.compensation.util.CmpSQLUtil;
  13. import com.kingdee.shr.compensation.util.integrate.CmpIntegrateEntryHelper;
  14. import com.kingdee.shr.compensation.util.integrate.IntegrateEntryTableAttrs;
  15. import com.kingdee.util.LocaleUtils;
  16. import java.sql.Timestamp;
  17. import java.text.ParseException;
  18. import java.text.SimpleDateFormat;
  19. import java.util.Date;
  20. import java.util.List;
  21. import org.apache.commons.lang3.StringUtils;
  22. import org.slf4j.Logger;
  23. import org.slf4j.LoggerFactory;
  24. public class SubmitBillEntryFacadeControllerBean extends AbstractSubmitBillEntryFacadeControllerBean {
  25. private static final long serialVersionUID = -3822503672868646868L;
  26. private static final Logger logger = LoggerFactory.getLogger(SubmitBillEntryFacadeControllerBean.class);
  27. private static final String BASE_TABLE_NAME = "T_HR_SchemeBillEntry";
  28. private static final String ENTITY_TYPE = "7F647776";
  29. private final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
  30. private String userId;
  31. protected void _dealSaveEnties(Context ctx, BatchSubmitShemeBillInfo billInfo) throws BOSException, EASBizException {
  32. String submitSchemeId = billInfo.getSubmitScheme().getId().toString();
  33. IntegrateEntryTableAttrs entryTableAttrs = CmpIntegrateEntryHelper.getIntegrateEntryTableAttrs(ctx, submitSchemeId);
  34. List<Object[]> baseParamArrayList = Lists.newArrayList();
  35. List<Object[]> paramArrayList = Lists.newArrayList();
  36. BatchSubmitShemeBillEntryCollection coll = billInfo.getEntry();
  37. for (int i = 0; i < coll.size(); i++)
  38. assembleSaveParamList(ctx, coll.get(i), billInfo, entryTableAttrs, baseParamArrayList, paramArrayList);
  39. batchSaveEntries(ctx, billInfo, entryTableAttrs, baseParamArrayList, paramArrayList);
  40. }
  41. protected void assembleSaveParamList(Context ctx, BatchSubmitShemeBillEntryInfo entryInfo, BatchSubmitShemeBillInfo billInfo, IntegrateEntryTableAttrs entryTableAttrs, List<Object[]> baseParamArrayList, List<Object[]> paramArrayList) {
  42. List<Object> paramList = Lists.newArrayList();
  43. String id = BOSUuid.create("7F647776").toString();
  44. entryInfo.setId(BOSUuid.read(id));
  45. paramList.add(id);
  46. paramList.add(billInfo.getId().toString());
  47. paramList.add(getUserId(ctx));
  48. paramList.add(new Timestamp(System.currentTimeMillis()));
  49. paramList.add(getEffectDate(entryInfo));
  50. paramList.add((entryInfo.getOrgUnit() == null) ? null : entryInfo.getOrgUnit().getId().toString());
  51. paramList.add((entryInfo.getPerson() == null) ? null : entryInfo.getPerson().getId().toString());
  52. paramList.add((entryInfo.getAdminOrgUnit() == null) ? null : entryInfo.getAdminOrgUnit().getId().toString());
  53. paramList.add((entryInfo.getPosition() == null) ? null : entryInfo.getPosition().getId().toString());
  54. paramList.add((entryInfo.getCmpEmpORelation() == null) ? null : entryInfo.getCmpEmpORelation().getId().toString());
  55. paramList.add((entryInfo.getSubmitElement() == null) ? null : entryInfo.getSubmitElement().getId().toString());
  56. paramList.add((entryInfo.getCurrency() == null) ? CmpCurrencyHelper.getCNYCurrencyId() : entryInfo
  57. .getCurrency().getId().toString());
  58. paramList.add(entryInfo.getDescription(LocaleUtils.locale_l1));
  59. paramList.add(entryInfo.getDescription(LocaleUtils.locale_l2));
  60. paramList.add(entryInfo.getDescription(LocaleUtils.locale_l3));
  61. paramList.add((entryInfo.getLeffectDate() == null) ? CmpDateUtil.toSqlDate(CmpDateUtil.getMaxEndDate()) :
  62. CmpDateUtil.toSqlDate(entryInfo.getLeffectDate()));
  63. paramList.add(billInfo.getHrOrgUnit().getId().toString());
  64. paramList.add("01");
  65. paramList.add(Integer.valueOf(10));
  66. paramList.add(Integer.valueOf((null == entryInfo.getBillState()) ? 0 : entryInfo
  67. .getBillState().getValue()));
  68. if (billInfo.getIsSsc() != SscTypeEnum.DISTRIBUTE) {
  69. paramList.add(Integer.valueOf(1));
  70. } else {
  71. paramList.add(Integer.valueOf((entryInfo.getDealStatus() == null) ? 1 : entryInfo.getDealStatus().getValue()));
  72. }
  73. afterAssembleInsertFixColumn(entryInfo, paramList);
  74. // start xiaoxin
  75. List<Object> baseParamList = Lists.newArrayList(paramList);
  76. addListValue(baseParamList, entryInfo);
  77. addListValue(paramList, entryInfo);
  78. // end
  79. baseParamArrayList.add(baseParamList.toArray());
  80. assembleDynamicColumn(entryInfo, paramList, entryTableAttrs);
  81. paramArrayList.add(paramList.toArray());
  82. }
  83. private void assembleUpdateParamList(Context ctx, BatchSubmitShemeBillEntryInfo entryInfo, BatchSubmitShemeBillInfo billInfo, IntegrateEntryTableAttrs entryTableAttrs, List<Object[]> baseParamArrayList, List<Object[]> paramArrayList) {
  84. List<Object> updateParamList = Lists.newArrayList();
  85. updateParamList.add(getUserId(ctx));
  86. updateParamList.add(new Timestamp(System.currentTimeMillis()));
  87. updateParamList.add(getEffectDate(entryInfo));
  88. updateParamList.add((entryInfo.getOrgUnit() == null) ? null : entryInfo.getOrgUnit().getId().toString());
  89. updateParamList.add((entryInfo.getPerson() == null) ? null : entryInfo.getPerson().getId().toString());
  90. updateParamList.add((entryInfo.getAdminOrgUnit() == null) ? null : entryInfo.getAdminOrgUnit().getId().toString());
  91. updateParamList.add((entryInfo.getPosition() == null) ? null : entryInfo.getPosition().getId().toString());
  92. updateParamList.add((entryInfo.getCmpEmpORelation() == null) ? null : entryInfo.getCmpEmpORelation().getId().toString());
  93. updateParamList.add((entryInfo.getSubmitElement() == null) ? null : entryInfo.getSubmitElement().getId().toString());
  94. updateParamList.add((entryInfo.getCurrency() == null) ? CmpCurrencyHelper.getCNYCurrencyId() : entryInfo.getCurrency().getId().toString());
  95. updateParamList.add(entryInfo.getDescription(LocaleUtils.locale_l1));
  96. updateParamList.add(entryInfo.getDescription(LocaleUtils.locale_l2));
  97. updateParamList.add(entryInfo.getDescription(LocaleUtils.locale_l3));
  98. updateParamList.add((entryInfo.getLeffectDate() == null) ?
  99. CmpDateUtil.toSqlDate(CmpDateUtil.getMaxEndDate()) : entryInfo.getLeffectDate());
  100. if (billInfo.getIsSsc() != SscTypeEnum.DISTRIBUTE) {
  101. updateParamList.add(Integer.valueOf(1));
  102. } else {
  103. updateParamList.add(Integer.valueOf((entryInfo.getDealStatus() == null) ? 1 : entryInfo.getDealStatus().getValue()));
  104. }
  105. afterAssembleUpdateFixColumn(entryInfo, updateParamList);
  106. List<Object> updateBaseParamList = Lists.newArrayList(updateParamList);
  107. // start xiaoxin
  108. addListValue(updateBaseParamList, entryInfo);
  109. addListValue(updateParamList, entryInfo);
  110. // end
  111. updateBaseParamList.add(entryInfo.getId().toString());
  112. baseParamArrayList.add(updateBaseParamList.toArray());
  113. assembleDynamicColumn(entryInfo, updateParamList, entryTableAttrs);
  114. updateParamList.add(entryInfo.getId().toString());
  115. paramArrayList.add(updateParamList.toArray());
  116. }
  117. protected Date getEffectDate(BatchSubmitShemeBillEntryInfo entryInfo) {
  118. Date effectDate = entryInfo.getEffectDate();
  119. if (effectDate != null)
  120. return CmpDateUtil.toSqlDate(effectDate);
  121. return CmpDateUtil.toSqlDate(entryInfo.get("effectday"));
  122. }
  123. protected void assembleDynamicColumn(BatchSubmitShemeBillEntryInfo entryInfo, List<Object> paramList, IntegrateEntryTableAttrs entryTableAttrs) {
  124. int index = 0;
  125. for (String colName : entryTableAttrs.getColNames()) {
  126. String dataType = entryTableAttrs.getColTypes().get(index++);
  127. int dataLength = ((Integer)entryTableAttrs.getDataLength().get(colName)).intValue();
  128. Object object = entryInfo.get(colName);
  129. if (object != null && object.toString().trim().length() > 0 && "2"
  130. .equals(dataType)) {
  131. String datestr = object.toString();
  132. try {
  133. Date date = this.dateFormat.parse(datestr);
  134. paramList.add(new Date(date.getTime()));
  135. } catch (ParseException e) {
  136. logger.error(e.getMessage(), e);
  137. paramList.add(null);
  138. }
  139. continue;
  140. }
  141. if (object != null && object.toString().trim().length() > 0 && "1"
  142. .equals(dataType) && object.toString().length() > dataLength) {
  143. paramList.add(object.toString().substring(0, dataLength));
  144. continue;
  145. }
  146. paramList.add("0E-10".equals(object) ? "0.00" : object);
  147. }
  148. }
  149. protected void _saveOrUpdateEntries(Context ctx, BatchSubmitShemeBillInfo billInfo) throws BOSException, EASBizException {
  150. String submitSchemeId = billInfo.getSubmitScheme().getId().toString();
  151. IntegrateEntryTableAttrs entryTableAttrs = CmpIntegrateEntryHelper.getIntegrateEntryTableAttrs(ctx, submitSchemeId);
  152. BatchSubmitShemeBillEntryCollection coll = billInfo.getEntry();
  153. List<Object[]> updateBaseParamArrayList = Lists.newArrayList();
  154. List<Object[]> updateParamArrayList = Lists.newArrayList();
  155. List<Object[]> insertBaseParamArrayInsertList = Lists.newArrayList();
  156. List<Object[]> insertParamArrayList = Lists.newArrayList();
  157. for (int i = 0; i < coll.size(); i++) {
  158. BatchSubmitShemeBillEntryInfo entryInfo = coll.get(i);
  159. if (entryInfo.getId() != null) {
  160. assembleUpdateParamList(ctx, entryInfo, billInfo, entryTableAttrs, updateBaseParamArrayList, updateParamArrayList);
  161. } else {
  162. assembleSaveParamList(ctx, entryInfo, billInfo, entryTableAttrs, insertBaseParamArrayInsertList, insertParamArrayList);
  163. }
  164. }
  165. batchUpdateEntries(ctx, billInfo, entryTableAttrs, updateBaseParamArrayList, updateParamArrayList);
  166. batchSaveEntries(ctx, billInfo, entryTableAttrs, insertBaseParamArrayInsertList, insertParamArrayList);
  167. }
  168. protected void batchSaveEntries(Context ctx, BatchSubmitShemeBillInfo billInfo, IntegrateEntryTableAttrs entryTableAttrs, List<Object[]> baseParamArrayList, List<Object[]> paramArrayList) throws BOSException {
  169. if (!paramArrayList.isEmpty()) {
  170. String insertBaseSql = getInsertBaseEntryPrepareSql();
  171. String insertSql = getInsertEntryPrepareSql(entryTableAttrs.getTableName(), entryTableAttrs.getColNames(), false);
  172. CmpSQLUtil.executeBatch(ctx, insertBaseSql, baseParamArrayList);
  173. CmpSQLUtil.executeBatch(ctx, insertSql, paramArrayList);
  174. }
  175. }
  176. protected void batchUpdateEntries(Context ctx, BatchSubmitShemeBillInfo billInfo, IntegrateEntryTableAttrs entryTableAttrs, List<Object[]> baseParamArrayList, List<Object[]> paramArrayList) throws BOSException, EASBizException {
  177. if (!paramArrayList.isEmpty()) {
  178. String updateBaseSql = getUpdateBaseSql();
  179. String updateSql = getUpdateSql(entryTableAttrs.getTableName(), entryTableAttrs.getColNames(), false);
  180. CmpSQLUtil.executeBatch(ctx, updateBaseSql, baseParamArrayList);
  181. CmpSQLUtil.executeBatch(ctx, updateSql, paramArrayList);
  182. }
  183. }
  184. protected List<String> getInsertFixColumnNames() {
  185. return Lists.newArrayList(new String[] {
  186. "FID", "FBillID", "FCreatorID", "FCreateTime", "FEffectDate", "FOrgUnitID", "FPersonID", "FAdminOrgUnitID", "FPositionID", "FCmpEmpORelationID",
  187. "FSubmitElementID", "FCurrencyID", "FDescription_l1", "FDescription_l2", "FDescription_l3", "FLeffectDate", "FHrOrgUnitID", "FCalState", "FIsCal", "FBillState",
  188. "FDealStatus" });
  189. }
  190. protected void afterAssembleInsertFixColumn(BatchSubmitShemeBillEntryInfo entryInfo, List<Object> paramList) {}
  191. protected List<String> getUpdateFixColumnNames() {
  192. return Lists.newArrayList(new String[] {
  193. "FLastUpdateUserID", "FLastUpdateTime", "FEffectDate", "FOrgUnitID", "FPersonID", "FAdminOrgUnitID", "FPositionID", "FCmpEmpORelationID", "FSubmitElementID", "FCurrencyID",
  194. "FDescription_l1", "FDescription_l2", "FDescription_l3", "FLeffectDate", "FDealStatus" });
  195. }
  196. protected void afterAssembleUpdateFixColumn(BatchSubmitShemeBillEntryInfo entryInfo, List<Object> paramList) {}
  197. protected String getInsertBaseEntryPrepareSql() {
  198. return getInsertEntryPrepareSql(null, null, true);
  199. }
  200. protected String getInsertEntryPrepareSql(String dynamicEntryTable, List<String> submitItemColumnNames, boolean isBase) {
  201. String entryTableName, submitItemKeys = "";
  202. String submitItemvalues = "";
  203. if (isBase) {
  204. entryTableName = "T_HR_SchemeBillEntry";
  205. } else {
  206. entryTableName = dynamicEntryTable;
  207. submitItemKeys = "," + StringUtils.join(submitItemColumnNames, ",");
  208. submitItemvalues = submitItemKeys.replaceAll("[Ss]{1}\\d{1,4}", "?");
  209. }
  210. List<String> fixColumnNames = getInsertFixColumnNames();
  211. // start xiaoxin
  212. //if(isBase){
  213. addListParam(fixColumnNames);
  214. //}
  215. // end
  216. String fixColumnKeys = StringUtils.join(fixColumnNames, ",");
  217. String fixColumnValues = fixColumnKeys.replaceAll("\\w+", "?");
  218. return "INSERT INTO " + entryTableName + " (" + fixColumnKeys + submitItemKeys + ") VALUES (" + fixColumnValues + submitItemvalues + ")";
  219. }
  220. protected String getUpdateBaseSql() {
  221. return getUpdateSql(null, null, true);
  222. }
  223. protected String getUpdateSql(String dynamicEntryTable, List<String> submitItemColumnNames, boolean isBase) {
  224. String entryTableName;
  225. if (isBase) {
  226. entryTableName = "T_HR_SchemeBillEntry";
  227. } else {
  228. entryTableName = dynamicEntryTable;
  229. }
  230. StringBuilder updateSql = new StringBuilder("UPDATE %s SET ");
  231. List<String> updateColumnNames = getUpdateFixColumnNames();
  232. // start xiaoxin
  233. //if(isBase){
  234. addListParam(updateColumnNames);
  235. //}
  236. // end
  237. if (submitItemColumnNames != null) {
  238. updateColumnNames.addAll(submitItemColumnNames);
  239. }
  240. List<String> setSqlColumnList = Lists.newArrayList();
  241. for (String columnName : updateColumnNames) {
  242. setSqlColumnList.add(columnName + "=?");
  243. }
  244. updateSql.append(StringUtils.join(setSqlColumnList.toArray(), ","));
  245. updateSql.append(" WHERE fid=?");
  246. return String.format(updateSql.toString(), new Object[] { entryTableName });
  247. }
  248. protected String getUserId(Context ctx) {
  249. if (this.userId == null)
  250. this.userId = HRFilterUtils.getCurrentUserId(ctx);
  251. return this.userId;
  252. }
  253. /**
  254. * 添加自定义字段
  255. * @param list
  256. */
  257. protected void addListParam(List<String> list) {
  258. //直属上级ID
  259. list.add("CFSuperiorID");
  260. //直属上级名称
  261. list.add("CFSuperiorName");
  262. //时薪
  263. list.add("cfhourlyWage");
  264. //开始时间
  265. list.add("cfstartTime");
  266. //结束时间
  267. list.add("cfendTime");
  268. //休息开始时间
  269. list.add("cfrestStartTime");
  270. //休息结束时间
  271. list.add("cfrestEndTime");
  272. //说明
  273. list.add("cfexplain");
  274. //总工时
  275. list.add("cftotalWorkHours");
  276. //总金额
  277. list.add("cftotalAmount");
  278. //合同开始日期
  279. list.add("CFBeginContractDate");
  280. //合同结束日期
  281. list.add("CFEndContractDate");
  282. //备注
  283. list.add("CFRemark");
  284. }
  285. /**
  286. * 给自定义字段赋值
  287. * @param list
  288. * @param entryInfo
  289. */
  290. protected void addListValue(List<Object> list, BatchSubmitShemeBillEntryInfo entryInfo) {
  291. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  292. // if(entryInfo.get("superiorId")!=null) {
  293. // list.add(((PersonInfo)entryInfo.get("superior")).getId().toString());
  294. // }else {
  295. // list.add("");
  296. // }
  297. //直属上级ID
  298. list.add(entryInfo.getString("superiorId"));
  299. //直属上级名称
  300. list.add(entryInfo.getString("superiorName"));
  301. //时薪
  302. list.add(entryInfo.get("hourlyWage"));
  303. // list.add(sdf.format(entryInfo.getDate("startTime")));
  304. // list.add(sdf.format(entryInfo.getDate("endTime")));
  305. //开始时间 -- 格式化成字符串保存,避免只保存年月日
  306. if(StringUtils.isNotBlank(entryInfo.getString("startTime"))) {
  307. list.add(sdf.format(entryInfo.getDate("startTime")));
  308. }else {
  309. list.add(null);
  310. }
  311. //结束时间
  312. if(StringUtils.isNotBlank(entryInfo.getString("endTime"))) {
  313. list.add(sdf.format(entryInfo.getDate("endTime")));
  314. }else {
  315. list.add(null);
  316. }
  317. //休息开始时间
  318. if(StringUtils.isNotBlank(entryInfo.getString("restStartTime"))) {
  319. list.add(sdf.format(entryInfo.getDate("restStartTime")));
  320. }else {
  321. list.add(null);
  322. }
  323. //休息结束时间
  324. if(StringUtils.isNotBlank(entryInfo.getString("restEndTime"))) {
  325. list.add(sdf.format(entryInfo.getDate("restEndTime")));
  326. }else {
  327. list.add(null);
  328. }
  329. //说明
  330. list.add(entryInfo.getString("explain"));
  331. //总工时
  332. list.add(entryInfo.get("totalWorkHours"));
  333. //总金额
  334. list.add(entryInfo.get("totalAmount"));
  335. //合同开始日期
  336. if(StringUtils.isNotBlank(entryInfo.getString("beginContractDate"))) {
  337. list.add(sdf.format(entryInfo.getDate("beginContractDate")));
  338. }else {
  339. list.add(null);
  340. }
  341. //合同结束日期
  342. if(StringUtils.isNotBlank(entryInfo.getString("endContractDate"))) {
  343. list.add(sdf.format(entryInfo.getDate("endContractDate")));
  344. }else {
  345. list.add(null);
  346. }
  347. //备注
  348. list.add(entryInfo.getString("remark"));
  349. }
  350. }