|
|
@@ -0,0 +1,144 @@
|
|
|
+package com.usoftchina.uas.office.dingtalk.service;
|
|
|
+
|
|
|
+import com.dingtalk.api.response.OapiAlitripBtripApplySearchResponse;
|
|
|
+import com.usoftchina.dingtalk.sdk.OaSdk;
|
|
|
+import com.usoftchina.uas.office.service.AbstractService;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.dao.DataAccessException;
|
|
|
+import org.springframework.jdbc.core.CallableStatementCallback;
|
|
|
+import org.springframework.jdbc.core.CallableStatementCreator;
|
|
|
+import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
+import org.springframework.jdbc.support.rowset.SqlRowSet;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
+
|
|
|
+import java.sql.CallableStatement;
|
|
|
+import java.sql.Connection;
|
|
|
+import java.sql.SQLException;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+@Service
|
|
|
+public class UasOaService extends AbstractService {
|
|
|
+ //创建序列
|
|
|
+ static final String CREATE_SEQ = "CREATE SEQUENCE ? MINVALUE 1 MAXVALUE 99999999999 INCREMENT BY 1 START WITH 3000 CACHE 20 NOORDER NOCYCLE ";
|
|
|
+ @Autowired
|
|
|
+ protected JdbcTemplate jdbcTemplate;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private OaSdk oaSdk;
|
|
|
+
|
|
|
+ public void saveOa(int id){
|
|
|
+ SqlRowSet rs = jdbcTemplate.queryForRowSet("select od_id,od_kind,to_char(od_startdate,'yyyy-MM-dd hh24:mi:ss') startdate,to_char(od_enddate,'yyyy-MM-dd hh24:mi:ss') enddate from OaDingTalklog where od_id=" + id);
|
|
|
+ while (rs.next()){
|
|
|
+ String odKind = rs.getString("od_kind");
|
|
|
+ String startdate = rs.getString("startdate");
|
|
|
+ String enddate = rs.getString("enddate");
|
|
|
+ if ("出差申请单".equals(odKind)){
|
|
|
+ saveAlitripList("Uas", startdate, enddate, 1, 50);
|
|
|
+ } else if ("".equals(odKind)) {
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 保存出差申请
|
|
|
+ */
|
|
|
+ public void saveAlitripList(String agentCode, String startTime, String endTime, long offset, long limit) {
|
|
|
+ List<OapiAlitripBtripApplySearchResponse.OpenApplyRs> alitripList = oaSdk.getAllAlitrip(agentCode,startTime,endTime,offset,limit);
|
|
|
+ if (!CollectionUtils.isEmpty(alitripList)) {
|
|
|
+ for (OapiAlitripBtripApplySearchResponse.OpenApplyRs openApplyRs:alitripList) {
|
|
|
+ int id = getSeqId("FEEPLEASE_SEQ");
|
|
|
+ String code = callProcedure("Sp_GetMaxNumber", new Object[]{"FeePlease!CCSQ!new", 2});
|
|
|
+ SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
+ String inDate = format.format(openApplyRs.getGmtCreate());
|
|
|
+ List<OapiAlitripBtripApplySearchResponse.OpenItineraryInfo> itineraryList = openApplyRs.getItineraryList();
|
|
|
+ String startDate = format.format(itineraryList.get(0).getDepDate());
|
|
|
+ String endDate = format.format(itineraryList.get(0).getArrDate());
|
|
|
+ Long rsId = openApplyRs.getId();
|
|
|
+ SqlRowSet rowSet = jdbcTemplate.queryForRowSet("select * from FeePlease where dp_ddid=" + rsId);
|
|
|
+ if (!rowSet.next()) {
|
|
|
+ jdbcTemplate.execute("insert into FeePlease (fp_id,fp_code,fp_v9,FP_PEOPLE2,fp_recordman,fp_recorddate,fp_statuscode,fp_status,fp_v3,fp_prestartdate,fp_preenddate,fp_n6,) " +
|
|
|
+ "values (" + id + ",'" + code + "','" + openApplyRs.getDeptName() + "','" + openApplyRs.getUserName() + "','" + openApplyRs.getUserName() + "',to_date('" + inDate + "','yyyy-MM-dd HH:mi:ss'),'AUDITED','已审核','" + openApplyRs.getTripCause() + "',to_date('" + startDate + "','yyyy-MM-dd HH:mi:ss'),to_date('" + endDate + "','yyyy-MM-dd HH:mi:ss')," + openApplyRs.getTripDay() + ")");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取序列号
|
|
|
+ *
|
|
|
+ * @param seq
|
|
|
+ * 指定的序列名
|
|
|
+ */
|
|
|
+ private int getSeqId(String seq) {
|
|
|
+ try {
|
|
|
+ String sql = "select " + seq + ".nextval from dual";
|
|
|
+ SqlRowSet rs = jdbcTemplate.queryForRowSet(sql);
|
|
|
+ if (rs.next()) {
|
|
|
+ return rs.getInt(1);
|
|
|
+ } else {// 如果不存在就创建序列
|
|
|
+ SqlRowSet rowSet = jdbcTemplate.queryForRowSet("select * from user_sequences where Sequence_Name='" + seq.toUpperCase() + "'");
|
|
|
+ if (!rowSet.next()) {
|
|
|
+ jdbcTemplate.execute(CREATE_SEQ.replace("?", seq));
|
|
|
+ }
|
|
|
+ return getSeqId(seq);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ SqlRowSet rowSet = jdbcTemplate.queryForRowSet("select * from user_sequences where Sequence_Name='" + seq.toUpperCase() + "'");
|
|
|
+ if (!rowSet.next()) {
|
|
|
+ jdbcTemplate.execute(CREATE_SEQ.replace("?", seq));
|
|
|
+ }
|
|
|
+ return getSeqId(seq);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 调用存储过程
|
|
|
+ *
|
|
|
+ * @param procedureName
|
|
|
+ * 存储过程名称
|
|
|
+ * @param args
|
|
|
+ * 参数
|
|
|
+ * @return varchar类型结果
|
|
|
+ */
|
|
|
+ private String callProcedure(final String procedureName, final Object... args) {
|
|
|
+ try {
|
|
|
+ return jdbcTemplate.execute(new CallableStatementCreator() {
|
|
|
+ @Override
|
|
|
+ public CallableStatement createCallableStatement(Connection conn) throws SQLException {
|
|
|
+ StringBuffer storedProcName = new StringBuffer("{call ");
|
|
|
+ int i = 0;
|
|
|
+ storedProcName.append(procedureName + "(");
|
|
|
+ for (i = 0; i < args.length; i++) {
|
|
|
+ if (storedProcName.toString().contains("?")) {
|
|
|
+ storedProcName.append(",");
|
|
|
+ }
|
|
|
+ storedProcName.append("?");
|
|
|
+ }
|
|
|
+ if (storedProcName.toString().contains("?")) {
|
|
|
+ storedProcName.append(",");
|
|
|
+ }
|
|
|
+ storedProcName.append("?");
|
|
|
+ storedProcName.append(")}");
|
|
|
+ CallableStatement cs = conn.prepareCall(storedProcName.toString());
|
|
|
+ for (i = 0; i < args.length; i++) {
|
|
|
+ cs.setObject(i + 1, args[i]);
|
|
|
+ }
|
|
|
+ cs.registerOutParameter(args.length + 1, java.sql.Types.VARCHAR);
|
|
|
+ return cs;
|
|
|
+ }
|
|
|
+ }, new CallableStatementCallback<String>() {
|
|
|
+ @Override
|
|
|
+ public String doInCallableStatement(CallableStatement cs) throws SQLException, DataAccessException {
|
|
|
+ cs.execute();
|
|
|
+ return cs.getString(args.length + 1);
|
|
|
+ }
|
|
|
+
|
|
|
+ });
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.getMessage();
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+}
|