FormDaoImpl.java 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802
  1. package com.yw.bpm.form.dao;
  2. import java.io.IOException;
  3. import java.sql.PreparedStatement;
  4. import java.sql.ResultSet;
  5. import java.sql.SQLException;
  6. import java.util.ArrayList;
  7. import java.util.Date;
  8. import java.util.List;
  9. import java.util.Map;
  10. import javax.annotation.Resource;
  11. import org.apache.commons.fileupload.FileItem;
  12. import org.springframework.dao.DataAccessException;
  13. import org.springframework.jdbc.core.JdbcTemplate;
  14. import org.springframework.jdbc.core.PreparedStatementSetter;
  15. import org.springframework.jdbc.core.RowMapper;
  16. import com.yw.core.common.BaseDao;
  17. import com.yw.core.framework.view.service.PagerService;
  18. import com.yw.core.utils.CommonUtil;
  19. import com.yw.core.utils.StringUtil;
  20. import com.yw.eu.base.system.model.UploadFile;
  21. import com.yw.bpm.form.dao.FormDaoImpl.FormElementMapperAddBDDZ;
  22. import com.yw.bpm.form.model.FormElement;
  23. import com.yw.bpm.form.model.FormInfo;
  24. import com.yw.bpm.form.model.FormInfopath;
  25. import com.yw.bpm.instance.model.GenFile;
  26. import com.yw.bpm.system.constant.ExceptionDefine;
  27. import com.yw.bpm.system.util.SpringUtil;
  28. public class FormDaoImpl extends BaseDao implements FormDao {
  29. @Resource
  30. private PagerService pagerService;
  31. @Resource
  32. private JdbcTemplate jdbcTemplate;
  33. private StringBuffer standardSqlForFormInfo = new StringBuffer("select ").append("t.l_form_id, t.l_form_vid, t.v_form_name, ").append("t.l_file_id, t.n_version, t.v_creator, b.name, ")
  34. .append("t.d_createdate, t.n_state, c.v_data_name as v_state_name, ").append("t.v_table, t.v_html, ").append("t.v_remark, t.n_has_gen, a.v_data_name as n_has_gen_name, ")
  35. .append("t.n_is_create, s.groupname, t.v_dept, ").append("t.n_savetype, d.v_data_name as n_savetype_name,count(e.l_ins_id) as flowCount ").append("from bpm_form_info t ")
  36. .append("left join t_group s on t.v_dept=s.universalid ").append("left join bpm_data a on t.n_has_gen=a.n_value and a.v_data_field='n_has_gen' and a.v_data_table='form_info' ")
  37. .append("left join t_user b on t.v_creator=b.universalid ").append("left join bpm_data c on t.n_state=c.n_value and c.v_data_table='form_info' and c.v_data_field='n_state' ")
  38. .append("left join bpm_data d on t.n_savetype=d.n_value and d.v_data_field='n_savetype' and d.v_data_table='form_info' ")
  39. .append("left join bpm_flow_instance e on t.l_form_id=e.l_form_id and e.n_state=1 ");
  40. private StringBuffer standardSqlForFormElement = new StringBuffer("select ")
  41. .append("t.l_form_id, t.n_version, t.v_element_name, t.v_element_code, ")
  42. .append("t.v_table_field, t.n_field_type, t.v_field_validate, t.v_sum_field, t.v_search_field, ")
  43. .append("t.l_element_id, ")
  44. .append("t.n_type_detail, t.n_long, t.n_is_group, ")
  45. .append("t.l_group_id, t.n_type,c.v_data_name ")
  46. .append("from bpm_form_element t ")
  47. .append("left join bpm_data c on t.n_field_type=c.n_value and c.v_data_table='form_element' and c.v_data_field='n_field_type' ");
  48. @Override
  49. public int changeStateOfFormInfo(FormInfo form) {
  50. String sql = "update bpm_form_info set n_state=? where l_form_id=?";
  51. List<Object> conditionList = new ArrayList<Object>();
  52. conditionList.add(form.getState().getValue());
  53. conditionList.add(form.getFormId());
  54. return jdbcTemplate.update(sql, conditionList.toArray());
  55. }
  56. @SuppressWarnings("rawtypes")
  57. @Override
  58. public List getListOfFormInfoForPage(int p, int pSize, Map<String, String> conditions) throws SQLException, Exception {
  59. String sql = this.standardSqlForFormInfo.toString() + "where 1=1 and t.n_state not in(2,3) ";
  60. StringBuffer sqlBuffer = new StringBuffer(sql);
  61. List<Object> conditionList = new ArrayList<Object>();
  62. if (conditions.get("formName") != null && !"".equals(conditions.get("formName"))) {
  63. conditionList.add("%" + conditions.get("formName") + "%");
  64. sqlBuffer.append(" and t.v_form_name like ?");
  65. }
  66. if (conditions.get("groupid") != null && !"".equals(conditions.get("groupid"))) {
  67. sqlBuffer.append(" and t.v_dept = ?");
  68. conditionList.add(conditions.get("groupid"));
  69. }
  70. sqlBuffer.append(" group by t.l_form_id order by t.n_state,t.d_createdate desc ");
  71. return pagerService.queryForList(p, pSize, sqlBuffer.toString(), conditionList, new FormInfoMapper());
  72. }
  73. @Override
  74. public int getCountOfFormInfoForPage(Map<String, String> conditions) {
  75. String sql = "select count(t.l_form_id) " + "from " + "bpm_form_info t " + "where 1=1 and t.n_state not in(2,3) ";
  76. StringBuffer sqlBuffer = new StringBuffer(sql);
  77. List<Object> conditionList = new ArrayList<Object>();
  78. if (conditions.get("formName") != null && !"".equals(conditions.get("formName"))) {
  79. conditionList.add("%" + conditions.get("formName") + "%");
  80. sqlBuffer.append(" and t.v_form_name like ?");
  81. }
  82. if (conditions.get("groupid") != null && !"".equals(conditions.get("groupid"))) {
  83. sqlBuffer.append(" and t.v_dept = ?");
  84. conditionList.add(conditions.get("groupid"));
  85. }
  86. return jdbcTemplate.queryForObject(sqlBuffer.toString(), conditionList.toArray(),Integer.class);
  87. }
  88. @Override
  89. public int createFormInfoPath(FormInfopath formInfopath) {
  90. String sql = "insert into bpm_form_infopath " + "(l_form_id, v_infopath_file, v_infopath_content, " + "v_path, l_finfopath_id)" + " values(?, ?, ?, ?, ?)";
  91. List<Object> conditionList = new ArrayList<Object>();
  92. conditionList.add(formInfopath.getFormId().getFormId());
  93. conditionList.add(formInfopath.getInfopathFile());
  94. conditionList.add(formInfopath.getInfopathContent());
  95. conditionList.add(formInfopath.getPath());
  96. conditionList.add(formInfopath.getFinfopathId());
  97. return jdbcTemplate.update(sql, conditionList.toArray());
  98. }
  99. @SuppressWarnings("rawtypes")
  100. @Override
  101. public List getListOfFormInfopathByFormId(String formId) {
  102. String sql = "select l_form_id, " + "v_infopath_file, " + "v_infopath_content, " + "l_finfopath_id, " + "v_path from bpm_form_infopath where l_form_id=?";
  103. return SpringUtil.springQueryForList(jdbcTemplate, sql, new Object[] { formId }, new FormInfopathMapper());
  104. }
  105. @Override
  106. public int createFormElement(FormElement element) {
  107. String sql = "insert into bpm_form_element " + "(l_form_id, n_version, v_element_name, v_element_code, " + "v_table_field, n_field_type, n_type, "// n_is_edit,
  108. + "n_type_detail,v_field_validate, l_element_id" + ", n_is_group, l_group_id)" + "values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
  109. return jdbcTemplate.update(sql, new Object[] { element.getFormId().getFormId(), element.getVesion(), element.getElementName(), element.getElementCode(), element.getTableField(),
  110. element.getFieldType().getValue(), element.getType().getValue(), element.getTypeDetail(), element.getFieldValidate(), element.getElementId(), element.getIsGroup(), element.getGroupId() });
  111. }
  112. @Override
  113. public int createFormElementForNewVersion(FormElement element) throws Exception {
  114. String sql = "insert into bpm_form_element " + "(l_form_id, n_version, v_element_name, v_element_code, " + "v_table_field, n_field_type, n_type, "// n_is_edit,
  115. + "v_field_validate, l_element_id" + ", n_is_group, l_group_id, n_long, n_type_detail,v_sum_field, v_search_field)" + "values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
  116. List<Object> conditionList = new ArrayList<Object>();
  117. conditionList.add(element.getFormId().getFormId());
  118. conditionList.add(element.getVesion());
  119. conditionList.add(element.getElementName());
  120. conditionList.add(element.getElementCode());
  121. conditionList.add(element.getTableField());
  122. conditionList.add(element.getFieldType().getValue());
  123. conditionList.add(element.getType().getValue());
  124. conditionList.add(element.getFieldValidate());
  125. conditionList.add(element.getElementId());
  126. conditionList.add(element.getIsGroup());
  127. conditionList.add(element.getGroupId());
  128. conditionList.add(element.getLength());
  129. conditionList.add(element.getTypeDetail());
  130. conditionList.add(element.getSumField());
  131. conditionList.add(element.getSearchFiled());
  132. return jdbcTemplate.update(sql, conditionList.toArray());
  133. }
  134. // @Override
  135. // public int createRepeatElement(Map<String, Object> element) {
  136. // String sql = "INSERT INTO bpm_form_element " + "(l_form_id, "
  137. // + "n_version, " + "v_element_name, " + "v_table_field, "
  138. // + "n_field_type, " + "n_type, " + "n_is_edit, "
  139. // + "v_field_validate, " + "n_is_group, " + "l_group_id, "
  140. // + "l_element_id" + ")" + "VALUES" + "(?, " + "?, " + "?, "
  141. // + "?, " + "?, ?, " + "?, " + "?, " + "?, ?, ?)";
  142. // return jdbcTemplate.update(
  143. // sql,
  144. // new Object[] { element.get("l_form_id"),
  145. // element.get("n_version"),
  146. // element.get("v_element_name"),
  147. // element.get("v_table_field"),
  148. // element.get("n_field_type"), element.get("n_type"),
  149. // element.get("n_is_edit"),
  150. // element.get("v_field_validate"),
  151. // element.get("n_is_group"), element.get("l_group_id"),
  152. // element.get("l_element_id") });
  153. // }
  154. @Override
  155. public int editFormElement(FormElement element) {
  156. String sql = "update bpm_form_element set " + "n_type = ?, " + "n_type_detail = ?,v_sum_field = ?,v_search_field = ?, " + "n_field_type = ?, n_long = ?, " + "v_element_name=? "
  157. + "where l_element_id = ? and n_version = ? ";
  158. List<Object> conditionList = new ArrayList<Object>();
  159. conditionList.add(element.getType().getValue());
  160. conditionList.add(element.getTypeDetail());
  161. conditionList.add(element.getSumField());
  162. conditionList.add(element.getSearchFiled());
  163. conditionList.add(element.getFieldType().getValue());
  164. conditionList.add(element.getLength());
  165. conditionList.add(element.getElementName());
  166. conditionList.add(element.getElementId());
  167. conditionList.add(element.getVesion());
  168. return jdbcTemplate.update(sql, conditionList.toArray());
  169. }
  170. @Override
  171. public int createFormInfo(FormInfo form) {
  172. String sql = "insert into bpm_form_info " + "(l_form_id, l_form_vid, v_form_name, " + "l_file_id, n_version, v_creator, " + "d_createdate, n_state, v_table, "
  173. + "v_html, v_remark, v_dept, n_is_create, n_has_gen, n_savetype" + ")" + "values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
  174. List<Object> conditionList = new ArrayList<Object>();
  175. conditionList.add(form.getFormId());
  176. conditionList.add(form.getFormVid());
  177. conditionList.add(form.getFormName());
  178. conditionList.add(form.getFileId().getUniversalid());
  179. conditionList.add(form.getVersion());
  180. conditionList.add(form.getCreator().getUserId());
  181. conditionList.add(new Date());
  182. conditionList.add(form.getState().getValue());
  183. // conditionList.add("oa_form_ins_" + form.getFormId()); 新版本沿用原来的表,不重新创建
  184. // 2015-04-22 cxx
  185. conditionList.add(form.getTable());
  186. conditionList.add(form.getHtml());
  187. conditionList.add(form.getRemark());
  188. conditionList.add(form.getDept().getGroupId());
  189. conditionList.add(form.getIsCreate().getValue()); // 表单是否创建沿用旧版本标识
  190. conditionList.add(form.getHasGen().getValue());
  191. conditionList.add(form.getSaveType().getValue());
  192. return jdbcTemplate.update(sql, conditionList.toArray());
  193. }
  194. @Override
  195. public int editFormInfo(FormInfo form) {
  196. String sql = "update bpm_form_info set " + "v_form_name = ?, n_state = ?, v_remark = ?, " + "n_is_create = ?, n_has_gen=?, v_dept = ?, n_version = ?, "
  197. + "l_file_id = ?, l_form_vid = ?, n_savetype = ? " + "where l_form_id = ?";
  198. List<Object> conditionList = new ArrayList<Object>();
  199. conditionList.add(form.getFormName());
  200. conditionList.add(form.getState().getValue());
  201. conditionList.add(form.getRemark());
  202. conditionList.add(form.getIsCreate().getValue());
  203. conditionList.add(form.getHasGen().getValue());
  204. conditionList.add(form.getDept().getGroupId());
  205. conditionList.add(form.getVersion());
  206. conditionList.add(form.getFileId().getUniversalid());
  207. conditionList.add(form.getFormVid());
  208. conditionList.add(form.getSaveType().getValue());
  209. conditionList.add(form.getFormId());
  210. return jdbcTemplate.update(sql, conditionList.toArray());
  211. }
  212. @Override
  213. public FormInfo getFormInfoById(String formId) {
  214. String sql = this.standardSqlForFormInfo.toString() + "where 1=1 and t.l_form_id=? group by t.l_form_id ";
  215. Object result = SpringUtil.springQueryForObject(jdbcTemplate, sql, new Object[] { formId }, new FormInfoMapper());
  216. if (result == null) {
  217. return new FormInfo();
  218. } else {
  219. return (FormInfo) result;
  220. }
  221. }
  222. @SuppressWarnings("rawtypes")
  223. @Override
  224. public List getListOfFormElementByConditions(Map<String, String> conditions) {
  225. String sql = this.standardSqlForFormElement.toString() + "where 1=1 ";
  226. StringBuffer sqlBuffer = new StringBuffer(sql);
  227. List<Object> conditionList = new ArrayList<Object>();
  228. if (conditions.get("formId") != null) {
  229. conditionList.add(conditions.get("formId"));
  230. sqlBuffer.append(" and t.l_form_id=?");
  231. }
  232. if (conditions.get("isGroup") != null) {
  233. conditionList.add(conditions.get("isGroup"));
  234. sqlBuffer.append(" and t.n_is_group=?");
  235. }
  236. if (conditions.get("groupId") != null) {
  237. conditionList.add(conditions.get("groupId"));
  238. sqlBuffer.append(" and t.l_group_id=?");
  239. }
  240. if (conditions.get("!type") != null) {
  241. conditionList.add(conditions.get("!type"));
  242. sqlBuffer.append(" and t.n_type!=?");
  243. }
  244. if (conditions.get("version") != null) {
  245. conditionList.add(conditions.get("version"));
  246. sqlBuffer.append(" and t.n_version=?");
  247. }
  248. if (conditions.get("element_ids") != null) {
  249. String element_ids = conditions.get("element_ids");
  250. Object[] inSql = CommonUtil.toInSql(element_ids);
  251. if (inSql == null)
  252. return new ArrayList<UploadFile>();
  253. Object[] params = (Object[]) inSql[1];
  254. sqlBuffer.append(" and t.l_element_id in (");
  255. sqlBuffer.append(inSql[0].toString() + ")");
  256. //
  257. for (Object element_id : (Object[]) inSql[1]) {
  258. conditionList.add(element_id);
  259. }
  260. }
  261. return SpringUtil.springQueryForList(jdbcTemplate, sqlBuffer.toString(), conditionList.toArray(), new FormElementMapper());
  262. }
  263. @SuppressWarnings("unchecked")
  264. @Override
  265. public List<String> getGroupIdOfFormElementByConditions(Map<String, String> conditions) {
  266. String sql = "select distinct t.l_group_id from bpm_form_element t " + "where 1=1";
  267. StringBuffer sqlBuffer = new StringBuffer(sql);
  268. List<Object> conditionList = new ArrayList<Object>();
  269. if (conditions.get("formId") != null) {
  270. conditionList.add(conditions.get("formId"));
  271. sqlBuffer.append(" and t.l_form_id=?");
  272. }
  273. if (conditions.get("isGroup") != null) {
  274. conditionList.add(conditions.get("isGroup"));
  275. sqlBuffer.append(" and t.n_is_group=?");
  276. }
  277. return SpringUtil.springQueryForList(jdbcTemplate, sqlBuffer.toString(), conditionList.toArray(), new RowMapper() {
  278. @Override
  279. public Object mapRow(ResultSet rs, int arg1) throws SQLException {
  280. return rs.getString("l_group_id");
  281. }
  282. });
  283. }
  284. @Override
  285. public FormElement getFormElementByConditions(Map<String, String> conditions) throws Exception {
  286. String sql = this.standardSqlForFormElement.toString() + "where 1=1";
  287. StringBuffer sqlBuffer = new StringBuffer(sql);
  288. List<Object> conditionList = new ArrayList<Object>();
  289. if (conditions.get("formId") != null) {
  290. conditionList.add(conditions.get("formId"));
  291. sqlBuffer.append(" and t.l_form_id=?");
  292. }
  293. if (conditions.get("elementCode") != null) {
  294. conditionList.add(conditions.get("elementCode"));
  295. sqlBuffer.append(" and t.v_element_code=?");
  296. }
  297. if (conditions.get("elementId") != null) {
  298. conditionList.add(conditions.get("elementId"));
  299. sqlBuffer.append(" and t.l_element_id=?");
  300. }
  301. if (conditions.get("version") != null) {
  302. conditionList.add(conditions.get("version"));
  303. sqlBuffer.append(" and t.n_version=?");
  304. }
  305. Object result = SpringUtil.springQueryForObject(jdbcTemplate, sqlBuffer.toString(), conditionList.toArray(), new FormElementMapper());
  306. if (result == null) {
  307. throw new Exception(ExceptionDefine.objectIsNull);
  308. } else {
  309. return (FormElement) result;
  310. }
  311. }
  312. @SuppressWarnings("rawtypes")
  313. @Override
  314. public List getListOfFormInfoForUnused(String deptId, String modelId) {
  315. String sql = this.standardSqlForFormInfo.toString() + "where 1=1 and t.n_state not in(1,2,3) " + "and t.l_form_id not in ("
  316. + " select s.l_form_id from bpm_flow_model s where s.l_model_id!=? and s.n_state!=-1)";
  317. StringBuffer sqlBuffer = new StringBuffer(sql);
  318. List<Object> conditionList = new ArrayList<Object>();
  319. conditionList.add(modelId);
  320. if (deptId != null && !"".equals(deptId)) {
  321. sqlBuffer.append(" and t.v_dept=?");
  322. conditionList.add(deptId);
  323. }
  324. sqlBuffer.append(" group by t.l_form_id ");
  325. return SpringUtil.springQueryForList(jdbcTemplate, sqlBuffer.toString(), conditionList.toArray(), new FormInfoMapper());
  326. }
  327. // @SuppressWarnings("unchecked")
  328. // @Override
  329. // public Map<String, Object> infoFormFlowElement(
  330. // Map<String, String> conditions) {
  331. // String sql = "SELECT "
  332. // + "t.l_form_id, "
  333. // + "t.l_model_id, "
  334. // + "t.l_tmodel_id, "
  335. // + "t.l_element_id, "
  336. // + "t.n_can_edit "
  337. // + "FROM bpm_form_element a "
  338. // +
  339. // "LEFT JOIN bpm_flow_form_element t ON a.l_element_id=t.l_element_id WHERE 1=1";
  340. // StringBuffer sqlBuffer = new StringBuffer(sql);
  341. // List<Object> conditionList = new ArrayList<Object>();
  342. // if (conditions.get("formId") != null) {
  343. // conditionList.add(conditions.get("formId"));
  344. // sqlBuffer.append(" AND t.l_form_id=?");
  345. // }
  346. // if (conditions.get("elementId") != null) {
  347. // conditionList.add(conditions.get("elementId"));
  348. // sqlBuffer.append(" AND t.l_element_id=?");
  349. // }
  350. // if (conditions.get("tmodelId") != null
  351. // && !"".equals(conditions.get("tmodelId"))) {
  352. // conditionList.add(conditions.get("tmodelId"));
  353. // sqlBuffer.append(" AND t.l_tmodel_id=?");
  354. // }
  355. // Map<String, Object> map = null;
  356. // try {
  357. // map = SpringUtil.springQueryForMap(jdbcTemplate,
  358. // sqlBuffer.toString(), conditionList.toArray());
  359. // } catch (Exception e) {
  360. // map = new HashMap<String, Object>();
  361. // }
  362. // return map;
  363. // }
  364. @Override
  365. public int getCountOfCanEditForElement(Map<String, String> conditions) {
  366. String sql = "select " + "count(n_can_edit) " + "from bpm_flow_form_element where 1=1";
  367. StringBuffer sqlBuffer = new StringBuffer(sql);
  368. List<Object> conditionList = new ArrayList<Object>();
  369. if (conditions.get("formId") != null) {
  370. conditionList.add(conditions.get("formId"));
  371. sqlBuffer.append(" and l_form_id=?");
  372. }
  373. if (conditions.get("elementId") != null) {
  374. conditionList.add(conditions.get("elementId"));
  375. sqlBuffer.append(" and l_element_id=?");
  376. }
  377. if (conditions.get("tmodelId") != null && !"".equals(conditions.get("tmodelId"))) {
  378. conditionList.add(conditions.get("tmodelId"));
  379. sqlBuffer.append(" and l_tmodel_id=?");
  380. }
  381. return jdbcTemplate.queryForObject(sqlBuffer.toString(), conditionList.toArray(),Integer.class);
  382. }
  383. @Override
  384. public int deleteFlowFormElement(String l_form_id, String l_tmodel_id) {
  385. String sql = "delete from bpm_flow_form_element where l_form_id=? and l_tmodel_id=?";
  386. return jdbcTemplate.update(sql, new Object[] { l_form_id, l_tmodel_id });
  387. }
  388. @Override
  389. public int createFlowFormElement(Map<String, String> ffElement) {
  390. String sql = "insert into bpm_flow_form_element (" + "l_form_id, " + "l_model_id, " + "l_tmodel_id, " + "l_element_id, " + "n_can_edit ) " + "values (? ,? ,? ,? ,?)";
  391. List<Object> conditionList = new ArrayList<Object>();
  392. conditionList.add(ffElement.get("l_form_id"));
  393. conditionList.add(ffElement.get("l_model_id"));
  394. conditionList.add(ffElement.get("l_tmodel_id"));
  395. conditionList.add(ffElement.get("l_element_id"));
  396. conditionList.add(ffElement.get("n_can_edit"));
  397. return jdbcTemplate.update(sql, conditionList.toArray());
  398. }
  399. @Override
  400. public int updateSql(String sql, List<Object> values) {
  401. return jdbcTemplate.update(sql, values.toArray());
  402. }
  403. @Override
  404. public int updateSqlForGen(String sql, final List<Object> values) {
  405. return jdbcTemplate.update(sql, new PreparedStatementSetter() {
  406. @Override
  407. public void setValues(PreparedStatement ps) throws SQLException {
  408. for (int i = 0; i < values.size(); i++) {
  409. Object obj = values.get(i);
  410. if (obj instanceof FileItem) {
  411. FileItem fi = (FileItem) obj;
  412. try {
  413. ps.setBinaryStream(i + 1, fi.getInputStream(), (int) fi.getSize());
  414. } catch (IOException e) {
  415. e.printStackTrace();
  416. }
  417. } else {
  418. ps.setObject(i + 1, obj);
  419. }
  420. }
  421. }
  422. });
  423. }
  424. @Override
  425. public GenFile getGenFileById(String formInsId) {
  426. String sql = "select t.l_form_id,t.l_form_ins_id,t.v_gen_file,t.v_gen_path from bpm_genfile t " + "where 1=1 and t.l_form_ins_id=?";
  427. Object result = SpringUtil.springQueryForObject(jdbcTemplate, sql, new Object[] { formInsId }, new GenFileMapper());
  428. if (result == null) {
  429. return null;
  430. } else {
  431. return (GenFile) result;
  432. }
  433. }
  434. @SuppressWarnings("rawtypes")
  435. @Override
  436. public List getListOfFormInfo(Map<String, String> conditions) {
  437. String sql = this.standardSqlForFormInfo.toString() + "where 1=1 and t.n_state not in(2,3) ";
  438. StringBuffer sqlBuffer = new StringBuffer(sql);
  439. List<Object> conditionList = new ArrayList<Object>();
  440. if (conditions.get("groupid") != null && !"".equals(conditions.get("groupid"))) {
  441. sqlBuffer.append(" and t.v_dept = ?");
  442. conditionList.add(conditions.get("groupid"));
  443. }
  444. sqlBuffer.append(" group by t.l_form_id ");
  445. return SpringUtil.springQueryForList(jdbcTemplate, sqlBuffer.toString(), conditionList.toArray(), new FormInfoMapper());
  446. }
  447. @Override
  448. public int getMaxFormVersionByFormVid(String formVid) {
  449. String sql = "select IFNULL(max(n_version),0) from bpm_form_info where l_form_vid = " + formVid;
  450. return jdbcTemplate.queryForObject(sql,Integer.class);
  451. }
  452. @SuppressWarnings("unchecked")
  453. @Override
  454. public List<FormInfo> getListOfFormInfoForOldVersion(Map<String, String> conditions) throws Exception {
  455. String sql = this.standardSqlForFormInfo.toString() + "where 1=1 ";
  456. StringBuffer sqlBuffer = new StringBuffer(sql);
  457. List<Object> conditionList = new ArrayList<Object>();
  458. if (conditions.get("groupid") != null && !"".equals(conditions.get("groupid"))) {
  459. sqlBuffer.append(" and t.v_dept = ?");
  460. conditionList.add(conditions.get("groupid"));
  461. }
  462. if (conditions.get("formVid") != null && !"".equals(conditions.get("formVid"))) {
  463. sqlBuffer.append(" and t.l_form_vid = ?");
  464. conditionList.add(conditions.get("formVid"));
  465. }
  466. if (conditions.get("state") != null && !"".equals(conditions.get("state"))) {
  467. sqlBuffer.append(" and t.n_state = ?");
  468. conditionList.add(conditions.get("state"));
  469. }
  470. sqlBuffer.append(" group by t.l_form_id ");
  471. return SpringUtil.springQueryForList(jdbcTemplate, sqlBuffer.toString(), conditionList.toArray(), new FormInfoMapper());
  472. }
  473. @Override
  474. public FormInfo getInUseFormInfoByVid(String formVid) {
  475. String sql = this.standardSqlForFormInfo.toString() + "where 1=1 and t.n_state not in(2,3) and t.l_form_vid=? group by t.l_form_id ";
  476. Object result = SpringUtil.springQueryForObject(jdbcTemplate, sql, new Object[] { formVid }, new FormInfoMapper());
  477. if (result == null) {
  478. return new FormInfo();
  479. } else {
  480. return (FormInfo) result;
  481. }
  482. }
  483. @Override
  484. public List getListOfFormInfoVersionForPage(int p, int pSize, Map<String, String> conditions) throws SQLException, Exception {
  485. String sql = this.standardSqlForFormInfo.toString() + "where 1=1 and t.n_state not in(3) ";
  486. StringBuffer sqlBuffer = new StringBuffer(sql);
  487. List<Object> conditionList = new ArrayList<Object>();
  488. if (conditions.get("formVid") != null && !"".equals(conditions.get("formVid"))) {
  489. sqlBuffer.append(" and t.l_form_vid = ?");
  490. conditionList.add(conditions.get("formVid"));
  491. }
  492. sqlBuffer.append(" group by t.l_form_id ");
  493. sqlBuffer.append(" order by t.n_state asc");
  494. if ("version".equals(conditions.get("sortname"))) {
  495. if ("asc".equals(conditions.get("sortorder"))) {
  496. sqlBuffer.append(",t.n_version asc");
  497. } else if ("desc".equals(conditions.get("sortorder"))) {
  498. sqlBuffer.append(",t.n_version desc");
  499. }
  500. } else if ("flowCount".equals(conditions.get("sortname"))) {
  501. if ("asc".equals(conditions.get("sortorder"))) {
  502. sqlBuffer.append(",flowcount asc");
  503. } else if ("desc".equals(conditions.get("sortorder"))) {
  504. sqlBuffer.append(",flowcount desc");
  505. }
  506. } else {
  507. sqlBuffer.append(",t.n_version desc");
  508. }
  509. return pagerService.queryForList(p, pSize, sqlBuffer.toString(), conditionList, new FormInfoMapper());
  510. }
  511. @Override
  512. public int getCountOfFormInfoVersionForPage(Map<String, String> conditions) {
  513. String sql = "select count(t.l_form_id) " + "from " + "bpm_form_info t " + "where 1=1 and t.n_state not in(3) ";
  514. StringBuffer sqlBuffer = new StringBuffer(sql);
  515. List<Object> conditionList = new ArrayList<Object>();
  516. if (conditions.get("formVid") != null && !"".equals(conditions.get("formVid"))) {
  517. sqlBuffer.append(" and t.l_form_vid = ?");
  518. conditionList.add(conditions.get("formVid"));
  519. }
  520. return jdbcTemplate.queryForObject(sqlBuffer.toString(), conditionList.toArray(),Integer.class);
  521. }
  522. @Override
  523. public int getCountOfDealingFlowByFormId(String formId) {
  524. String sql = "SELECT COUNT(t.l_ins_id) FROM bpm_flow_instance t WHERE t.n_state=1 AND t.l_form_id=" + formId;
  525. return jdbcTemplate.queryForObject(sql,Integer.class);
  526. }
  527. protected class FormInfoMapper implements RowMapper {
  528. @Override
  529. public Object mapRow(ResultSet rs, int arg1) throws SQLException {
  530. FormInfo formInfo = new FormInfo();
  531. formInfo.setFormId(rs.getString("l_form_id"));
  532. formInfo.setFormVid(rs.getString("l_form_vid"));
  533. formInfo.setFormName(rs.getString("v_form_name"));
  534. formInfo.getFileId().setUniversalid(rs.getString("l_file_id"));
  535. formInfo.setVersion(rs.getString("n_version"));
  536. formInfo.getCreator().setUserId(rs.getString("v_creator"));
  537. formInfo.getCreator().setUsername(rs.getString("name"));
  538. formInfo.getState().setDataName(rs.getString("v_state_name"));
  539. formInfo.getState().setValue(rs.getString("n_state"));
  540. formInfo.setCreatedate(rs.getTimestamp("d_createdate"));
  541. formInfo.setTable(rs.getString("v_table"));
  542. formInfo.setHtml(rs.getString("v_html"));
  543. formInfo.setRemark(rs.getString("v_remark"));
  544. formInfo.getHasGen().setValue(rs.getString("n_has_gen"));
  545. formInfo.getHasGen().setDataName(rs.getString("n_has_gen_name"));
  546. formInfo.getIsCreate().setValue(rs.getString("n_is_create"));
  547. formInfo.getDept().setGroupId(rs.getString("v_dept"));
  548. formInfo.getDept().setGroupName(rs.getString("groupname"));
  549. formInfo.getSaveType().setValue(rs.getString("n_savetype"));
  550. formInfo.getSaveType().setDataName(rs.getString("n_savetype_name"));
  551. formInfo.setFlowCount(rs.getString("flowCount"));
  552. return formInfo;
  553. }
  554. }
  555. protected class FormElementMapper implements RowMapper {
  556. @Override
  557. public Object mapRow(ResultSet rs, int arg1) throws SQLException {
  558. FormElement element = new FormElement();
  559. element.getFormId().setFormId(rs.getString("l_form_id"));
  560. element.setVesion(rs.getString("n_version"));
  561. element.setElementName(rs.getString("v_element_name"));
  562. element.setElementCode(rs.getString("v_element_code"));
  563. element.setTableField(rs.getString("v_table_field"));
  564. element.getFieldType().setValue(rs.getString("n_field_type"));
  565. element.setFieldValidate(rs.getString("v_field_validate"));
  566. element.setElementId(rs.getString("l_element_id"));
  567. element.getType().setValue(rs.getString("n_type"));
  568. element.setTypeDetail(rs.getString("n_type_detail"));
  569. element.setSumField(rs.getString("v_sum_field"));
  570. element.setSearchFiled(rs.getString("v_search_field"));
  571. element.setLength(rs.getString("n_long"));
  572. element.setIsGroup(rs.getString("n_is_group"));
  573. element.setGroupId(rs.getString("l_group_id"));
  574. element.getFieldType().setDataName(rs.getString("v_data_name"));
  575. return element;
  576. }
  577. }
  578. protected class FormInfopathMapper implements RowMapper {
  579. @Override
  580. public Object mapRow(ResultSet rs, int arg1) throws SQLException {
  581. FormInfopath infopath = new FormInfopath();
  582. infopath.getFormId().setFormId(rs.getString("l_form_id"));
  583. infopath.setInfopathFile(rs.getString("v_infopath_file"));
  584. infopath.getInfopathContent().append(rs.getString("v_infopath_content"));
  585. infopath.setFinfopathId(rs.getString("l_finfopath_id"));
  586. infopath.setPath(rs.getString("v_path"));
  587. return infopath;
  588. }
  589. }
  590. protected class GenFileMapper implements RowMapper {
  591. @Override
  592. public Object mapRow(ResultSet rs, int arg1) throws SQLException {
  593. GenFile genFile = new GenFile();
  594. genFile.setFormId(rs.getLong("l_form_id"));
  595. genFile.setFormInsId(rs.getLong("l_form_ins_id"));
  596. genFile.setGenFile(rs.getString("v_gen_file"));
  597. genFile.setGenPath(rs.getString("v_gen_path"));
  598. return genFile;
  599. }
  600. }
  601. @Override
  602. public PagerService getFormRecodPageList(int p, int pSize, Map<String, Object> conditions) throws SQLException, Exception {
  603. String formId = conditions.get("formId").toString();
  604. Object searchElementList = conditions.get("searchElementList"); // 查询条件
  605. FormInfo formInfo = this.getFormInfoById(formId);
  606. StringBuffer sb = new StringBuffer("SELECT fi.v_ins_name insName,fi.d_createdate createdate,foi.*,a.v_data_name as dataname FROM ");
  607. sb.append(formInfo.getTable());
  608. sb.append(" foi,bpm_flow_instance fi,bpm_data a,bpm_form_info fo ");
  609. sb.append(" where foi.l_form_ins_id = fi.l_form_ins_id");
  610. sb.append(" and fi.n_state = a.n_value AND a.v_data_module = 'ins' AND a.v_data_field = 'n_state'");
  611. sb.append(" and fo.l_form_id = ? ");
  612. sb.append(" and fo.l_form_vid = ? ");
  613. sb.append(" and fi.v_creator = ? ");
  614. sb.append(" and fi.n_state not in(0,4) ");// 过去撤销和删除的流程
  615. List<Object> params = new ArrayList();
  616. params.add(formId);
  617. params.add(formInfo.getFormVid());
  618. params.add(conditions.get("userId"));
  619. if (searchElementList != null) {
  620. for (FormElement searchElement : (List<FormElement>) searchElementList) {
  621. sb.append(" and foi." + searchElement.getTableField() + " = ? ");
  622. params.add(conditions.get(searchElement.getTableField()));
  623. }
  624. }
  625. if (conditions.get("insname") != null) { // 获取流程标题
  626. String insname = conditions.get("insname").toString();
  627. if (!StringUtil.isEmpty(insname)) {
  628. sb.append(" and fi.v_ins_name like ? ");
  629. params.add("%" + insname + "%");
  630. }
  631. }
  632. sb.append(" order by fi.d_createdate desc");
  633. PagerService ps = getPagerService();
  634. ps.queryPageForList(p, pSize, sb.toString(), params);
  635. return ps;
  636. }
  637. @Override
  638. public Map getSumFiled(Map<String, Object> conditions) {
  639. String formId = conditions.get("formId").toString();
  640. FormInfo formInfo = this.getFormInfoById(formId);
  641. StringBuffer sb = new StringBuffer("SELECT sum(foi." + conditions.get("sumField") + ") allTotal FROM ");
  642. // SELECT fi.v_ins_name,fo.* FROM `oa_form_ins_6486064572673`
  643. // fo,bpm_flow_instance fi where fo.l_form_ins_id = fi.l_form_ins_id and
  644. // fi.l_form_id =6486064572673 ORDER BY fi.d_createdate desc;
  645. Object searchElementList = conditions.get("searchElementList"); // 查询条件
  646. sb.append(formInfo.getTable());
  647. sb.append(" foi,bpm_flow_instance fi,bpm_form_info fo ");
  648. sb.append(" where foi.l_form_ins_id = fi.l_form_ins_id");
  649. sb.append(" and fo.l_form_id = ? ");
  650. sb.append(" and fo.l_form_vid = ? ");
  651. sb.append(" and fi.v_creator = ? ");
  652. sb.append(" and fi.n_state not in(0,4) ");// 过去撤销和删除的流程
  653. List<Object> params = new ArrayList();
  654. params.add(formId);
  655. params.add(formInfo.getFormVid());
  656. params.add(conditions.get("userId"));
  657. if (searchElementList != null) {
  658. for (FormElement searchElement : (List<FormElement>) searchElementList) {
  659. sb.append(" and foi." + searchElement.getTableField() + " = ? ");
  660. params.add(conditions.get(searchElement.getTableField()));
  661. }
  662. }
  663. if (conditions.get("insname") != null) { // 获取流程标题
  664. String insname = conditions.get("insname").toString();
  665. if (!StringUtil.isEmpty(insname)) {
  666. sb.append(" and fi.v_ins_name like ? ");
  667. params.add("%" + insname + "%");
  668. }
  669. }
  670. sb.append(" order by fi.d_createdate desc");
  671. try {
  672. return jdbcTemplate.queryForMap(sb.toString(), params.toArray());
  673. } catch (DataAccessException e) {
  674. e.printStackTrace();
  675. return null;
  676. }
  677. }
  678. protected class FormElementMapperAddBDDZ implements RowMapper {
  679. @Override
  680. public Object mapRow(ResultSet rs, int arg1) throws SQLException {
  681. FormElement element = new FormElement();
  682. element.getFormId().setFormId(rs.getString("l_form_id"));
  683. element.setVesion(rs.getString("n_version"));
  684. element.setElementName(rs.getString("v_element_name"));
  685. element.setElementCode(rs.getString("v_element_code"));
  686. element.setTableField(rs.getString("v_table_field"));
  687. element.getFieldType().setValue(rs.getString("n_field_type"));
  688. element.setFieldValidate(rs.getString("v_field_validate"));
  689. element.setElementId(rs.getString("l_element_id"));
  690. element.getType().setValue(rs.getString("n_type"));
  691. element.setTypeDetail(rs.getString("n_type_detail"));
  692. element.setSumField(rs.getString("v_sum_field"));
  693. element.setSearchFiled(rs.getString("v_search_field"));
  694. element.setLength(rs.getString("n_long"));
  695. element.setIsGroup(rs.getString("n_is_group"));
  696. element.setGroupId(rs.getString("l_group_id"));
  697. element.getFieldType().setDataName(rs.getString("v_data_name"));
  698. element.setBddz(rs.getString("BDDZ"));
  699. element.setBddzText(rs.getString("BDDZText"));
  700. return element;
  701. }
  702. }
  703. @Override
  704. public List<FormElement> getListOfFormElementByConditionsAddBDDZ(Map<String, String> conditions) {
  705. String sql = " SELECT t.l_form_id,t.n_version,t.v_element_name, t.v_element_code,t.v_table_field,bf.n_is_edit_detail,"
  706. + " b.v_formula_name as BDDZ,b.v_formula_text AS BDDZText,t.n_field_type,t.v_field_validate, t.v_sum_field, t.v_search_field,t.l_element_id,"
  707. + " t.n_type_detail,t.n_long,t.n_is_group,t.l_group_id, t.n_type,c.v_data_name"
  708. + " FROM bpm_form_element t "
  709. + " LEFT JOIN bpm_data c ON t.n_field_type = c.n_value "
  710. + " AND c.v_data_table = 'form_element' AND c.v_data_field = 'n_field_type' "
  711. + " LEFT JOIN bpm_flow_form_element bf ON bf.l_element_id = t.l_element_id "
  712. + " LEFT JOIN bpm_form_formula b ON b.l_form_id = bf.l_form_id "
  713. + " AND b.l_form_id = t.l_form_id AND b.l_formula_id = bf.n_is_edit_detail "
  714. + " WHERE 1 = 1 "
  715. + " AND t.l_form_id = ?"
  716. + " AND t.n_is_group = ?"
  717. + " AND t.n_type != ?"
  718. + " AND bf.l_tmodel_id = ?"
  719. + " AND bf.n_state = 1 "
  720. + " ORDER BY t.sort is null,t.sort asc ";
  721. List<Object> conditionList = new ArrayList<Object>();
  722. conditionList.add(conditions.get("formId"));
  723. conditionList.add(conditions.get("isGroup"));
  724. conditionList.add(conditions.get("!type"));
  725. conditionList.add(conditions.get("tmodelId"));
  726. return SpringUtil.springQueryForList(jdbcTemplate, sql, conditionList.toArray(), new FormElementMapperAddBDDZ());
  727. }
  728. }