|
@@ -0,0 +1,294 @@
|
|
|
+package com.platform.service.qykh.impl;
|
|
|
+
|
|
|
+import com.github.pagehelper.Page;
|
|
|
+import com.platform.common.exception.BusinessException;
|
|
|
+import com.platform.common.exception.DeniedException;
|
|
|
+import com.platform.common.util.DateUtils;
|
|
|
+import com.platform.common.util.JsonUtils;
|
|
|
+import com.platform.common.util.StringUtils;
|
|
|
+import com.platform.dao.bean.MyVOPage;
|
|
|
+import com.platform.dao.vo.query.qykh.PlandetailsVO;
|
|
|
+import com.platform.dao.vo.query.qykh.ProductHelpVO;
|
|
|
+import com.platform.service.qykh.QykhPlanDetailsService;
|
|
|
+import com.platform.service.qykh.QykhProductHelpService;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import javax.sql.DataSource;
|
|
|
+import java.sql.Connection;
|
|
|
+import java.sql.ResultSet;
|
|
|
+import java.sql.SQLException;
|
|
|
+import java.sql.Statement;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+@Service("qykhProductHelpService")
|
|
|
+@Slf4j
|
|
|
+public class QykhProductHelpServiceImpl implements QykhProductHelpService {
|
|
|
+ @Resource
|
|
|
+ private DataSource qykhDataSource;
|
|
|
+
|
|
|
+ @Value("${qykh.product_help}")
|
|
|
+ private String info_table_name;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public MyVOPage<ProductHelpVO> selectPage(int pageNum, int pageSize, ProductHelpVO guaranteeInfoDTO) {
|
|
|
+ MyVOPage<ProductHelpVO> myVOPage = new MyVOPage<>();
|
|
|
+ myVOPage.setPageNum(pageNum);
|
|
|
+ myVOPage.setPageSize(pageSize);
|
|
|
+ Connection conn = null;
|
|
|
+ Statement stmt = null;
|
|
|
+ ResultSet rs = null;
|
|
|
+ StringBuffer querySql = new StringBuffer("select " +
|
|
|
+ "id," +
|
|
|
+ "title," +
|
|
|
+ "descr," +
|
|
|
+ "purl," +
|
|
|
+ "pid," +
|
|
|
+ "keywords," +
|
|
|
+ "ord," +
|
|
|
+ "digest," +
|
|
|
+ "time ");
|
|
|
+ StringBuffer countSql = new StringBuffer("select count(*) ");
|
|
|
+ StringBuffer sql = new StringBuffer(" from " + info_table_name + " where 1 = 1 ");
|
|
|
+ if (StringUtils.isNotBlank(guaranteeInfoDTO.getTitle())) {
|
|
|
+ sql.append("and title like '%" + guaranteeInfoDTO.getTitle() + "%' ");
|
|
|
+ }
|
|
|
+ sql.append(" order by time desc ");
|
|
|
+ try {
|
|
|
+ conn = qykhDataSource.getConnection();
|
|
|
+ stmt = conn.createStatement();
|
|
|
+ // 获取总条数
|
|
|
+ rs = stmt.executeQuery(countSql.append(sql).toString());
|
|
|
+ rs.next();
|
|
|
+ long total = rs.getLong(1);
|
|
|
+ Page page = new Page(pageNum, pageSize);
|
|
|
+ page.setTotal(total);
|
|
|
+ myVOPage.setPages(page.getPages());
|
|
|
+ myVOPage.setTotal(total);
|
|
|
+ if (total < 1) {
|
|
|
+ myVOPage.setRows(new ArrayList<ProductHelpVO>());
|
|
|
+ return myVOPage;
|
|
|
+ }
|
|
|
+ int startNum = (pageNum - 1) * pageSize;
|
|
|
+ sql.append("limit " + startNum + "," + pageSize);
|
|
|
+ rs = stmt.executeQuery(querySql.append(sql).toString());
|
|
|
+ // 封装数据
|
|
|
+ myVOPage.setRows(packageInfo(rs));
|
|
|
+ rs.close();
|
|
|
+ stmt.close();
|
|
|
+ conn.close();
|
|
|
+ return myVOPage;
|
|
|
+ } catch (SQLException e1) {
|
|
|
+ e1.printStackTrace();
|
|
|
+ throw new DeniedException("获取乾元数据库连接失败" + e1.getCause().getMessage());
|
|
|
+ } finally {
|
|
|
+ try {
|
|
|
+ if (rs != null) {
|
|
|
+ rs.close();
|
|
|
+ }
|
|
|
+ if (stmt != null) {
|
|
|
+ stmt.close();
|
|
|
+ }
|
|
|
+ if (conn != null) {
|
|
|
+ conn.close();
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void modModel(ProductHelpVO vo) {
|
|
|
+ Connection conn = null;
|
|
|
+ Statement stmt = null;
|
|
|
+ StringBuffer updateSql = new StringBuffer("update " + info_table_name + " set " +
|
|
|
+ "title='" + vo.getTitle() +
|
|
|
+ "',descr='" + vo.getDescr() +/*
|
|
|
+ "',purl='" + vo.getPurl() +
|
|
|
+ "',pid='" + vo.getPid()
|
|
|
+ "',digest='" + vo.getDigest() +
|
|
|
+ "',keywords='" + vo.getKeywords() +
|
|
|
+ "',ord='" + vo.getOrd() +
|
|
|
+ "',time='" + vo.getTime() +*/
|
|
|
+ "' where id='" + vo.getId() + "'");
|
|
|
+ log.info("更新数据:" + updateSql);
|
|
|
+ try {
|
|
|
+ conn = qykhDataSource.getConnection();
|
|
|
+ stmt = conn.createStatement();
|
|
|
+ // 获取总条数
|
|
|
+ int result = stmt.executeUpdate(updateSql.toString());
|
|
|
+ if (result != 1) {
|
|
|
+ throw new BusinessException("");
|
|
|
+ }
|
|
|
+ stmt.close();
|
|
|
+ conn.close();
|
|
|
+ } catch (SQLException e1) {
|
|
|
+ e1.printStackTrace();
|
|
|
+ throw new DeniedException("获取乾元数据库连接失败" + e1.getCause().getMessage());
|
|
|
+ } finally {
|
|
|
+ try {
|
|
|
+ if (stmt != null) {
|
|
|
+ stmt.close();
|
|
|
+ }
|
|
|
+ if (conn != null) {
|
|
|
+ conn.close();
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<ProductHelpVO> packageInfo(ResultSet rs) throws SQLException {
|
|
|
+ List<ProductHelpVO> list = new ArrayList<>();
|
|
|
+ while (rs.next()) {
|
|
|
+ ProductHelpVO vo = new ProductHelpVO();
|
|
|
+ vo.setId(rs.getInt(1));
|
|
|
+ vo.setTitle(rs.getString(2));
|
|
|
+ vo.setDescr(rs.getString(3));
|
|
|
+ vo.setPurl(rs.getString(4));
|
|
|
+ vo.setPid(rs.getInt(5));
|
|
|
+ vo.setKeywords(rs.getString(6));
|
|
|
+ vo.setOrd(rs.getInt(7));
|
|
|
+ vo.setDigest(rs.getString(8));
|
|
|
+ vo.setTime(rs.getString(9));
|
|
|
+ list.add(vo);
|
|
|
+ }
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public String insertSingle(ProductHelpVO vo) {
|
|
|
+ try {
|
|
|
+ if (vo != null) {
|
|
|
+ if (vo.getTime() == null) {
|
|
|
+ vo.setTime(DateUtils.dateToString(LocalDateTime.now(), DateUtils.PATTERN_YMD_HMS));
|
|
|
+ }
|
|
|
+ StringBuffer sql = new StringBuffer();
|
|
|
+ sql.append("insert into " + info_table_name +
|
|
|
+ " (title,descr,purl,pid,keywords,ord,digest,time) values ");
|
|
|
+ sql.append("('");
|
|
|
+ sql.append("'" + vo.getTitle() + "',");
|
|
|
+ sql.append("'" + vo.getDescr() + "',");
|
|
|
+ sql.append("'" + vo.getPurl() + "',");
|
|
|
+ sql.append("'" + vo.getPid() + "',");
|
|
|
+ sql.append("'" + vo.getKeywords() + "',");
|
|
|
+ sql.append("'" + vo.getOrd() + "',");
|
|
|
+ sql.append("'" + vo.getDigest() + "',");
|
|
|
+ sql.append("'" + vo.getTime() + "',");
|
|
|
+ sql.append(")");
|
|
|
+ log.info("----------" + sql.toString());
|
|
|
+ centerInsertBatch(sql.toString());
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ //throw new DeniedException("单个宿州交易中心失败,请联系技术处理");
|
|
|
+ }
|
|
|
+ return "推送成功";
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public void centerInsertBatch(String sql) {
|
|
|
+ Connection conn = null;
|
|
|
+ Statement stmt = null;
|
|
|
+ try {
|
|
|
+ conn = qykhDataSource.getConnection();
|
|
|
+ stmt = conn.createStatement();
|
|
|
+ stmt.executeUpdate(sql);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ } finally {
|
|
|
+ try {
|
|
|
+ stmt.close();
|
|
|
+ conn.close();
|
|
|
+ } catch (Exception e1) {
|
|
|
+ e1.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ProductHelpVO selectSingle(Integer id) {
|
|
|
+ try {
|
|
|
+ ProductHelpVO vo = new ProductHelpVO();
|
|
|
+ StringBuffer sql = new StringBuffer();
|
|
|
+ sql.append("select " +
|
|
|
+ "id," +
|
|
|
+ "title," +
|
|
|
+ "descr," +
|
|
|
+ "purl," +
|
|
|
+ "pid," +
|
|
|
+ "keywords," +
|
|
|
+ "ord," +
|
|
|
+ "digest," +
|
|
|
+ "time " +
|
|
|
+ "from "
|
|
|
+ + info_table_name + " where id = '" + id + "'");
|
|
|
+ ResultSet rs = null;
|
|
|
+ Connection conn = null;
|
|
|
+ Statement stmt = null;
|
|
|
+ try {
|
|
|
+ conn = qykhDataSource.getConnection();
|
|
|
+ stmt = conn.createStatement();
|
|
|
+ rs = stmt.executeQuery(sql.toString());
|
|
|
+ rs.next();
|
|
|
+ vo.setId(rs.getInt(1));
|
|
|
+ vo.setTitle(rs.getString(2));
|
|
|
+ vo.setDescr(rs.getString(3));
|
|
|
+ vo.setPurl(rs.getString(4));
|
|
|
+ vo.setPid(rs.getInt(5));
|
|
|
+ vo.setKeywords(rs.getString(6));
|
|
|
+ vo.setOrd(rs.getInt(7));
|
|
|
+ vo.setDigest(rs.getString(8));
|
|
|
+ vo.setTime(rs.getString(9));
|
|
|
+ return vo;
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.info(e.getCause().getMessage());
|
|
|
+ e.printStackTrace();
|
|
|
+ //throw new DeniedException("交易中心插入报错"+e.getCause().getMessage());
|
|
|
+ } finally {
|
|
|
+ try {
|
|
|
+ rs.close();
|
|
|
+ stmt.close();
|
|
|
+ conn.close();
|
|
|
+ } catch (Exception e1) {
|
|
|
+ e1.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public ResultSet queryQykh(String sql) {
|
|
|
+ Connection conn = null;
|
|
|
+ Statement stmt = null;
|
|
|
+ try {
|
|
|
+ conn = qykhDataSource.getConnection();
|
|
|
+ stmt = conn.createStatement();
|
|
|
+ return stmt.executeQuery(sql);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.info(e.getCause().getMessage());
|
|
|
+ e.printStackTrace();
|
|
|
+ //throw new DeniedException("交易中心插入报错"+e.getCause().getMessage());
|
|
|
+ } finally {
|
|
|
+ try {
|
|
|
+ stmt.close();
|
|
|
+ conn.close();
|
|
|
+ } catch (Exception e1) {
|
|
|
+ e1.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+}
|