|
|
@@ -0,0 +1,118 @@
|
|
|
+package com.poteviohealth.cgp.integration.service.impl;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.poteviohealth.cgp.common.filter.TokenContext;
|
|
|
+import com.poteviohealth.cgp.common.model.CommonPage;
|
|
|
+import com.poteviohealth.cgp.common.model.VaultsResponse;
|
|
|
+import com.poteviohealth.cgp.common.service.impl.BaseServiceImpl;
|
|
|
+import com.poteviohealth.cgp.integration.mapper.IntegralDetailMapper;
|
|
|
+import com.poteviohealth.cgp.integration.mapstruct.IntegralConverter;
|
|
|
+import com.poteviohealth.cgp.integration.model.IntegralDetail;
|
|
|
+import com.poteviohealth.cgp.integration.model.invo.web.IntegralDetailWebInDTO;
|
|
|
+import com.poteviohealth.cgp.integration.model.outvo.web.IntegralDetailWebOutDTO;
|
|
|
+import com.poteviohealth.cgp.integration.service.IIntegralDetailService;
|
|
|
+import lombok.extern.log4j.Log4j2;
|
|
|
+import org.springframework.beans.factory.config.YamlPropertiesFactoryBean;
|
|
|
+import org.springframework.core.io.ClassPathResource;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
+import java.sql.Connection;
|
|
|
+import java.sql.SQLException;
|
|
|
+import java.sql.Statement;
|
|
|
+import java.util.Properties;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @PackageName:com.poteviohealth.cgp.integration.service.impl
|
|
|
+ * @className:IntegralDetailServiceImpl
|
|
|
+ * @Description:
|
|
|
+ * @author: QIN
|
|
|
+ * @date: 2020/9/1 15:46
|
|
|
+ */
|
|
|
+@Service
|
|
|
+@Log4j2
|
|
|
+public class IntegralDetailServiceImpl extends BaseServiceImpl<IntegralDetailMapper, IntegralDetail> implements IIntegralDetailService {
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public VaultsResponse<String> createTable(Connection conn, Integer mark) {
|
|
|
+ //获取yml配置文件
|
|
|
+ StringBuilder stringBuilder = new StringBuilder();
|
|
|
+ try {
|
|
|
+ YamlPropertiesFactoryBean yamlMapFactoryBean = new YamlPropertiesFactoryBean();
|
|
|
+ yamlMapFactoryBean.setResources(new ClassPathResource("integration-sql.yml"));
|
|
|
+ Properties properties = yamlMapFactoryBean.getObject();
|
|
|
+
|
|
|
+ properties.forEach((k, v) -> {
|
|
|
+ //获取执行次数
|
|
|
+
|
|
|
+ String tableName = k.toString().substring(0,k.toString().lastIndexOf('_')+1);
|
|
|
+ tableName+= mark.toString();
|
|
|
+
|
|
|
+ //执行替换
|
|
|
+ String sql = v.toString().replace("$", mark.toString());
|
|
|
+ Statement statement = null;
|
|
|
+ try {
|
|
|
+ statement = conn.createStatement();
|
|
|
+
|
|
|
+ //执行创建表
|
|
|
+ statement.executeUpdate("DROP TABLE IF EXISTS `"+tableName+"`");
|
|
|
+ statement.executeUpdate(sql);
|
|
|
+ } catch (SQLException e) {
|
|
|
+ log.error("{createTable}创建表[" + k + "]时异常;");
|
|
|
+ stringBuilder.append("创建表[" + k + "]时异常;");
|
|
|
+ //break;
|
|
|
+ } finally {
|
|
|
+ if (statement != null) {
|
|
|
+ try {
|
|
|
+ statement.close();
|
|
|
+ } catch (SQLException e) {
|
|
|
+ log.error("close statement error", e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ if (stringBuilder.length() == 0) {
|
|
|
+ return VaultsResponse.success();
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("创建表失败", e);
|
|
|
+ return VaultsResponse.failed(stringBuilder.toString());
|
|
|
+ } finally {
|
|
|
+ try {
|
|
|
+ if (conn != null) {
|
|
|
+ conn.close();
|
|
|
+ }
|
|
|
+ } catch (SQLException e) {
|
|
|
+ log.error("close connection error", e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return VaultsResponse.success();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public VaultsResponse<CommonPage<IntegralDetailWebOutDTO>> selectPage(IntegralDetailWebInDTO integralDetailWebInDTO) {
|
|
|
+
|
|
|
+ IPage<IntegralDetail> pageOrder = selectOrderIPage(integralDetailWebInDTO);
|
|
|
+ return VaultsResponse.success(IntegralConverter.INSTANCE.model2WebDTO(pageOrder));
|
|
|
+ }
|
|
|
+
|
|
|
+ private IPage<IntegralDetail> selectOrderIPage(IntegralDetailWebInDTO integralDetailWebInDTO) {
|
|
|
+ Page<IntegralDetail> page = new Page<>(integralDetailWebInDTO.getPageNum(), integralDetailWebInDTO.getPageSize());
|
|
|
+
|
|
|
+ QueryWrapper<IntegralDetail> orderQueryWrapper = new QueryWrapper<>();
|
|
|
+ orderQueryWrapper.eq("customer_id",integralDetailWebInDTO.getCustomerId());
|
|
|
+ if (null != integralDetailWebInDTO.getStartDate()) {
|
|
|
+ orderQueryWrapper.le("created_date", integralDetailWebInDTO.getStartDate());
|
|
|
+ }
|
|
|
+ if (null != integralDetailWebInDTO.getEndDate()) {
|
|
|
+ orderQueryWrapper.ge("created_date", integralDetailWebInDTO.getEndDate());
|
|
|
+ }
|
|
|
+ orderQueryWrapper.orderByDesc("created_date");
|
|
|
+ return super.page(page, orderQueryWrapper);
|
|
|
+ }
|
|
|
+
|
|
|
+}
|