From c5e422f058998b016486e9e160da872bf40ed734 Mon Sep 17 00:00:00 2001 From: aipper Date: Fri, 7 Nov 2025 18:08:54 +0800 Subject: [PATCH] test --- doc/1.md | 267 ++++++ .../point/strategy/common/WebAppConfig.java | 60 +- .../controller/ArchivesUploadController.java | 885 +++++++++++++++++- .../CityBusinessSystemIntegration.java | 64 ++ src/main/resources/application-dev.yml | 7 + 5 files changed, 1270 insertions(+), 13 deletions(-) create mode 100644 doc/1.md create mode 100644 src/main/java/com/point/strategy/oaDocking/service/CityBusinessSystemIntegration.java diff --git a/doc/1.md b/doc/1.md new file mode 100644 index 0000000..0643bbb --- /dev/null +++ b/doc/1.md @@ -0,0 +1,267 @@ +好的,这是将您提供的文档转换为 Markdown 格式的内容。 +# 市公司业务数据文档 + +## 一、月度卷烟购进、销售、库存数据 + +**说明**:每月初导一份数据,导入的为进销存仓库数据,包含罚没库。 + +| 字段中文 | 字段名称 | +| :--- | :--- | +| 日期 | `biz_date` | +| 仓库名称 | `stor_name` | +| 商品编码 | `product_code` | +| 商品名称 | `product_name` | +| 计量单位名称 | `unit_name` | +| 期初数量 | `last_qty` | +| 购入数量 | `buy_qty` | +| 销售数量 | `sale_qty` | +| 报损数量 | `dec_qty` | +| 期末数量 | `rest_qty` | + +## 二、年度在销及退出卷烟品牌规格数据 + +### 1. 在销品牌 + +**说明**:每月初导一份数据,导入的为在销品规的数据,用于归档。 + +| 字段中文 | 字段名称 | +| :--- | :--- | +| 卷烟标识 | `product_uuid` | +| 卷烟编码 | `product_code` | +| 卷烟名称 | `product_name` | +| 厂家简称 | `factory_simple_name` | +| 品牌名称 | `brand_name` | +| 是否异形包装(1:是;0:否) | `is_abnormity` | +| 包装长度(mm) | `length` | +| 包装宽度(mm) | `width` | +| 包装高度(mm) | `height` | +| 焦油含量(mg) | `tar_qty` | +| 包条形码 | `bar_code` | +| 包包装支数 | `package_qty` | +| 条条形码 | `bar_code2` | +| 条包装支数 | `package_qty2` | +| 件条形码 | `bar_code3` | +| 件包装支数 | `package_qty3` | +| 卷烟价类 | `price_type_code` | +| 批发指导价 | `direct_whole_price` | +| 零售指导价 | `direct_retail price` | +| 是否省内烟 | `is_province` | +| 是否查扣烟启用 | `is_seized` | +| 调剂价 | `adjust_price` | +| 零售价 | `retail price` | +| 批发价 | `whole_sale_price` | +| 引入日期 | `in_begin_date` | +| 上市日期 | `sale_begin_date` | +| 退出日期 | `out_begin_date` | + +### 2. 退出品规 + +**说明**:每月初导一份数据,导入的为审批完结的数据,用于归档。 + +| 字段中文 | 字段名称 | +| :--- | :--- | +| 卷烟标识 | `product_uuid` | +| 卷烟编码 | `product_code` | +| 卷烟名称 | `product_name` | +| 厂家简称 | `factory_simple_name` | +| 品牌名称 | `brand_name` | +| 是否异形包装(1:是;0:否) | `is_abnormity` | +| 包装长度(mm) | `length` | +| 包装宽度(mm) | `width` | +| 包装高度(mm) | `height` | +| 焦油含量(mg) | `tar_qty` | +| 包条形码 | `bar_code` | +| 包包装支数 | `package_qty` | +| 条条形码 | `bar_code2` | +| 条包装支数 | `package_qty2` | +| 件条形码 | `bar_code3` | +| 件包装支数 | `package_qty3` | +| 卷烟价类 | `price_type_code` | +| 批发指导价 | `direct_whole_price` | +| 零售指导价 | `direct_retail_price` | +| 是否省内烟 | `is_province` | +| 是否查扣烟启用 | `is_seized` | +| 调剂价 | `adjust price` | +| 零售价 | `retail price` | +| 批发价 | `whole_sale_price` | +| 退出日期 | `out begin date` | + +## 三、终端建设全流程档案数据 + +**说明**:每月初导一份数据,导入的为审批完结的数据,用于归档。 + +| 字段中文 | 字段名称 | +| :--- | :--- | +| 市场部 | `depart_uuid` | +| 部门名称 | `depart_name` | +| 营销线 | `saler_dept_uuid` | +| 许可证号码 | `license_code` | +| 客户名称 | `cust_name` | +| 经营地址 | `address` | +| 经营者 | `manage_person_name` | +| 客户档位名称 | `cust_type_name` | +| 经营业态 | `busi_place_code` | +| 当前终端层级 | `terminal_level_before` | +| 拟建设终端层级 | `terminal_level_after` | +| 申请说明 | `apply_remark` | +| 处理说明 | `deal_remark` | +| 受理状态 | `accept_status` | +| 申请人名称 | `creator_name` | +| 创建时间 | `syscreatedate` | + +---- +CREATE TABLE `cc_tbc_product_ez` ( +`product_uuid` char(32) COLLATE utf8_bin NOT NULL, +`product_code` varchar(20) COLLATE utf8_bin NOT NULL, +`product_name` varchar(100) COLLATE utf8_bin NOT NULL, +`factory_simple_name` varchar(20) COLLATE utf8_bin DEFAULT NULL, +`brand_name` varchar(100) COLLATE utf8_bin DEFAULT NULL, +`is_abnormity` char(1) COLLATE utf8_bin NOT NULL DEFAULT '0', +`length` decimal(9,0) DEFAULT NULL, +`width` decimal(9,0) DEFAULT NULL, +`height` decimal(9,0) DEFAULT NULL, +`tar_qty` decimal(9,2) DEFAULT NULL, +`bar_code` varchar(20) COLLATE utf8_bin DEFAULT NULL, +`package_qty` decimal(9,0) DEFAULT NULL, +`bar_code2` varchar(20) COLLATE utf8_bin DEFAULT NULL, +`package_qty2` decimal(9,0) DEFAULT NULL, +`bar_code3` varchar(20) COLLATE utf8_bin DEFAULT NULL, +`package_qty3` decimal(9,0) DEFAULT NULL, +`price_type_code` varchar(5) COLLATE utf8_bin NOT NULL, +`direct_whole_price` decimal(9,2) NOT NULL DEFAULT '0.00', +`direct_retail_price` decimal(9,2) NOT NULL DEFAULT '0.00', +`is_province` char(1) COLLATE utf8_bin NOT NULL, +`is_seized` char(1) COLLATE utf8_bin NOT NULL, +`adjust_price` decimal(9,2) DEFAULT NULL, +`retail_price` decimal(9,2) DEFAULT NULL, +`whole_sale_price` decimal(9,2) DEFAULT NULL, +`in_begin_date` char(10) COLLATE utf8_bin DEFAULT NULL, +`sale_begin_date` char(10) COLLATE utf8_bin DEFAULT NULL, +`out_begin_date` char(10) COLLATE utf8_bin DEFAULT NULL, +PRIMARY KEY (`product_uuid`) USING BTREE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8_bin ROW_FORMAT=DYNAMIC; + + +CREATE TABLE `cc_tbc_drawout_ez` ( +`drawout_uuid` char(32) NOT NULL, +`org_name` varchar(100) DEFAULT NULL, +`quit_uuid` char(32) NOT NULL, +`drawout_date` char(10) DEFAULT NULL, +`quit_date` char(10) DEFAULT NULL, +`comment` varchar(1000) DEFAULT NULL, +`creater_name` varchar(20) DEFAULT NULL, +`SYSCREATEDATE` varchar(25) DEFAULT NULL, +PRIMARY KEY (`drawout_uuid`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3; + +CREATE TABLE `scm_rpt_bizstordayreport_ez` ( +`id` bigint NOT NULL AUTO_INCREMENT, +`biz_date` char(10) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL, +`manage_unit_uuid` char(32) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL, +`stor_uuid` char(32) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL, +`stor_name` varchar(500) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL, +`product_uuid` char(32) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL, +`product_code` varchar(100) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL, +`product_name` varchar(500) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL, +`unit_uuid` char(32) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL, +`unit_name` varchar(100) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL, +`last_qty` decimal(15,2) NOT NULL DEFAULT '0.00', +`last_amount` decimal(15,2) NOT NULL DEFAULT '0.00', +`buy_qty` decimal(15,2) NOT NULL DEFAULT '0.00', +`buy_notax_amount` decimal(15,2) NOT NULL DEFAULT '0.00', +`buy_amount` decimal(15,2) NOT NULL DEFAULT '0.00', +`movein_qty` decimal(15,2) NOT NULL DEFAULT '0.00', +`movein_notax_amount` decimal(15,2) NOT NULL DEFAULT '0.00', +`movein_amount` decimal(15,2) NOT NULL DEFAULT '0.00', +`movein_cost` decimal(15,2) NOT NULL DEFAULT '0.00', +`moveout_qty` decimal(15,2) NOT NULL DEFAULT '0.00', +`moveout_notax_amount` decimal(15,2) NOT NULL DEFAULT '0.00', +`moveout_amount` decimal(15,2) NOT NULL DEFAULT '0.00', +`moveout_cost` decimal(15,2) NOT NULL DEFAULT '0.00', +`sale_qty` decimal(15,2) NOT NULL DEFAULT '0.00', +`sale_notax_amount` decimal(15,2) NOT NULL DEFAULT '0.00', +`sale_amount` decimal(15,2) NOT NULL DEFAULT '0.00', +`sale_cost` decimal(15,2) NOT NULL DEFAULT '0.00', +`sale_gross_profit` decimal(15,2) NOT NULL DEFAULT '0.00', +`allot_qty` decimal(15,2) NOT NULL DEFAULT '0.00', +`allot_notax_amount` decimal(15,2) NOT NULL DEFAULT '0.00', +`allot_amount` decimal(15,2) NOT NULL DEFAULT '0.00', +`allot_cost` decimal(15,2) NOT NULL DEFAULT '0.00', +`allot_gross_profit` decimal(15,2) NOT NULL DEFAULT '0.00', +`dec_qty` decimal(15,2) NOT NULL DEFAULT '0.00', +`dec_notax_amount` decimal(15,2) NOT NULL DEFAULT '0.00', +`dec_amount` decimal(15,2) NOT NULL DEFAULT '0.00', +`inc_qty` decimal(15,2) NOT NULL DEFAULT '0.00', +`inc_notax_amount` decimal(15,2) NOT NULL DEFAULT '0.00', +`inc_amount` decimal(15,2) NOT NULL DEFAULT '0.00', +`rest_qty` decimal(15,2) NOT NULL DEFAULT '0.00', +`rest_amount` decimal(15,2) NOT NULL DEFAULT '0.00', +`cost_price` decimal(18,6) NOT NULL DEFAULT '0.000000', +PRIMARY KEY (`id`) USING BTREE, +UNIQUE KEY `pk_idx` (`biz_date`,`stor_uuid`,`product_uuid`) USING BTREE, +KEY `auto_shard_key_manage_unit_uuid` (`manage_unit_uuid`) USING BTREE +) ENGINE=InnoDB AUTO_INCREMENT=38406392 DEFAULT CHARSET=utf8mb3 COLLATE=utf8_bin ROW_FORMAT=DYNAMIC; + + +CREATE TABLE `ec_exp_apply_accept_ez` ( +`accept_uuid` char(32) NOT NULL, +`org_name` varchar(500) NOT NULL, +`org_name2` varchar(500) NOT NULL, +`license_code` varchar(20) DEFAULT NULL, +`cust_name` varchar(100) NOT NULL, +`address` varchar(500) NOT NULL, +`manage_person_name` varchar(100) DEFAULT NULL, +`cust_type_name` varchar(100) NOT NULL, +`busi_place_code` varchar(5) NOT NULL, +`terminal_level_before` varchar(5) NOT NULL, +`terminal_level_after` varchar(5) DEFAULT NULL, +`apply_remark` varchar(255) DEFAULT NULL, +`deal_remark` varchar(255) DEFAULT NULL, +`accept_status` varchar(5) NOT NULL, +`syscreatedate` varchar(25) NOT NULL, +`updator_name` varchar(20) DEFAULT NULL, +PRIMARY KEY (`accept_uuid`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3; + + + +##1、查询在销品牌 +select +product_uuid, +product_code, +product_name, +factory_simple_name, +brand_name, +is_abnormity, +length, +width, +height, +tar_qty, +bar_code, +package_qty, +bar_code2, +package_qty2, +bar_code3, +package_qty3, +price_type_code, +direct_whole_price, +direct_retail_price, +is_province, +is_seized, +adjust_price, +retail_price, +whole_sale_price, +in_begin_date, +sale_begin_date, +out_begin_date +from CC_TBC_PRODUCT_ez; + + +## 2、查询退出品规 +select org_name,quit_uuid,drawout_date,quit_date,comment,creater_name,SYSCREATEDATE from cc_tbc_drawout_ez; + +##3、市公司月度卷烟购进、销售、库存数据 +select * from SCM_RPT_BizStorDayReport_ez; + +#4、市公司终端建设全流程档案数据 +select * from ec_exp_apply_accept_ez ; diff --git a/src/main/java/com/point/strategy/common/WebAppConfig.java b/src/main/java/com/point/strategy/common/WebAppConfig.java index fcaf439..54091ca 100644 --- a/src/main/java/com/point/strategy/common/WebAppConfig.java +++ b/src/main/java/com/point/strategy/common/WebAppConfig.java @@ -1,10 +1,12 @@ package com.point.strategy.common; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Configuration; import org.springframework.http.HttpHeaders; import org.springframework.web.servlet.config.annotation.CorsRegistry; import org.springframework.web.servlet.config.annotation.InterceptorRegistry; +import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; /** @@ -16,11 +18,28 @@ public class WebAppConfig implements WebMvcConfigurer { @Autowired private TokenInterceptor tokenInterceptor; + @Value("${upload.path}") + private String uploadPath; + + @Value("${img.upload}") + private String imgUploadPath; + + @Value("${temp.path}") + private String tempPath; + + @Value("${unzip.path}") + private String unzipPath; + + @Value("${report.path}") + private String reportPath; + @Override public void addInterceptors(InterceptorRegistry registry){ - registry.addInterceptor(tokenInterceptor).addPathPatterns("/**"); // token 验证拦截器 + registry.addInterceptor(tokenInterceptor) + .addPathPatterns("/**") + .excludePathPatterns("/upload/**", "/images/**", "/temp/**", "/unzip/**", "/report/**", "/pdffile/**", "/template/**"); // 排除静态资源路径 } - + @Override public void addCorsMappings(CorsRegistry registry) { registry.addMapping("/**"). @@ -31,5 +50,40 @@ public class WebAppConfig implements WebMvcConfigurer { allowCredentials(true). //带上cookie信息 exposedHeaders(HttpHeaders.SET_COOKIE).maxAge(3600L); //maxAge(3600)表明在3600秒内,不需要再发送预检验请求,可以缓存该结果 } - + + @Override + public void addResourceHandlers(ResourceHandlerRegistry registry) { + // 上传文件访问映射 + registry.addResourceHandler("/upload/**") + .addResourceLocations("file:" + uploadPath + "/"); + + // 图片文件访问映射(外部存储) + registry.addResourceHandler("/img/**") + .addResourceLocations("file:" + imgUploadPath + "/"); + + // 临时文件访问映射 + registry.addResourceHandler("/temp/**") + .addResourceLocations("file:" + tempPath + "/"); + + // 解压文件访问映射 + registry.addResourceHandler("/unzip/**") + .addResourceLocations("file:" + unzipPath + "/"); + + // 报表文件访问映射 + registry.addResourceHandler("/report/**") + .addResourceLocations("file:" + reportPath + "/"); + + // webapp静态资源访问映射 + registry.addResourceHandler("/pdffile/**") + .addResourceLocations("classpath:/pdffile/"); + + registry.addResourceHandler("/images/**") + .addResourceLocations("classpath:/images/"); + + registry.addResourceHandler("/template/**") + .addResourceLocations("classpath:/template/"); + } + + } + diff --git a/src/main/java/com/point/strategy/oaDocking/controller/ArchivesUploadController.java b/src/main/java/com/point/strategy/oaDocking/controller/ArchivesUploadController.java index 3d8b310..a1b94cc 100644 --- a/src/main/java/com/point/strategy/oaDocking/controller/ArchivesUploadController.java +++ b/src/main/java/com/point/strategy/oaDocking/controller/ArchivesUploadController.java @@ -13,6 +13,7 @@ import com.point.strategy.oaDocking.service.DocSimpleOaService; import com.point.strategy.oaDocking.service.DocTraditionFileOaService; import com.point.strategy.oaDocking.service.DocTraditionVolumeOaService; import com.point.strategy.oaDocking.service.YcjSystemIntegration; +import com.point.strategy.oaDocking.service.CityBusinessSystemIntegration; import com.point.strategy.oaDocking.util.FileUtils; import com.point.strategy.service.OperLoggerService; import com.point.strategy.user.bean.User; @@ -390,7 +391,7 @@ public class ArchivesUploadController { log.info("[DOC] fawen_index={} 对应的记录数量: {}", indexComment, recordCount); } } - YcjSystemIntegration.closeResources(null, null, countResult); + CityBusinessSystemIntegration.closeResources(null, null, countResult); resultSetFile = YcjSystemIntegration.executeQuery(sqlFile); while (resultSetFile.next()) { @@ -515,10 +516,10 @@ public class ArchivesUploadController { } json = AjaxJson.returnExceptionInfo(e.toString()); } finally { - YcjSystemIntegration.closeResources(null, null, resultSet); - YcjSystemIntegration.closeResources(null, null, resultSetFile); - YcjSystemIntegration.closeResources(null, null, resultSetDisposal); - YcjSystemIntegration.closeResources(null, null, resultSetCount); + CityBusinessSystemIntegration.closeResources(null, null, resultSet); + CityBusinessSystemIntegration.closeResources(null, null, resultSetFile); + CityBusinessSystemIntegration.closeResources(null, null, resultSetDisposal); + CityBusinessSystemIntegration.closeResources(null, null, resultSetCount); } return json; @@ -782,7 +783,7 @@ public class ArchivesUploadController { log.info("[CONTRACT] fawen_index={} 对应的记录数量: {}", indexComment, recordCount); } } - YcjSystemIntegration.closeResources(null, null, countResult); + CityBusinessSystemIntegration.closeResources(null, null, countResult); resultSetFile = YcjSystemIntegration.executeQuery(sqlFile); while (resultSetFile.next()) { String fileName = resultSetFile.getString("file_path"); @@ -964,14 +965,878 @@ public class ArchivesUploadController { operLoggerService.addEntity(entity); } } finally { - YcjSystemIntegration.closeResources(null, null, resultSet); - YcjSystemIntegration.closeResources(null, null, resultSetFile); - YcjSystemIntegration.closeResources(null, null, resultSetDisposal); - YcjSystemIntegration.closeResources(null, null, resultSetCount); + CityBusinessSystemIntegration.closeResources(null, null, resultSet); + CityBusinessSystemIntegration.closeResources(null, null, resultSetFile); + CityBusinessSystemIntegration.closeResources(null, null, resultSetDisposal); + CityBusinessSystemIntegration.closeResources(null, null, resultSetCount); } return json; } + @RequestMapping(value="/productSalesDocking" , method= RequestMethod.POST) + @ApiOperation(value = "在销品牌对接") + public AjaxJson productSalesDocking() { + AjaxJson json = new AjaxJson(); + if (log.isInfoEnabled()) { + log.info("[PRODUCT_SALES] 在销品牌对接开始, archiveXMLGenerate={}, uploadPath={}", archiveXMLGenerate, uploadPath); + } + //查询在销品牌数据,从2025-01-01开始的全量数据 + String sql = " select * from CC_TBC_PRODUCT_ez where 1=1 "; + ResultSet resultSet = null; + ResultSet resultSetFile = null; + ResultSet resultSetCount = null; + int j = 0; + int totalPending = 0; + String product_uuid = ""; + try { + // 统计总条数 + String countSql = "select count(1) as CNT from CC_TBC_PRODUCT_ez where 1=1"; + resultSetCount = CityBusinessSystemIntegration.executeQuery(countSql); + if (resultSetCount.next()) { + totalPending = resultSetCount.getInt("CNT"); + } + if (log.isInfoEnabled()) { + log.info("[PRODUCT_SALES] 总条数 totalPending={}", totalPending); + } + String tableName = "product_sales_" + new SimpleDateFormat("yyyyMMdd").format(new Date()) + "_temp"; + String tempTableName = tableName + "_temp"; + String fileTableName = tableName + "_temp_file"; + if (log.isDebugEnabled()) { + log.debug("[PRODUCT_SALES] 执行源库查询: {}", sql); + } + resultSet = CityBusinessSystemIntegration.executeQuery(sql); + //把数据添加到简化表中 + String fieldName = "product_uuid,product_code,product_name,factory_simple_name,brand_name,is_abnormity,length,width,height,tar_qty,bar_code,package_qty,bar_code2,package_qty2,bar_code3,package_qty3,price_type_code,direct_whole_price,direct_retail_price,is_province,is_seized,adjust_price,retail_price,whole_sale_price,in_begin_date,sale_begin_date,out_begin_date,fonds_no,retention,archive_ctg_no,created_date,maintitle,responsibleby,archive_flag,batch_id"; + String valueName = ""; + // 遍历结果集 + while (resultSet.next()) { + // 获取每一行的数据 + product_uuid = nvl(resultSet.getString("product_uuid")); + String product_code = nvl(resultSet.getString("product_code")); + String product_name = nvl(resultSet.getString("product_name")); + String factory_simple_name = nvl(resultSet.getString("factory_simple_name")); + String brand_name = nvl(resultSet.getString("brand_name")); + String is_abnormity = nvl(resultSet.getString("is_abnormity")); + BigDecimal length = resultSet.getBigDecimal("length"); + BigDecimal width = resultSet.getBigDecimal("width"); + BigDecimal height = resultSet.getBigDecimal("height"); + BigDecimal tar_qty = resultSet.getBigDecimal("tar_qty"); + String bar_code = nvl(resultSet.getString("bar_code")); + BigDecimal package_qty = resultSet.getBigDecimal("package_qty"); + String bar_code2 = nvl(resultSet.getString("bar_code2")); + BigDecimal package_qty2 = resultSet.getBigDecimal("package_qty2"); + String bar_code3 = nvl(resultSet.getString("bar_code3")); + BigDecimal package_qty3 = resultSet.getBigDecimal("package_qty3"); + String price_type_code = nvl(resultSet.getString("price_type_code")); + BigDecimal direct_whole_price = resultSet.getBigDecimal("direct_whole_price"); + BigDecimal direct_retail_price = resultSet.getBigDecimal("direct_retail_price"); + String is_province = nvl(resultSet.getString("is_province")); + String is_seized = nvl(resultSet.getString("is_seized")); + BigDecimal adjust_price = resultSet.getBigDecimal("adjust_price"); + BigDecimal retail_price = resultSet.getBigDecimal("retail_price"); + BigDecimal whole_sale_price = resultSet.getBigDecimal("whole_sale_price"); + String in_begin_date = nvl(resultSet.getString("in_begin_date")); + String sale_begin_date = nvl(resultSet.getString("sale_begin_date")); + String out_begin_date = nvl(resultSet.getString("out_begin_date")); + + String fonds_no = "0240"; // 固定全宗号 + String retention = "永久"; // 默认保管期限 + String archive_ctg_no = "CP"; // 产品档案分类 + String created_date = new SimpleDateFormat("yyyyMMdd").format(new Date()); + String maintitle = product_name; + String responsibleby = "系统管理员"; + + valueName = "'" + product_uuid + "'," + + "'" + product_code + "'," + + "'" + product_name + "'," + + "'" + factory_simple_name + "'," + + "'" + brand_name + "'," + + "'" + is_abnormity + "'," + + (length != null ? length : "NULL") + "," + + (width != null ? width : "NULL") + "," + + (height != null ? height : "NULL") + "," + + (tar_qty != null ? tar_qty : "NULL") + "," + + "'" + bar_code + "'," + + (package_qty != null ? package_qty : "NULL") + "," + + "'" + bar_code2 + "'," + + (package_qty2 != null ? package_qty2 : "NULL") + "," + + "'" + bar_code3 + "'," + + (package_qty3 != null ? package_qty3 : "NULL") + "," + + "'" + price_type_code + "'," + + (direct_whole_price != null ? direct_whole_price : "NULL") + "," + + (direct_retail_price != null ? direct_retail_price : "NULL") + "," + + "'" + is_province + "'," + + "'" + is_seized + "'," + + (adjust_price != null ? adjust_price : "NULL") + "," + + (retail_price != null ? retail_price : "NULL") + "," + + (whole_sale_price != null ? whole_sale_price : "NULL") + "," + + "'" + in_begin_date + "'," + + "'" + sale_begin_date + "'," + + "'" + out_begin_date + "'," + + "'" + fonds_no + "'," + + "'" + retention + "'," + + "'" + archive_ctg_no + "'," + + "'" + created_date + "'," + + "'" + maintitle + "'," + + "'" + responsibleby + "'," + + "'预归档未完成'," + + "'" + product_uuid + "'"; + + if (log.isInfoEnabled()) { + log.info("[PRODUCT_SALES] 处理记录 product_uuid={}, product_code={}, product_name={}", product_uuid, product_code, product_name); + } + + // 幂等:优先检查是否已存在相同 product_uuid 记录 + Integer jhId; + String whereSql = " 1=1 and product_uuid='" + product_uuid + "' "; + if (existsInTemp(tempTableName, whereSql)) { + jhId = findSingleId(tempTableName, whereSql); + if (log.isDebugEnabled()) { + log.debug("[PRODUCT_SALES] 命中幂等: 复用已有记录 id={}, where={}", jhId, whereSql); + } + } else { + Map mapTwo = new HashMap(); + mapTwo.put("tableName", tempTableName); + mapTwo.put("fieldName", fieldName); + mapTwo.put("valueName", valueName); + danganguanliService.saveObject(mapTwo); + jhId = Integer.parseInt(mapTwo.get("id").toString()); + if (log.isInfoEnabled()) { + log.info("[PRODUCT_SALES] 新增主表记录 id={} (temp={})", jhId, tempTableName); + } + } + + String filePath = "uploadFile/" + fileTableName + "/" + jhId; + Path dirPath = ensureDir(uploadPath, filePath); + String dir = dirPath.toString(); + if (log.isDebugEnabled()) { + log.debug("[PRODUCT_SALES] 目标目录: {}", dir); + } + + //是否生成归档xml + if(archiveXMLGenerate){ + String head = ""; + String xml = " <目录>" + + " <卷烟标识>" + xmlEscape(product_uuid) + "" + + " <卷烟编码>" + xmlEscape(product_code) + "" + + " <卷烟名称>" + xmlEscape(product_name) + "" + + " <厂家简称>" + xmlEscape(factory_simple_name) + "" + + " <品牌名称>" + xmlEscape(brand_name) + "" + + " <是否异形包装>" + xmlEscape(is_abnormity) + "" + + " <包装长度>" + (length != null ? length.toString() : "") + "" + + " <包装宽度>" + (width != null ? width.toString() : "") + "" + + " <包装高度>" + (height != null ? height.toString() : "") + "" + + " <焦油含量>" + (tar_qty != null ? tar_qty.toString() : "") + "" + + " <包条形码>" + xmlEscape(bar_code) + "" + + " <包包装支数>" + (package_qty != null ? package_qty.toString() : "") + "" + + " <条条形码>" + xmlEscape(bar_code2) + "" + + " <条包装支数>" + (package_qty2 != null ? package_qty2.toString() : "") + "" + + " <件条形码>" + xmlEscape(bar_code3) + "" + + " <件包装支数>" + (package_qty3 != null ? package_qty3.toString() : "") + "" + + " <卷烟价类>" + xmlEscape(price_type_code) + "" + + " <批发指导价>" + (direct_whole_price != null ? direct_whole_price.toString() : "") + "" + + " <零售指导价>" + (direct_retail_price != null ? direct_retail_price.toString() : "") + "" + + " <是否省内烟>" + xmlEscape(is_province) + "" + + " <是否查扣烟启用>" + xmlEscape(is_seized) + "" + + " <调剂价>" + (adjust_price != null ? adjust_price.toString() : "") + "" + + " <零售价>" + (retail_price != null ? retail_price.toString() : "") + "" + + " <批发价>" + (whole_sale_price != null ? whole_sale_price.toString() : "") + "" + + " <引入日期>" + xmlEscape(in_begin_date) + "" + + " <上市日期>" + xmlEscape(sale_begin_date) + "" + + " <退出日期>" + xmlEscape(out_begin_date) + "" + + " <全宗号>" + xmlEscape(fonds_no) + "" + + " <保管期限>" + xmlEscape(retention) + "" + + " <归档分类>" + xmlEscape(archive_ctg_no) + "" + + " <归档时间>" + created_date + "" + + " <责任者>" + xmlEscape(responsibleby) + "" + + " "; + String content = head + xml; + String newContent = FileTool.formatXml(content); + FileTool.write(newContent, dirPath.resolve(product_uuid + ".xml").toString()); + String fileName = product_uuid + ".xml"; + String fileNameServer = product_uuid + ".xml"; + String type = "xml"; + insertFileRecord(fileTableName, jhId, fileName, fileNameServer, filePath, type, 1, dir); + if (log.isInfoEnabled()) { + log.info("[PRODUCT_SALES] 生成XML文件并登记: {}", dirPath.resolve(fileName)); + } + } + + //不需要更新源库状态,全量处理 + j++; + + //添加日志 + ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); + User user = null; + if (servletRequestAttributes != null) { + HttpServletRequest request = servletRequestAttributes.getRequest(); + UserRole userRole = userService.getUserRole(request); + if (userRole != null) user = userRole.getUser(); + } + if (user != null) { + //记录日志 + java.util.Date date = new Date(); + OperLogger entity = new OperLogger(); + entity.setLogType("7"); + entity.setOperator(user.getUsername()); + entity.setOperatorChn(user.getUserChnName()); + entity.setOperateDate(date); + entity.setDescription("在销品牌系统成功归档"+product_code+"的卷烟编码"); + entity.setArgs("在销品牌系统成功归档"+product_code+"的卷烟编码"); + operLoggerService.addEntity(entity); + } + } + if (log.isInfoEnabled()) log.info("[PRODUCT_SALES] 在销品牌对接完成, 待处理条数={}, 成功处理条数={}", totalPending, j); + json = AjaxJson.returnInfo("成功接收" + j + "条"); + } catch (Exception e) { + log.error("[PRODUCT_SALES] 在销品牌对接失败 product_uuid={}", product_uuid, e); + //添加日志 + ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); + User user = null; + if (servletRequestAttributes != null) { + HttpServletRequest request = servletRequestAttributes.getRequest(); + UserRole userRole = userService.getUserRole(request); + if (userRole != null) user = userRole.getUser(); + } + if (user != null) { + //记录日志 + java.util.Date date = new Date(); + OperLogger entity = new OperLogger(); + entity.setLogType("7"); + entity.setOperator(user.getUsername()); + entity.setOperatorChn(user.getUserChnName()); + entity.setOperateDate(date); + entity.setDescription("在销品牌系统失败归档"+product_uuid+"的卷烟标识"); + entity.setArgs("在销品牌系统失败归档"+e.toString()); + operLoggerService.addEntity(entity); + } + json = AjaxJson.returnExceptionInfo(e.toString()); + } finally { + CityBusinessSystemIntegration.closeResources(null, null, resultSet); + CityBusinessSystemIntegration.closeResources(null, null, resultSetFile); + CityBusinessSystemIntegration.closeResources(null, null, resultSetCount); + } + + return json; + } + + @RequestMapping(value="/productExitDocking" , method= RequestMethod.POST) + @ApiOperation(value = "退出品规对接") + public AjaxJson productExitDocking() { + AjaxJson json = new AjaxJson(); + if (log.isInfoEnabled()) { + log.info("[PRODUCT_EXIT] 退出品规对接开始, archiveXMLGenerate={}, uploadPath={}", archiveXMLGenerate, uploadPath); + } + //查询退出品规数据,从2025-01-01开始的全量数据 + String sql = " select * from cc_tbc_drawout_ez where 1=1 "; + ResultSet resultSet = null; + ResultSet resultSetFile = null; + ResultSet resultSetCount = null; + int j = 0; + int totalPending = 0; + String drawout_uuid = ""; + try { + // 统计总条数 + String countSql = "select count(1) as CNT from cc_tbc_drawout_ez where 1=1"; + resultSetCount = CityBusinessSystemIntegration.executeQuery(countSql); + if (resultSetCount.next()) { + totalPending = resultSetCount.getInt("CNT"); + } + if (log.isInfoEnabled()) { + log.info("[PRODUCT_EXIT] 总条数 totalPending={}", totalPending); + } + String tableName = "product_exit_" + new SimpleDateFormat("yyyyMMdd").format(new Date()) + "_temp"; + String tempTableName = tableName + "_temp"; + String fileTableName = tableName + "_temp_file"; + if (log.isDebugEnabled()) { + log.debug("[PRODUCT_EXIT] 执行源库查询: {}", sql); + } + resultSet = CityBusinessSystemIntegration.executeQuery(sql); + //把数据添加到简化表中 + String fieldName = "drawout_uuid,org_name,quit_uuid,drawout_date,quit_date,comment,creater_name,syscreatedate,fonds_no,retention,archive_ctg_no,created_date,maintitle,responsibleby,archive_flag,batch_id"; + String valueName = ""; + // 遍历结果集 + while (resultSet.next()) { + // 获取每一行的数据 + drawout_uuid = nvl(resultSet.getString("drawout_uuid")); + String org_name = nvl(resultSet.getString("org_name")); + String quit_uuid = nvl(resultSet.getString("quit_uuid")); + String drawout_date = nvl(resultSet.getString("drawout_date")); + String quit_date = nvl(resultSet.getString("quit_date")); + String comment = nvl(resultSet.getString("comment")); + String creater_name = nvl(resultSet.getString("creater_name")); + String syscreatedate = nvl(resultSet.getString("SYSCREATEDATE")); + + String fonds_no = "0240"; // 固定全宗号 + String retention = "永久"; // 默认保管期限 + String archive_ctg_no = "CE"; // 退出品规分类 + String created_date = new SimpleDateFormat("yyyyMMdd").format(new Date()); + String maintitle = "退出品规-" + quit_uuid; + String responsibleby = creater_name; + + valueName = "'" + drawout_uuid + "'," + + "'" + org_name + "'," + + "'" + quit_uuid + "'," + + "'" + drawout_date + "'," + + "'" + quit_date + "'," + + "'" + comment + "'," + + "'" + creater_name + "'," + + "'" + syscreatedate + "'," + + "'" + fonds_no + "'," + + "'" + retention + "'," + + "'" + archive_ctg_no + "'," + + "'" + created_date + "'," + + "'" + maintitle + "'," + + "'" + responsibleby + "'," + + "'预归档未完成'," + + "'" + drawout_uuid + "'"; + + if (log.isInfoEnabled()) { + log.info("[PRODUCT_EXIT] 处理记录 drawout_uuid={}, quit_uuid={}, org_name={}", drawout_uuid, quit_uuid, org_name); + } + + // 幂等:优先检查是否已存在相同 drawout_uuid 记录 + Integer jhId; + String whereSql = " 1=1 and drawout_uuid='" + drawout_uuid + "' "; + if (existsInTemp(tempTableName, whereSql)) { + jhId = findSingleId(tempTableName, whereSql); + if (log.isDebugEnabled()) { + log.debug("[PRODUCT_EXIT] 命中幂等: 复用已有记录 id={}, where={}", jhId, whereSql); + } + } else { + Map mapTwo = new HashMap(); + mapTwo.put("tableName", tempTableName); + mapTwo.put("fieldName", fieldName); + mapTwo.put("valueName", valueName); + danganguanliService.saveObject(mapTwo); + jhId = Integer.parseInt(mapTwo.get("id").toString()); + if (log.isInfoEnabled()) { + log.info("[PRODUCT_EXIT] 新增主表记录 id={} (temp={})", jhId, tempTableName); + } + } + + String filePath = "uploadFile/" + fileTableName + "/" + jhId; + Path dirPath = ensureDir(uploadPath, filePath); + String dir = dirPath.toString(); + if (log.isDebugEnabled()) { + log.debug("[PRODUCT_EXIT] 目标目录: {}", dir); + } + + //是否生成归档xml + if(archiveXMLGenerate){ + String head = ""; + String xml = " <目录>" + + " <退出标识>" + xmlEscape(drawout_uuid) + "" + + " <机构名称>" + xmlEscape(org_name) + "" + + " <退出品规标识>" + xmlEscape(quit_uuid) + "" + + " <退出日期>" + xmlEscape(drawout_date) + "" + + " <退出时间>" + xmlEscape(quit_date) + "" + + " <备注>" + xmlEscape(comment) + "" + + " <创建人>" + xmlEscape(creater_name) + "" + + " <系统创建时间>" + xmlEscape(syscreatedate) + "" + + " <全宗号>" + xmlEscape(fonds_no) + "" + + " <保管期限>" + xmlEscape(retention) + "" + + " <归档分类>" + xmlEscape(archive_ctg_no) + "" + + " <归档时间>" + created_date + "" + + " <责任者>" + xmlEscape(responsibleby) + "" + + " "; + String content = head + xml; + String newContent = FileTool.formatXml(content); + FileTool.write(newContent, dirPath.resolve(drawout_uuid + ".xml").toString()); + String fileName = drawout_uuid + ".xml"; + String fileNameServer = drawout_uuid + ".xml"; + String type = "xml"; + insertFileRecord(fileTableName, jhId, fileName, fileNameServer, filePath, type, 1, dir); + if (log.isInfoEnabled()) { + log.info("[PRODUCT_EXIT] 生成XML文件并登记: {}", dirPath.resolve(fileName)); + } + } + + //不需要更新源库状态,全量处理 + j++; + + //添加日志 + ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); + User user = null; + if (servletRequestAttributes != null) { + HttpServletRequest request = servletRequestAttributes.getRequest(); + UserRole userRole = userService.getUserRole(request); + if (userRole != null) user = userRole.getUser(); + } + if (user != null) { + //记录日志 + java.util.Date date = new Date(); + OperLogger entity = new OperLogger(); + entity.setLogType("7"); + entity.setOperator(user.getUsername()); + entity.setOperatorChn(user.getUserChnName()); + entity.setOperateDate(date); + entity.setDescription("退出品规系统成功归档"+quit_uuid+"的退出品规标识"); + entity.setArgs("退出品规系统成功归档"+quit_uuid+"的退出品规标识"); + operLoggerService.addEntity(entity); + } + } + if (log.isInfoEnabled()) log.info("[PRODUCT_EXIT] 退出品规对接完成, 待处理条数={}, 成功处理条数={}", totalPending, j); + json = AjaxJson.returnInfo("成功接收" + j + "条"); + } catch (Exception e) { + log.error("[PRODUCT_EXIT] 退出品规对接失败 drawout_uuid={}", drawout_uuid, e); + //添加日志 + ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); + User user = null; + if (servletRequestAttributes != null) { + HttpServletRequest request = servletRequestAttributes.getRequest(); + UserRole userRole = userService.getUserRole(request); + if (userRole != null) user = userRole.getUser(); + } + if (user != null) { + //记录日志 + java.util.Date date = new Date(); + OperLogger entity = new OperLogger(); + entity.setLogType("7"); + entity.setOperator(user.getUsername()); + entity.setOperatorChn(user.getUserChnName()); + entity.setOperateDate(date); + entity.setDescription("退出品规系统失败归档"+drawout_uuid+"的退出标识"); + entity.setArgs("退出品规系统失败归档"+e.toString()); + operLoggerService.addEntity(entity); + } + json = AjaxJson.returnExceptionInfo(e.toString()); + } finally { + CityBusinessSystemIntegration.closeResources(null, null, resultSet); + CityBusinessSystemIntegration.closeResources(null, null, resultSetFile); + CityBusinessSystemIntegration.closeResources(null, null, resultSetCount); + } + + return json; + } + + @RequestMapping(value="/monthlyInventoryDocking" , method= RequestMethod.POST) + @ApiOperation(value = "月度进销存对接") + public AjaxJson monthlyInventoryDocking() { + AjaxJson json = new AjaxJson(); + if (log.isInfoEnabled()) { + log.info("[MONTHLY_INVENTORY] 月度进销存对接开始, archiveXMLGenerate={}, uploadPath={}", archiveXMLGenerate, uploadPath); + } + //查询月度进销存数据,从2025-01-01开始的全量数据,按日期排序 + String sql = " select * from SCM_RPT_BizStorDayReport_ez where biz_date >= '2025-01-01' order by biz_date "; + ResultSet resultSet = null; + ResultSet resultSetFile = null; + ResultSet resultSetCount = null; + int j = 0; + int totalPending = 0; + String id = ""; + try { + // 统计总条数 + String countSql = "select count(1) as CNT from SCM_RPT_BizStorDayReport_ez where biz_date >= '2025-01-01'"; + resultSetCount = CityBusinessSystemIntegration.executeQuery(countSql); + if (resultSetCount.next()) { + totalPending = resultSetCount.getInt("CNT"); + } + if (log.isInfoEnabled()) { + log.info("[MONTHLY_INVENTORY] 总条数 totalPending={}", totalPending); + } + String tableName = "monthly_inventory_" + new SimpleDateFormat("yyyyMMdd").format(new Date()) + "_temp"; + String tempTableName = tableName + "_temp"; + String fileTableName = tableName + "_temp_file"; + if (log.isDebugEnabled()) { + log.debug("[MONTHLY_INVENTORY] 执行源库查询: {}", sql); + } + resultSet = CityBusinessSystemIntegration.executeQuery(sql); + //把数据添加到简化表中 + String fieldName = "biz_date,stor_name,product_code,product_name,unit_name,last_qty,buy_qty,sale_qty,dec_qty,rest_qty,last_amount,buy_amount,sale_amount,dec_amount,rest_amount,fonds_no,retention,archive_ctg_no,created_date,maintitle,responsibleby,archive_flag,batch_id"; + String valueName = ""; + // 遍历结果集 + while (resultSet.next()) { + // 获取每一行的数据 + id = String.valueOf(resultSet.getLong("id")); + String biz_date = nvl(resultSet.getString("biz_date")); + String stor_name = nvl(resultSet.getString("stor_name")); + String product_code = nvl(resultSet.getString("product_code")); + String product_name = nvl(resultSet.getString("product_name")); + String unit_name = nvl(resultSet.getString("unit_name")); + BigDecimal last_qty = resultSet.getBigDecimal("last_qty"); + BigDecimal buy_qty = resultSet.getBigDecimal("buy_qty"); + BigDecimal sale_qty = resultSet.getBigDecimal("sale_qty"); + BigDecimal dec_qty = resultSet.getBigDecimal("dec_qty"); + BigDecimal rest_qty = resultSet.getBigDecimal("rest_qty"); + BigDecimal last_amount = resultSet.getBigDecimal("last_amount"); + BigDecimal buy_amount = resultSet.getBigDecimal("buy_amount"); + BigDecimal sale_amount = resultSet.getBigDecimal("sale_amount"); + BigDecimal dec_amount = resultSet.getBigDecimal("dec_amount"); + BigDecimal rest_amount = resultSet.getBigDecimal("rest_amount"); + + String fonds_no = "0240"; // 固定全宗号 + String retention = "10年"; // 默认保管期限 + String archive_ctg_no = "MI"; // 月度进销存分类 + String created_date = new SimpleDateFormat("yyyyMMdd").format(new Date()); + String maintitle = stor_name + "-" + biz_date + "-" + product_name; + String responsibleby = "系统管理员"; + + valueName = "'" + biz_date + "'," + + "'" + stor_name + "'," + + "'" + product_code + "'," + + "'" + product_name + "'," + + "'" + unit_name + "'," + + (last_qty != null ? last_qty : "NULL") + "," + + (buy_qty != null ? buy_qty : "NULL") + "," + + (sale_qty != null ? sale_qty : "NULL") + "," + + (dec_qty != null ? dec_qty : "NULL") + "," + + (rest_qty != null ? rest_qty : "NULL") + "," + + (last_amount != null ? last_amount : "NULL") + "," + + (buy_amount != null ? buy_amount : "NULL") + "," + + (sale_amount != null ? sale_amount : "NULL") + "," + + (dec_amount != null ? dec_amount : "NULL") + "," + + (rest_amount != null ? rest_amount : "NULL") + "," + + "'" + fonds_no + "'," + + "'" + retention + "'," + + "'" + archive_ctg_no + "'," + + "'" + created_date + "'," + + "'" + maintitle + "'," + + "'" + responsibleby + "'," + + "'预归档未完成'," + + "'" + id + "'"; + + if (log.isInfoEnabled()) { + log.info("[MONTHLY_INVENTORY] 处理记录 id={}, biz_date={}, stor_name={}, product_code={}", id, biz_date, stor_name, product_code); + } + + // 幂等:优先检查是否已存在相同 id 记录 + Integer jhId; + String whereSql = " 1=1 and batch_id='" + id + "' "; + if (existsInTemp(tempTableName, whereSql)) { + jhId = findSingleId(tempTableName, whereSql); + if (log.isDebugEnabled()) { + log.debug("[MONTHLY_INVENTORY] 命中幂等: 复用已有记录 id={}, where={}", jhId, whereSql); + } + } else { + Map mapTwo = new HashMap(); + mapTwo.put("tableName", tempTableName); + mapTwo.put("fieldName", fieldName); + mapTwo.put("valueName", valueName); + danganguanliService.saveObject(mapTwo); + jhId = Integer.parseInt(mapTwo.get("id").toString()); + if (log.isInfoEnabled()) { + log.info("[MONTHLY_INVENTORY] 新增主表记录 id={} (temp={})", jhId, tempTableName); + } + } + + String filePath = "uploadFile/" + fileTableName + "/" + jhId; + Path dirPath = ensureDir(uploadPath, filePath); + String dir = dirPath.toString(); + if (log.isDebugEnabled()) { + log.debug("[MONTHLY_INVENTORY] 目标目录: {}", dir); + } + + //是否生成归档xml + if(archiveXMLGenerate){ + String head = ""; + String xml = " <目录>" + + " <日期>" + xmlEscape(biz_date) + "" + + " <仓库名称>" + xmlEscape(stor_name) + "" + + " <商品编码>" + xmlEscape(product_code) + "" + + " <商品名称>" + xmlEscape(product_name) + "" + + " <计量单位名称>" + xmlEscape(unit_name) + "" + + " <期初数量>" + (last_qty != null ? last_qty.toString() : "") + "" + + " <购入数量>" + (buy_qty != null ? buy_qty.toString() : "") + "" + + " <销售数量>" + (sale_qty != null ? sale_qty.toString() : "") + "" + + " <报损数量>" + (dec_qty != null ? dec_qty.toString() : "") + "" + + " <期末数量>" + (rest_qty != null ? rest_qty.toString() : "") + "" + + " <期初金额>" + (last_amount != null ? last_amount.toString() : "") + "" + + " <购入金额>" + (buy_amount != null ? buy_amount.toString() : "") + "" + + " <销售金额>" + (sale_amount != null ? sale_amount.toString() : "") + "" + + " <报损金额>" + (dec_amount != null ? dec_amount.toString() : "") + "" + + " <期末金额>" + (rest_amount != null ? rest_amount.toString() : "") + "" + + " <全宗号>" + xmlEscape(fonds_no) + "" + + " <保管期限>" + xmlEscape(retention) + "" + + " <归档分类>" + xmlEscape(archive_ctg_no) + "" + + " <归档时间>" + created_date + "" + + " <责任者>" + xmlEscape(responsibleby) + "" + + " "; + String content = head + xml; + String newContent = FileTool.formatXml(content); + FileTool.write(newContent, dirPath.resolve(id + ".xml").toString()); + String fileName = id + ".xml"; + String fileNameServer = id + ".xml"; + String type = "xml"; + insertFileRecord(fileTableName, jhId, fileName, fileNameServer, filePath, type, 1, dir); + if (log.isInfoEnabled()) { + log.info("[MONTHLY_INVENTORY] 生成XML文件并登记: {}", dirPath.resolve(fileName)); + } + } + + //不需要更新源库状态,全量处理 + j++; + + //添加日志 + ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); + User user = null; + if (servletRequestAttributes != null) { + HttpServletRequest request = servletRequestAttributes.getRequest(); + UserRole userRole = userService.getUserRole(request); + if (userRole != null) user = userRole.getUser(); + } + if (user != null) { + //记录日志 + java.util.Date date = new Date(); + OperLogger entity = new OperLogger(); + entity.setLogType("7"); + entity.setOperator(user.getUsername()); + entity.setOperatorChn(user.getUserChnName()); + entity.setOperateDate(date); + entity.setDescription("月度进销存系统成功归档"+biz_date+"的数据"); + entity.setArgs("月度进销存系统成功归档"+biz_date+"的数据"); + operLoggerService.addEntity(entity); + } + } + if (log.isInfoEnabled()) log.info("[MONTHLY_INVENTORY] 月度进销存对接完成, 待处理条数={}, 成功处理条数={}", totalPending, j); + json = AjaxJson.returnInfo("成功接收" + j + "条"); + } catch (Exception e) { + log.error("[MONTHLY_INVENTORY] 月度进销存对接失败 id={}", id, e); + //添加日志 + ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); + User user = null; + if (servletRequestAttributes != null) { + HttpServletRequest request = servletRequestAttributes.getRequest(); + UserRole userRole = userService.getUserRole(request); + if (userRole != null) user = userRole.getUser(); + } + if (user != null) { + //记录日志 + java.util.Date date = new Date(); + OperLogger entity = new OperLogger(); + entity.setLogType("7"); + entity.setOperator(user.getUsername()); + entity.setOperatorChn(user.getUserChnName()); + entity.setOperateDate(date); + entity.setDescription("月度进销存系统失败归档"+id+"的记录"); + entity.setArgs("月度进销存系统失败归档"+e.toString()); + operLoggerService.addEntity(entity); + } + json = AjaxJson.returnExceptionInfo(e.toString()); + } finally { + CityBusinessSystemIntegration.closeResources(null, null, resultSet); + CityBusinessSystemIntegration.closeResources(null, null, resultSetFile); + CityBusinessSystemIntegration.closeResources(null, null, resultSetCount); + } + + return json; + } + + @RequestMapping(value="/terminalConstructionDocking" , method= RequestMethod.POST) + @ApiOperation(value = "终端建设全流程档案对接") + public AjaxJson terminalConstructionDocking() { + AjaxJson json = new AjaxJson(); + if (log.isInfoEnabled()) { + log.info("[TERMINAL_CONSTRUCTION] 终端建设全流程档案对接开始, archiveXMLGenerate={}, uploadPath={}", archiveXMLGenerate, uploadPath); + } + //查询终端建设数据,从2025-01-01开始的全量数据 + String sql = " select * from ec_exp_apply_accept_ez where 1=1 "; + ResultSet resultSet = null; + ResultSet resultSetFile = null; + ResultSet resultSetCount = null; + int j = 0; + int totalPending = 0; + String accept_uuid = ""; + try { + // 统计总条数 + String countSql = "select count(1) as CNT from ec_exp_apply_accept_ez where 1=1"; + resultSetCount = CityBusinessSystemIntegration.executeQuery(countSql); + if (resultSetCount.next()) { + totalPending = resultSetCount.getInt("CNT"); + } + if (log.isInfoEnabled()) { + log.info("[TERMINAL_CONSTRUCTION] 总条数 totalPending={}", totalPending); + } + String tableName = "terminal_construction_" + new SimpleDateFormat("yyyyMMdd").format(new Date()) + "_temp"; + String tempTableName = tableName + "_temp"; + String fileTableName = tableName + "_temp_file"; + if (log.isDebugEnabled()) { + log.debug("[TERMINAL_CONSTRUCTION] 执行源库查询: {}", sql); + } + resultSet = CityBusinessSystemIntegration.executeQuery(sql); + //把数据添加到简化表中 + String fieldName = "depart_uuid,depart_name,saler_dept_uuid,license_code,cust_name,address,manage_person_name,cust_type_name,busi_place_code,terminal_level_before,terminal_level_after,apply_remark,deal_remark,accept_status,creator_name,syscreatedate,fonds_no,retention,archive_ctg_no,created_date,maintitle,responsibleby,archive_flag,batch_id"; + String valueName = ""; + // 遍历结果集 + while (resultSet.next()) { + // 获取每一行的数据 + accept_uuid = nvl(resultSet.getString("accept_uuid")); + String depart_uuid = nvl(resultSet.getString("depart_uuid")); + String depart_name = nvl(resultSet.getString("depart_name")); + String saler_dept_uuid = nvl(resultSet.getString("saler_dept_uuid")); + String license_code = nvl(resultSet.getString("license_code")); + String cust_name = nvl(resultSet.getString("cust_name")); + String address = nvl(resultSet.getString("address")); + String manage_person_name = nvl(resultSet.getString("manage_person_name")); + String cust_type_name = nvl(resultSet.getString("cust_type_name")); + String busi_place_code = nvl(resultSet.getString("busi_place_code")); + String terminal_level_before = nvl(resultSet.getString("terminal_level_before")); + String terminal_level_after = nvl(resultSet.getString("terminal_level_after")); + String apply_remark = nvl(resultSet.getString("apply_remark")); + String deal_remark = nvl(resultSet.getString("deal_remark")); + String accept_status = nvl(resultSet.getString("accept_status")); + String creator_name = nvl(resultSet.getString("creator_name")); + String syscreatedate = nvl(resultSet.getString("syscreatedate")); + + String fonds_no = "0240"; // 固定全宗号 + String retention = "10年"; // 默认保管期限 + String archive_ctg_no = "TC"; // 终端建设分类 + String created_date = new SimpleDateFormat("yyyyMMdd").format(new Date()); + String maintitle = cust_name + "-" + license_code + "-终端建设"; + String responsibleby = creator_name; + + valueName = "'" + depart_uuid + "'," + + "'" + depart_name + "'," + + "'" + saler_dept_uuid + "'," + + "'" + license_code + "'," + + "'" + cust_name + "'," + + "'" + address + "'," + + "'" + manage_person_name + "'," + + "'" + cust_type_name + "'," + + "'" + busi_place_code + "'," + + "'" + terminal_level_before + "'," + + "'" + terminal_level_after + "'," + + "'" + apply_remark + "'," + + "'" + deal_remark + "'," + + "'" + accept_status + "'," + + "'" + creator_name + "'," + + "'" + syscreatedate + "'," + + "'" + fonds_no + "'," + + "'" + retention + "'," + + "'" + archive_ctg_no + "'," + + "'" + created_date + "'," + + "'" + maintitle + "'," + + "'" + responsibleby + "'," + + "'预归档未完成'," + + "'" + accept_uuid + "'"; + + if (log.isInfoEnabled()) { + log.info("[TERMINAL_CONSTRUCTION] 处理记录 accept_uuid={}, license_code={}, cust_name={}", accept_uuid, license_code, cust_name); + } + + // 幂等:优先检查是否已存在相同 accept_uuid 记录 + Integer jhId; + String whereSql = " 1=1 and batch_id='" + accept_uuid + "' "; + if (existsInTemp(tempTableName, whereSql)) { + jhId = findSingleId(tempTableName, whereSql); + if (log.isDebugEnabled()) { + log.debug("[TERMINAL_CONSTRUCTION] 命中幂等: 复用已有记录 id={}, where={}", jhId, whereSql); + } + } else { + Map mapTwo = new HashMap(); + mapTwo.put("tableName", tempTableName); + mapTwo.put("fieldName", fieldName); + mapTwo.put("valueName", valueName); + danganguanliService.saveObject(mapTwo); + jhId = Integer.parseInt(mapTwo.get("id").toString()); + if (log.isInfoEnabled()) { + log.info("[TERMINAL_CONSTRUCTION] 新增主表记录 id={} (temp={})", jhId, tempTableName); + } + } + + String filePath = "uploadFile/" + fileTableName + "/" + jhId; + Path dirPath = ensureDir(uploadPath, filePath); + String dir = dirPath.toString(); + if (log.isDebugEnabled()) { + log.debug("[TERMINAL_CONSTRUCTION] 目标目录: {}", dir); + } + + //是否生成归档xml + if(archiveXMLGenerate){ + String head = ""; + String xml = " <目录>" + + " <市场部>" + xmlEscape(depart_uuid) + "" + + " <部门名称>" + xmlEscape(depart_name) + "" + + " <营销线>" + xmlEscape(saler_dept_uuid) + "" + + " <许可证号码>" + xmlEscape(license_code) + "" + + " <客户名称>" + xmlEscape(cust_name) + "" + + " <经营地址>" + xmlEscape(address) + "" + + " <经营者>" + xmlEscape(manage_person_name) + "" + + " <客户档位名称>" + xmlEscape(cust_type_name) + "" + + " <经营业态>" + xmlEscape(busi_place_code) + "" + + " <当前终端层级>" + xmlEscape(terminal_level_before) + "" + + " <拟建设终端层级>" + xmlEscape(terminal_level_after) + "" + + " <申请说明>" + xmlEscape(apply_remark) + "" + + " <处理说明>" + xmlEscape(deal_remark) + "" + + " <受理状态>" + xmlEscape(accept_status) + "" + + " <申请人名称>" + xmlEscape(creator_name) + "" + + " <创建时间>" + xmlEscape(syscreatedate) + "" + + " <全宗号>" + xmlEscape(fonds_no) + "" + + " <保管期限>" + xmlEscape(retention) + "" + + " <归档分类>" + xmlEscape(archive_ctg_no) + "" + + " <归档时间>" + created_date + "" + + " <责任者>" + xmlEscape(responsibleby) + "" + + " "; + String content = head + xml; + String newContent = FileTool.formatXml(content); + FileTool.write(newContent, dirPath.resolve(accept_uuid + ".xml").toString()); + String fileName = accept_uuid + ".xml"; + String fileNameServer = accept_uuid + ".xml"; + String type = "xml"; + insertFileRecord(fileTableName, jhId, fileName, fileNameServer, filePath, type, 1, dir); + if (log.isInfoEnabled()) { + log.info("[TERMINAL_CONSTRUCTION] 生成XML文件并登记: {}", dirPath.resolve(fileName)); + } + } + + //不需要更新源库状态,全量处理 + j++; + + //添加日志 + ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); + User user = null; + if (servletRequestAttributes != null) { + HttpServletRequest request = servletRequestAttributes.getRequest(); + UserRole userRole = userService.getUserRole(request); + if (userRole != null) user = userRole.getUser(); + } + if (user != null) { + //记录日志 + java.util.Date date = new Date(); + OperLogger entity = new OperLogger(); + entity.setLogType("7"); + entity.setOperator(user.getUsername()); + entity.setOperatorChn(user.getUserChnName()); + entity.setOperateDate(date); + entity.setDescription("终端建设系统成功归档"+license_code+"的许可证号码"); + entity.setArgs("终端建设系统成功归档"+license_code+"的许可证号码"); + operLoggerService.addEntity(entity); + } + } + if (log.isInfoEnabled()) log.info("[TERMINAL_CONSTRUCTION] 终端建设全流程档案对接完成, 待处理条数={}, 成功处理条数={}", totalPending, j); + json = AjaxJson.returnInfo("成功接收" + j + "条"); + } catch (Exception e) { + log.error("[TERMINAL_CONSTRUCTION] 终端建设全流程档案对接失败 accept_uuid={}", accept_uuid, e); + //添加日志 + ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); + User user = null; + if (servletRequestAttributes != null) { + HttpServletRequest request = servletRequestAttributes.getRequest(); + UserRole userRole = userService.getUserRole(request); + if (userRole != null) user = userRole.getUser(); + } + if (user != null) { + //记录日志 + java.util.Date date = new Date(); + OperLogger entity = new OperLogger(); + entity.setLogType("7"); + entity.setOperator(user.getUsername()); + entity.setOperatorChn(user.getUserChnName()); + entity.setOperateDate(date); + entity.setDescription("终端建设系统失败归档"+accept_uuid+"的受理标识"); + entity.setArgs("终端建设系统失败归档"+e.toString()); + operLoggerService.addEntity(entity); + } + json = AjaxJson.returnExceptionInfo(e.toString()); + } finally { + CityBusinessSystemIntegration.closeResources(null, null, resultSet); + CityBusinessSystemIntegration.closeResources(null, null, resultSetFile); + CityBusinessSystemIntegration.closeResources(null, null, resultSetCount); + } + + return json; + } + @RequestMapping(value="/wsjhProject" , method= RequestMethod.POST) @ApiOperation(value = "简化工程") public AjaxJson wsjhProject() { diff --git a/src/main/java/com/point/strategy/oaDocking/service/CityBusinessSystemIntegration.java b/src/main/java/com/point/strategy/oaDocking/service/CityBusinessSystemIntegration.java new file mode 100644 index 0000000..b06df8a --- /dev/null +++ b/src/main/java/com/point/strategy/oaDocking/service/CityBusinessSystemIntegration.java @@ -0,0 +1,64 @@ +package com.point.strategy.oaDocking.service; + +import com.point.strategy.common.SystemProperty; + +import java.sql.*; +import java.util.logging.Level; +import java.util.logging.Logger; + +public class CityBusinessSystemIntegration { + private static final Logger LOGGER = Logger.getLogger(CityBusinessSystemIntegration.class.getName()); + + private static final String driver = SystemProperty.getKeyValue("cityBusiness.driverClassName", "application.properties"); + private static final String url = SystemProperty.getKeyValue("cityBusiness.url", "application.properties"); + private static final String user = SystemProperty.getKeyValue("cityBusiness.username", "application.properties"); + private static final String password = SystemProperty.getKeyValue("cityBusiness.password", "application.properties"); + + // 获取数据库连接 + private static Connection getConnection() throws Exception { + Class.forName(driver); + return DriverManager.getConnection(url, user, password); + } + + // 查询 + public static ResultSet executeQuery(String sql) throws Exception { + Connection conn = null; + Statement st = null; + try { + conn = getConnection(); + st = conn.createStatement(); + return st.executeQuery(sql); + } catch (Exception e) { + LOGGER.log(Level.SEVERE, "执行查询时出错: " + sql, e); + closeResources(conn, st, null); + throw e; + } + } + + // 修改 + public static int executeUpdate(String sql) throws Exception { + Connection conn = null; + Statement st = null; + try { + conn = getConnection(); + st = conn.createStatement(); + return st.executeUpdate(sql); + } catch (Exception e) { + LOGGER.log(Level.SEVERE, "执行更新时出错: " + sql, e); + throw e; + } finally { + closeResources(conn, st, null); + } + } + + // 关闭资源 + public static void closeResources(Connection conn, Statement st, ResultSet rs) { + try { + if (rs != null) rs.close(); + if (st != null) st.close(); + if (conn != null) conn.close(); + } catch (Exception e) { + LOGGER.log(Level.WARNING, "关闭资源时出错", e); + } + } +} \ No newline at end of file diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml index 1af16b6..e834257 100644 --- a/src/main/resources/application-dev.yml +++ b/src/main/resources/application-dev.yml @@ -94,6 +94,13 @@ ycj: username: ezdagl password: ezdagl#20241120 +# 市公司业务数据系统集成配置 +cityBusiness: + driverClassName: com.mysql.jdbc.Driver + url: jdbc:mysql://localhost:3306/city_business?useUnicode=true&characterEncoding=utf8&characterSetResults=utf8 + username: root + password: Abc@123456 + # 温湿度监控API配置 temperature: getAllWareHouseList: http://192.168.0.126:8080/api/getAllWareHouseList