|
@@ -0,0 +1,318 @@
|
|
|
|
+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.StringUtils;
|
|
|
|
+import com.platform.dao.bean.MyVOPage;
|
|
|
|
+import com.platform.dao.vo.query.qykh.ProductVO;
|
|
|
|
+import com.platform.service.qykh.QykhPlanDetailsService;
|
|
|
|
+import com.platform.service.qykh.QykhProductService;
|
|
|
|
+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("qykhProductService")
|
|
|
|
+@Slf4j
|
|
|
|
+public class QykhProductServiceImpl implements QykhProductService {
|
|
|
|
+ @Resource
|
|
|
|
+ private DataSource qykhDataSource;
|
|
|
|
+
|
|
|
|
+ @Value("${qykh.product}")
|
|
|
|
+ private String info_table_name;
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public MyVOPage<ProductVO> selectPage(int pageNum, int pageSize, ProductVO guaranteeInfoDTO) {
|
|
|
|
+ MyVOPage<ProductVO> myVOPage = new MyVOPage<>();
|
|
|
|
+ myVOPage.setPageNum(pageNum);
|
|
|
|
+ myVOPage.setPageSize(pageSize);
|
|
|
|
+ Connection conn = null;
|
|
|
|
+ Statement stmt = null;
|
|
|
|
+ ResultSet rs = null;
|
|
|
|
+ StringBuffer querySql = new StringBuffer("select " +
|
|
|
|
+ "id," +
|
|
|
|
+ "level," +
|
|
|
|
+ "pid," +
|
|
|
|
+ "pname," +
|
|
|
|
+ "desrc," +
|
|
|
|
+ "shortdesc," +
|
|
|
|
+ "purl," +
|
|
|
|
+ "bannerurl," +
|
|
|
|
+ "ord, " +
|
|
|
|
+ "oname," +
|
|
|
|
+ "seoid," +
|
|
|
|
+ "iszt," +
|
|
|
|
+ "zturl, " +
|
|
|
|
+ "iszhutui ");
|
|
|
|
+ StringBuffer countSql = new StringBuffer("select count(*) ");
|
|
|
|
+ StringBuffer sql = new StringBuffer(" from " + info_table_name + " where 1 = 1 ");
|
|
|
|
+ if (StringUtils.isNotBlank(guaranteeInfoDTO.getPname())) {
|
|
|
|
+ sql.append("and pname like '%" + guaranteeInfoDTO.getPname() + "%' ");
|
|
|
|
+ }
|
|
|
|
+ sql.append(" order by ord ");
|
|
|
|
+ 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<ProductVO>());
|
|
|
|
+ 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(ProductVO vo) {
|
|
|
|
+ Connection conn = null;
|
|
|
|
+ Statement stmt = null;
|
|
|
|
+ if(StringUtils.isBlank(vo.getPname()) || StringUtils.isBlank(vo.getDesrc())){
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ StringBuffer updateSql = new StringBuffer("update " + info_table_name + " set " +
|
|
|
|
+ "pname='" + vo.getPname() +
|
|
|
|
+ "',desrc='" + vo.getDesrc() +
|
|
|
|
+ /* "',shortdesc='" + vo.getShortdesc() +
|
|
|
|
+ "',planid='" + vo.getPlanid() +
|
|
|
|
+ "',orderid='" + vo.getOrderid() +
|
|
|
|
+ "',digest='" + vo.getDigest() +
|
|
|
|
+ "',keywords='" + vo.getKeywords() +
|
|
|
|
+ "',seoid='" + vo.getSeoid() +
|
|
|
|
+ "',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<ProductVO> packageInfo(ResultSet rs) throws SQLException {
|
|
|
|
+ List<ProductVO> list = new ArrayList<>();
|
|
|
|
+ while (rs.next()) {
|
|
|
|
+ ProductVO vo = new ProductVO();
|
|
|
|
+ vo.setId(rs.getInt(1));
|
|
|
|
+ vo.setLevel(rs.getInt(2));
|
|
|
|
+ vo.setPid(rs.getInt(3));
|
|
|
|
+ vo.setPname(rs.getString(4));
|
|
|
|
+ vo.setDesrc(rs.getString(5));
|
|
|
|
+ vo.setShortdesc(rs.getString(6));
|
|
|
|
+ vo.setPurl(rs.getString(7));
|
|
|
|
+ vo.setBannerurl(rs.getString(8));
|
|
|
|
+ vo.setOrd(rs.getInt(9));
|
|
|
|
+ vo.setOname(rs.getString(10));
|
|
|
|
+ vo.setSeoid(rs.getInt(11));
|
|
|
|
+ vo.setIszt(rs.getInt(12));
|
|
|
|
+ vo.setZturl(rs.getString(13));
|
|
|
|
+ vo.setIszhutui(rs.getInt(14));
|
|
|
|
+ list.add(vo);
|
|
|
|
+ }
|
|
|
|
+ return list;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
|
+ public String insertSingle(ProductVO vo) {
|
|
|
|
+ try {
|
|
|
|
+ if (vo != null) {
|
|
|
|
+ StringBuffer sql = new StringBuffer();
|
|
|
|
+ sql.append("insert into " + info_table_name +
|
|
|
|
+ " (level,pid,pname,desrc,shortdesc,purl,bannerurl,ord,oname,seoid,iszt,zturl,iszhutui) values ");
|
|
|
|
+ sql.append("('");
|
|
|
|
+ sql.append("'" + vo.getLevel() + "',");
|
|
|
|
+ sql.append("'" + vo.getPid() + "',");
|
|
|
|
+ sql.append("'" + vo.getPname() + "',");
|
|
|
|
+ sql.append("'" + vo.getDesrc() + "',");
|
|
|
|
+ sql.append("'" + vo.getShortdesc() + "',");
|
|
|
|
+ sql.append("'" + vo.getPurl() + "',");
|
|
|
|
+ sql.append("'" + vo.getBannerurl() + "',");
|
|
|
|
+ sql.append("'" + vo.getOrd() + "',");
|
|
|
|
+ sql.append("'" + vo.getOname() + "',");
|
|
|
|
+ sql.append("'" + vo.getSeoid() + "',");
|
|
|
|
+ sql.append("'" + vo.getIszt() + "',");
|
|
|
|
+ sql.append("'" + vo.getZturl() + "',");
|
|
|
|
+ sql.append("'" + vo.getIszhutui() + "',");
|
|
|
|
+ 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 ProductVO selectSingle(Integer id) {
|
|
|
|
+ try {
|
|
|
|
+ ProductVO vo = new ProductVO();
|
|
|
|
+ StringBuffer sql = new StringBuffer();
|
|
|
|
+ sql.append("select " +
|
|
|
|
+ "id," +
|
|
|
|
+ "level," +
|
|
|
|
+ "pid," +
|
|
|
|
+ "pname," +
|
|
|
|
+ "desrc," +
|
|
|
|
+ "shortdesc," +
|
|
|
|
+ "purl," +
|
|
|
|
+ "bannerurl," +
|
|
|
|
+ "ord, " +
|
|
|
|
+ "oname," +
|
|
|
|
+ "seoid," +
|
|
|
|
+ "iszt," +
|
|
|
|
+ "zturl, " +
|
|
|
|
+ "iszhutui " +
|
|
|
|
+ "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.setLevel(rs.getInt(2));
|
|
|
|
+ vo.setPid(rs.getInt(3));
|
|
|
|
+ vo.setPname(rs.getString(4));
|
|
|
|
+ vo.setDesrc(rs.getString(5));
|
|
|
|
+ vo.setShortdesc(rs.getString(6));
|
|
|
|
+ vo.setPurl(rs.getString(7));
|
|
|
|
+ vo.setBannerurl(rs.getString(8));
|
|
|
|
+ vo.setOrd(rs.getInt(9));
|
|
|
|
+ vo.setOname(rs.getString(10));
|
|
|
|
+ vo.setSeoid(rs.getInt(11));
|
|
|
|
+ vo.setIszt(rs.getInt(12));
|
|
|
|
+ vo.setZturl(rs.getString(13));
|
|
|
|
+ vo.setIszhutui(rs.getInt(14));
|
|
|
|
+ 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;
|
|
|
|
+ }
|
|
|
|
+}
|