提交 c5b709bf authored 作者: 李秋林's avatar 李秋林

axmr005战区数据同步飞书表格 (日数据)

上级 42effad8
...@@ -14,7 +14,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; ...@@ -14,7 +14,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
@EnableCustomConfig @EnableCustomConfig
@EnableRyFeignClients @EnableRyFeignClients
@SpringBootApplication @SpringBootApplication
@MapperScan({"com.sfa.job.domain.job.mapper","com.sfa.job.domain.system.mapper","com.sfa.job.domain.order.mapper"}) @MapperScan({"com.sfa.job.domain.job.mapper","com.sfa.job.domain.system.mapper","com.sfa.job.domain.order.mapper","com.sfa.job.domain.erp.mapper","com.sfa.job.domain.use.mapper"})
public class SfaJobApplication public class SfaJobApplication
{ {
public static void main(String[] args) { public static void main(String[] args) {
......
package com.sfa.job.domain.erp.dao;
import java.util.Date;
import java.util.List;
/**
* @author : liqiulin
* @date : 2025-04-08 13
* @describe :
*/
public interface ErpAxmr005ShippingDetailsDao {
List<Object> getZhanquDataset(Date date);
}
package com.sfa.job.domain.erp.dao;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.sfa.common.core.utils.DateUtils;
import com.sfa.job.domain.erp.entity.ErpAxmr005ShippingDetails;
import com.sfa.job.domain.erp.mapper.ErpAxmr005ShippingDetailsMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/**
* @author : liqiulin
* @date : 2025-04-08 13
* @describe :
*/
@DS("bi")
@Service
public class ErpAxmr005ShippingDetailsDaoImpl implements ErpAxmr005ShippingDetailsDao{
@Autowired
private ErpAxmr005ShippingDetailsMapper erpAxmr005ShippingDetailsMapper;
@Override
public List<Object> getZhanquDataset(Date date) {
List<ErpAxmr005ShippingDetails> zhanquDataset = erpAxmr005ShippingDetailsMapper.getZhanquDataset(date);
List<Object> os = new ArrayList<>();
long millis = System.currentTimeMillis();
String dateStr = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, date);
for (ErpAxmr005ShippingDetails erpDo : zhanquDataset) {
List<Object> data = new ArrayList<>();
data.add(millis+"_"+erpDo.getId());
data.add(erpDo.getShippingOrderNumber());
data.add(dateStr);
data.add(erpDo.getSalesDepartmentAbbr());
data.add(erpDo.getReceivingCustomerAbbr());
data.add(erpDo.getProductName());
data.add(erpDo.getQuantity());
data.add(erpDo.getThirdPartySystemCode());
os.add(data);
}
return os;
}
}
package com.sfa.job.domain.erp.entity;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
/**
* erp_axmr005出货明细表
* @TableName erp_axmr005_shipping_details
*/
@TableName(value ="erp_axmr005_shipping_details")
@Data
public class ErpAxmr005ShippingDetails implements Serializable {
@TableField(exist = false)
private Integer id;
/**
* 出货单号
*/
@TableId
private String shippingOrderNumber;
/**
* 项次
*/
private Integer itemSequence;
/**
* 营运据点
*/
private String operatingSite;
/**
* 单据日期
*/
private Date documentDate;
/**
* 扣账日期
*/
private Date debitDate;
/**
* 起运日期
*/
private Date shippingDate;
/**
* 出货性质
*/
private String shippingNature;
/**
* 状态
*/
private String status;
/**
* 销退方式
*/
private String salesReturnMethod;
/**
* 业务人员
*/
private String salesStaff;
/**
* 业务人员姓名
*/
private String salesStaffName;
/**
* 业务部门
*/
private String salesDepartment;
/**
* 业务部门简称
*/
private String salesDepartmentAbbr;
/**
* 订单客户
*/
private String orderCustomer;
/**
* 客户简称
*/
private String customerAbbr;
/**
* 收货客户
*/
private String receivingCustomer;
/**
* 收货客户简称
*/
private String receivingCustomerAbbr;
/**
* 收款客户
*/
private String paymentCustomer;
/**
* 收款客户简称
*/
private String paymentCustomerAbbr;
/**
* 国家
*/
private String country;
/**
* 国家说明
*/
private String countryDescription;
/**
* 省
*/
private String province;
/**
* 省份说明
*/
private String provinceDescription;
/**
* 县/市
*/
private String countyCity;
/**
* 县/市说明
*/
private String countyCityDescription;
/**
* 行政区域
*/
private String administrativeRegion;
/**
* 行政区域说明
*/
private String administrativeRegionDescription;
/**
* 送货地址
*/
private String deliveryAddress;
/**
* 地址
*/
private String address;
/**
* 运输方式
*/
private String transportationMethod;
/**
* 运输方式说明
*/
private String transportationMethodDescription;
/**
* 快递单号
*/
private String expressNumber;
/**
* 订单单号
*/
private String orderNumber;
/**
* 项次
*/
private Integer itemSequenceAgain;
/**
* 订单状态
*/
private String orderStatus;
/**
* 项序
*/
private Integer itemOrder;
/**
* 分批序
*/
private Integer batchSequence;
/**
* 客户订购单号
*/
private String customerOrderNumber;
/**
* 客户料号
*/
private String customerMaterialNumber;
/**
* 客户料号品名
*/
private String customerMaterialName;
/**
* 客户料号规格
*/
private String customerMaterialSpecification;
/**
* 子件特性
*/
private String subPartFeature;
/**
* 产品分类
*/
private String productCategory;
/**
* 产品分类说明
*/
private String productCategoryDescription;
/**
* 销售分群
*/
private String salesGroup;
/**
* 销售分群说明
*/
private String salesGroupDescription;
/**
* 料件编号
*/
private String materialNumber;
/**
* 品名
*/
private String productName;
/**
* 规格
*/
private String productSpecification;
/**
* 品牌
*/
private String brand;
/**
* 克重
*/
private BigDecimal weightGram;
/**
* 口味说明
*/
private String tasteDescription;
/**
* 克重
*/
private String weightGramAgain;
/**
* 克重说明
*/
private String weightGramDescription;
/**
* 产品特征
*/
private String productFeature;
/**
* 产品特征说明
*/
private String productFeatureDescription;
/**
* 数量
*/
private Integer quantity;
/**
* 出货单位
*/
private String shippingUnit;
/**
* 已验收数量
*/
private Integer acceptedQuantity;
/**
* 已签退量
*/
private Integer signedBackQuantity;
/**
* 未签收量
*/
private Integer unsignedQuantity;
/**
* 库位
*/
private String storageLocation;
/**
* 库位名称
*/
private String storageLocationName;
/**
* 储位
*/
private String storagePosition;
/**
* 储位名称
*/
private String storagePositionName;
/**
* 批号
*/
private String batchNumber;
/**
* 库存管理特征
*/
private String inventoryManagementFeature;
/**
* 备注
*/
private String remarks;
/**
* 单价
*/
private BigDecimal unitPrice;
/**
* 含税金额
*/
private BigDecimal amountWithTax;
/**
* 税额
*/
private BigDecimal taxAmount;
/**
* 币种
*/
private String currency;
/**
* 汇率
*/
private BigDecimal exchangeRate;
/**
* 本币税前金额
*/
private BigDecimal localPreTaxAmount;
/**
* 本币含税金额
*/
private BigDecimal localAmountWithTax;
/**
* 本币税额
*/
private BigDecimal localTaxAmount;
/**
* 折扣金额
*/
private BigDecimal discountAmount;
/**
* 折扣金额(开票)
*/
private BigDecimal discountAmountInvoice;
/**
* 多角序号
*/
private String multiAngleSequenceNumber;
/**
* 客户分类
*/
private String customerCategory;
/**
* 客户分类说明
*/
private String customerCategoryDescription;
/**
* 销售渠道
*/
private String salesChannel;
/**
* 销售渠道说明
*/
private String salesChannelDescription;
/**
* 订单类型
*/
private String orderType;
/**
* 类型说明
*/
private String typeDescription;
/**
* 备注
*/
private String remarksAgain;
/**
* 物流备注
*/
private String logisticsRemarks;
/**
* 第三方系统标识码
*/
private String thirdPartySystemCode;
/**
* 资料录入日期
*/
private Date dataEntryDate;
/**
* 打款类型说明
*/
private String paymentTypeDescription;
/**
* 订单拆单状态
*/
private String orderSplitStatus;
/**
* 基础单位
*/
private String baseUnit;
/**
* 订单基础单位数量
*/
private Integer orderBaseUnitQuantity;
/**
* 标准成本
*/
private BigDecimal standardCost;
/**
* 实际成本
*/
private BigDecimal actualCost;
/**
* 采集批次
*/
private String collectionBatch;
/**
* 采集时间
*/
private Date collectionTime;
@TableField(exist = false)
private static final long serialVersionUID = 1L;
}
\ No newline at end of file
package com.sfa.job.domain.erp.mapper;
import com.sfa.job.domain.erp.entity.ErpAxmr005ShippingDetails;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.springframework.stereotype.Repository;
import java.util.Date;
import java.util.List;
/**
* @author a02200059
* @description 针对表【erp_axmr005_shipping_details(erp_axmr005出货明细表)】的数据库操作Mapper
* @createDate 2025-04-08 13:10:15
* @Entity com.sfa.job.domain.erp.entity.ErpAxmr005ShippingDetails
*/
@Repository
public interface ErpAxmr005ShippingDetailsMapper extends BaseMapper<ErpAxmr005ShippingDetails> {
List<ErpAxmr005ShippingDetails> getZhanquDataset(Date date);
}
package com.sfa.job.domain.use.dao;
import com.sfa.job.pojo.response.FeishuSheetRecordDto;
/**
* @author : liqiulin
* @date : 2025-04-08 17
* @describe :
*/
public interface FeishuSheetRecordDao {
FeishuSheetRecordDto selectOne(Integer type, String createMonth);
}
package com.sfa.job.domain.use.dao;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.sfa.common.core.utils.bean.BeanUtils;
import com.sfa.job.domain.use.entity.FeishuSheetRecord;
import com.sfa.job.domain.use.mapper.FeishuSheetRecordMapper;
import com.sfa.job.pojo.response.FeishuSheetRecordDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
* @author : liqiulin
* @date : 2025-04-08 17
* @describe :
*/
@DS("bi")
@Service
public class FeishuSheetRecordDaoImpl implements FeishuSheetRecordDao{
@Autowired
private FeishuSheetRecordMapper feishuSheetRecordMapper;
@Override
public FeishuSheetRecordDto selectOne(Integer type, String createMonth) {
FeishuSheetRecord feishuSheetRecord = feishuSheetRecordMapper.findOne(type, createMonth);
return BeanUtils.transitionDto(feishuSheetRecord, FeishuSheetRecordDto.class);
}
}
package com.sfa.job.domain.use.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import java.io.Serializable;
import lombok.Data;
/**
* 推广图片推送至飞书电子表格-分月表
* @TableName feishu_sheet_record
*/
@TableName(value ="feishu_sheet_record")
@Data
public class FeishuSheetRecord implements Serializable {
/**
* 主键id
*/
@TableId(type = IdType.AUTO)
private Integer id;
/**
* 电子表格token
*/
private String sheetToken;
/**
* 工作表id
*/
private String sheetId;
/**
* 创建月份
*/
private String createMonth;
/**
* 1:axmr005_战区(每天);2:axmr005_战区(每月);
*/
private Integer type;
@TableField(exist = false)
private static final long serialVersionUID = 1L;
}
\ No newline at end of file
package com.sfa.job.domain.use.mapper;
import com.sfa.job.domain.use.entity.FeishuSheetRecord;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;
/**
* @author a02200059
* @description 针对表【feishu_sheet_record(推广图片推送至飞书电子表格-分月表)】的数据库操作Mapper
* @createDate 2025-04-08 17:07:31
* @Entity com.sfa.job.xxljob.use.entity.FeishuSheetRecord
*/
@Repository
public interface FeishuSheetRecordMapper extends BaseMapper<FeishuSheetRecord> {
FeishuSheetRecord findOne(@Param("type") Integer type,@Param("createMonth") String createMonth);
}
package com.sfa.job.enums;
import lombok.Getter;
/**
* @author : liqiulin
* @date : 2025-04-08 18
* @describe :
*/
@Getter
public enum FSRecordEnum {
/**
* 1:axmr005_战区(每天)
*/
AXMR005_1(1),
AXMR005_2(2),
;
private Integer type;
FSRecordEnum(Integer type) {
this.type = type;
}
}
package com.sfa.job.pojo.response;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* @author : liqiulin
* @date : 2025-04-08 17
* @describe :
*/
@AllArgsConstructor
@NoArgsConstructor
@Data
public class FeishuSheetRecordDto {
/**
* 主键id
*/
private Integer id;
/**
* 电子表格token
*/
private String sheetToken;
/**
* 工作表id
*/
private String sheetId;
/**
* 创建月份
*/
private String createMonth;
/**
* 1:axmr005_战区(每天);2:axmr005_战区(每月);
*/
private Integer type;
}
package com.sfa.job.service.erp;
import java.util.Date;
/**
* @author : liqiulin
* @date : 2025-04-08 13
* @describe :
*/
public interface ErpAxmr005Service {
void axmr005ZQToFS(Date debitDate,Integer type);
}
package com.sfa.job.service.erp.impl;
import com.alibaba.fastjson2.JSONObject;
import com.sfa.common.core.utils.DateUtils;
import com.sfa.job.domain.erp.dao.ErpAxmr005ShippingDetailsDao;
import com.sfa.job.pojo.response.FeishuSheetRecordDto;
import com.sfa.job.service.erp.ErpAxmr005Service;
import com.sfa.job.util.FeiShuUtil;
import com.sfa.job.domain.use.dao.FeishuSheetRecordDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.List;
/**
* @author : liqiulin
* @date : 2025-04-08 13
* @describe :
*/
@Service
public class ErpAxmr005ServiceImpl implements ErpAxmr005Service {
@Autowired
private ErpAxmr005ShippingDetailsDao erpAxmr005ShippingDetailsDao;
@Autowired
private FeishuSheetRecordDao feishuSheetRecordDao;
@Autowired
private FeiShuUtil feiShuUtil;
@Override
public void axmr005ZQToFS(Date debitDate,Integer type) {
List<Object> zhanquDataset = erpAxmr005ShippingDetailsDao.getZhanquDataset(debitDate);
FeishuSheetRecordDto recordDto = feishuSheetRecordDao.selectOne(type, DateUtils.parseDateToStr(DateUtils.YYYY_MM, debitDate));
/**
* 将结果推送到飞书表格,每次推100条
*/
String range = recordDto.getSheetId() + "!A:H";
JSONObject botToken1 = feiShuUtil.getBotToken1();
int batchSize = 100;
for (int i = 0; i < zhanquDataset.size(); i+=batchSize) {
// 计算当前批次的结束位置
int end = Math.min(i + batchSize, zhanquDataset.size());
System.out.println(end);
List<Object> batch = zhanquDataset.subList(i, end);
feiShuUtil.pushSetToSheet(range,batch,recordDto.getSheetToken(),botToken1.getString("tenant_access_token"));
}
}
}
package com.sfa.job.util; package com.sfa.job.util;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson2.JSONArray; import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject; import com.alibaba.fastjson2.JSONObject;
import com.google.gson.JsonParser; import com.google.gson.JsonParser;
...@@ -16,6 +17,11 @@ import lombok.extern.slf4j.Slf4j; ...@@ -16,6 +17,11 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/** /**
* @author : liqiulin * @author : liqiulin
* @date : 2024-12-06 16 * @date : 2024-12-06 16
...@@ -30,6 +36,20 @@ public class FeiShuUtil { ...@@ -30,6 +36,20 @@ public class FeiShuUtil {
@Value("${feishu.luzx.app_secret}") @Value("${feishu.luzx.app_secret}")
private String appSecret; private String appSecret;
@Value("${feishu.bot_1.app_id}")
private String botAppId1;
@Value("${feishu.bot_1.app_secret}")
private String botAppSecret1;
private static final String CONTENT_TYPE = "application/json; charset=utf-8";
private static final String SHEET_URL = "https://open.feishu.cn/open-apis/sheets/v2/spreadsheets/";
private static final String TENANT_ACCESS_TOKEN_URL = "https://open.feishu.cn/open-apis/auth/v3/tenant_access_token/internal";
private static final String VALUES_APPEND = "/values_append";
private static final String VALUES_IMAGE = "/values_image";
private static final String VALUES = "/values";
/** /**
* 根据部门父编码获取子部门 * 根据部门父编码获取子部门
* 公司编码:"0" * 公司编码:"0"
...@@ -56,6 +76,9 @@ public class FeiShuUtil { ...@@ -56,6 +76,9 @@ public class FeiShuUtil {
return null; return null;
} }
/**
* 获取部门用户
*/
public JSONArray getUsersByDeptId(String deptCode) { public JSONArray getUsersByDeptId(String deptCode) {
try { try {
Client client = getClient(); Client client = getClient();
...@@ -82,4 +105,44 @@ public class FeiShuUtil { ...@@ -82,4 +105,44 @@ public class FeiShuUtil {
private Client getClient() { private Client getClient() {
return Client.newBuilder(appId, appSecret).build(); return Client.newBuilder(appId, appSecret).build();
} }
public Integer pushSetToSheet(String range, List<Object> datas, String sheetToken, String autoToken) {
// 组装参数
Map<String, Map<String, Object>> bodyMap = new HashMap<>();
Map<String, Object> valueRange = new HashMap<>();
valueRange.put("range", range);
valueRange.put("values", datas);
bodyMap.put("valueRange", valueRange);
String bodyJson = JSONObject.toJSONString(bodyMap);
// body上传
String result = HttpUtil.createPost(SHEET_URL + sheetToken + VALUES_APPEND)
.auth("Bearer " + autoToken).contentType(CONTENT_TYPE)
.body(bodyJson)
.execute().body();
// 上传结果判断
JSONObject resultJson = JSONObject.parseObject(result);
return resultJson.getInteger("code");
}
public JSONObject getBotToken1() {
Map<String, Object> bodyMap = new HashMap<>();
bodyMap.put("app_id", botAppId1);
bodyMap.put("app_secret", botAppSecret1);
String bodyJson = JSONObject.toJSONString(bodyMap);
String result = HttpUtil.createPost(TENANT_ACCESS_TOKEN_URL)
.contentType(CONTENT_TYPE)
.body(bodyJson)
.execute().body();
JSONObject resultJson = JSONObject.parseObject(result);
int code = resultJson.getInteger("code");
if (code != 0) {
throw new RuntimeException("获取tenant_access_token错误");
}
return resultJson;
}
} }
package com.sfa.job.xxljob.erp;
import com.sfa.common.core.utils.DateUtils;
import com.sfa.job.enums.FSRecordEnum;
import com.sfa.job.service.erp.ErpAxmr005Service;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.Date;
/**
* @author : liqiulin
* @date : 2025-04-08 13
* @describe :
*/
@Component
@Slf4j
public class shippingTask {
@Autowired
private ErpAxmr005Service erpAxmr005Service;
/**
* 同步axmr005中t-1的数据到飞书表格
* 只同步线下战区数据、部分字段
*/
@XxlJob("axmr005_zhanqu_days")
public void axmr005ZQByDays() {
Date date = DateUtils.addDays(new Date(), -1);
Integer type = FSRecordEnum.AXMR005_1.getType();
axmr005ZQToFSByDate(date,type);
}
@XxlJob("axmr005_zhanqu_month")
public void axmr005ZQByMonth() {
Date date = DateUtils.addDays(new Date(), -4);
Integer type = FSRecordEnum.AXMR005_2.getType();
axmr005ZQToFSByDate(date,type);
}
private void axmr005ZQToFSByDate(Date date,Integer type) {
erpAxmr005Service.axmr005ZQToFS(date,type);
}
}
...@@ -29,7 +29,7 @@ public class FinanceOrderTask { ...@@ -29,7 +29,7 @@ public class FinanceOrderTask {
FinanceOrderSyncService financeOrderSyncService; FinanceOrderSyncService financeOrderSyncService;
/** /**
* 同步部门数据 * 同步财务订单数据
*/ */
@XxlJob("syncWangdiantongOrderDetail") @XxlJob("syncWangdiantongOrderDetail")
public SyncOrderDetailDto syncWangdiantongOrderDetail() { public SyncOrderDetailDto syncWangdiantongOrderDetail() {
......
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.sfa.job.domain.use.mapper.FeishuSheetRecordMapper">
<resultMap id="BaseResultMap" type="com.sfa.job.domain.use.entity.FeishuSheetRecord">
<id property="id" column="id" jdbcType="INTEGER"/>
<result property="sheetToken" column="sheet_token" jdbcType="VARCHAR"/>
<result property="sheetId" column="sheet_id" jdbcType="VARCHAR"/>
<result property="createMonth" column="create_month" jdbcType="VARCHAR"/>
<result property="type" column="type" jdbcType="INTEGER"/>
</resultMap>
<sql id="Base_Column_List">
id,sheet_token,sheet_id,
create_month,type
</sql>
<select id="findOne" resultMap="BaseResultMap">
select <include refid="Base_Column_List"/>
from feishu_sheet_record where type = #{type} and create_month = #{createMonth}
</select>
</mapper>
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论