思迅同步品牌问题修复
This commit is contained in:
parent
d1ef71669e
commit
da259b15e9
@ -3,29 +3,16 @@ package com.small.client.dao;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.json.JSONArray;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.google.gson.Gson;
|
||||
import com.small.client.Utils.BigDecimalFormatter;
|
||||
import com.small.client.Utils.CommonUtil;
|
||||
import com.small.client.Utils.HttpUtils;
|
||||
import com.small.client.Utils.SqlBuilder;
|
||||
import com.small.client.dto.*;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.lang3.math.NumberUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.sql.*;
|
||||
import java.sql.Date;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 考虑到每个思迅软件都是自己的数据,所以采用动态获取的方式获取数据
|
||||
@ -35,12 +22,9 @@ import java.util.stream.Collectors;
|
||||
@Service
|
||||
@Slf4j
|
||||
public class SxDataDao extends BaseDao{
|
||||
@Autowired
|
||||
private RestTemplate restTemplate;
|
||||
@Value("${remoteIp}")
|
||||
private String remoteIp;
|
||||
|
||||
private final static String T_BD_ITEM_CLS="t_bd_item_cls";//商品分类
|
||||
private final static String T_BD_ITEM_INFO="t_bd_item_info b";//商品表
|
||||
private final static String T_BD_ITEM_INFO="t_bd_item_info";//商品表
|
||||
private final static String T_RM_VIP_INFO="t_rm_vip_info";//会员表
|
||||
|
||||
private final static String ITEM_CLSNO="item_clsno";//商品分类排序字段
|
||||
@ -54,10 +38,6 @@ public class SxDataDao extends BaseDao{
|
||||
|
||||
//private final static String T_IM_BRANCH_STOCK="t_im_branch_stock";//库存表
|
||||
|
||||
private final static String T_BD_BRANCH_INFO="t_bd_branch_info";//仓库表
|
||||
|
||||
private final static String T_RM_CASHIER="t_rm_cashier";//小发收银账号
|
||||
|
||||
private final static String T_IM_BRANCH_STOCK="(" +
|
||||
"select * from( " +
|
||||
" select ROW_NUMBER() OVER( " +
|
||||
@ -72,12 +52,9 @@ public class SxDataDao extends BaseDao{
|
||||
|
||||
public final static String DEFALTWHERE="where 1=1";
|
||||
|
||||
public final static String DEFAULT_IMG="https://media-mall-prod-1259811287.cos.ap-guangzhou.myqcloud.com/media/media/plantform/20250906/b93a9751b35a49fca6cf979829230868.png";
|
||||
public final static String DEFAULT_IMG="https://digitalassets.tesla.com/tesla-contents/image/upload/f_auto,q_auto/Homepage-Model-Y-2-Promo-Hero-Tablet-CN.png";
|
||||
|
||||
|
||||
private final static String T_PUB_PLAN_MASTER="t_pub_plan_master";//活动方案表
|
||||
private final static String T_PUB_PLAN_DETAIL_B="t_pub_plan_detail_b";//活动商品表
|
||||
private final static String PLAN_NO="plan_no";//活动方案表排序字段
|
||||
/**
|
||||
* 查找商品分类数据
|
||||
* @param dataBaseInfo
|
||||
@ -178,12 +155,8 @@ public class SxDataDao extends BaseDao{
|
||||
* @return
|
||||
*/
|
||||
public int getTBditemInfoJoninTotal(DataBaseInfo dataBaseInfo){
|
||||
String stockOperateWhere="";
|
||||
if(StringUtils.isNotEmpty(dataBaseInfo.getStockOperateWhere())){
|
||||
stockOperateWhere="where "+dataBaseInfo.getStockOperateWhere();
|
||||
}
|
||||
return getBaseGoodsJoinTotal(dataBaseInfo.getIp(),dataBaseInfo.getUserName(),dataBaseInfo.getPassword(),dataBaseInfo.getDbPort(),dataBaseInfo.getDataBaseName()
|
||||
,dataBaseInfo.getWhere()==null?DEFALTWHERE:dataBaseInfo.getWhere(),stockOperateWhere);
|
||||
,dataBaseInfo.getWhere()==null?DEFALTWHERE:dataBaseInfo.getWhere());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -204,12 +177,8 @@ public class SxDataDao extends BaseDao{
|
||||
* @param pageSize
|
||||
*/
|
||||
public List<SxSyncGoods> findBditemInfoListPage(DataBaseInfo dataBaseInfo,int pageNo,int pageSize){
|
||||
String stockOperateWhere="";
|
||||
if(StringUtils.isNotEmpty(dataBaseInfo.getStockOperateWhere())){
|
||||
stockOperateWhere=" and "+dataBaseInfo.getStockOperateWhere();
|
||||
}
|
||||
ResultDto resultDto=baseFindGoodsListJoinPage(dataBaseInfo.getIp(),dataBaseInfo.getUserName(),dataBaseInfo.getPassword(),dataBaseInfo.getDbPort(),dataBaseInfo.getDataBaseName()
|
||||
,pageNo,pageSize,dataBaseInfo.getWhere()==null?DEFALTWHERE:dataBaseInfo.getWhere(),stockOperateWhere);
|
||||
,pageNo,pageSize,dataBaseInfo.getWhere()==null?DEFALTWHERE:dataBaseInfo.getWhere());
|
||||
ResultSet rs= resultDto.getResultSet();
|
||||
List<SxSyncGoods> sxSyncGoodses=new ArrayList<>();
|
||||
SxSyncGoods sxSyncGoods=null;
|
||||
@ -486,21 +455,16 @@ public class SxDataDao extends BaseDao{
|
||||
* @param dataBaseInfo
|
||||
* @param map
|
||||
*/
|
||||
public void updateStoreData(DataBaseInfo dataBaseInfo, Map map,Map<String,ProductQuantityConsumptionDto> pqMap,List<ProductQuantityConsumptionDto> productQuantityConsumptionDtoList,
|
||||
CommentModel commentModel){
|
||||
public void updateStoreData(DataBaseInfo dataBaseInfo, Map map){
|
||||
if(CollectionUtil.isEmpty(map)){
|
||||
log.info("同步数据为空");
|
||||
return;
|
||||
}
|
||||
String brachNo=getLocalBranch(dataBaseInfo);//获取总店铺分仓编号
|
||||
Map<String,ItemInfo> itemInfoMap= findItemInfoList(dataBaseInfo,map);//查询商品信息
|
||||
Connection conn =getConnection(dataBaseInfo.getIp(),dataBaseInfo.getUserName(),
|
||||
Connection conn =getConnection(dataBaseInfo.getIp(),dataBaseInfo.getUserName(),
|
||||
dataBaseInfo.getPassword(), dataBaseInfo.getDbPort(),dataBaseInfo.getDataBaseName());
|
||||
try {
|
||||
conn.setAutoCommit(false); // 关闭自动提交,开启事务
|
||||
//String sql = "update t_im_branch_stock set stock_qty= stock_qty+(?),oper_date=? where item_no=?";
|
||||
List<RmSaleflow> rmSaleflowList=new ArrayList<>();
|
||||
List<TRmPayflow> tRmPayflowList=new ArrayList<>();
|
||||
String sql = "WITH TopStock AS ( " +
|
||||
" SELECT TOP(1) * " +
|
||||
" FROM t_im_branch_stock " +
|
||||
@ -511,34 +475,12 @@ public class SxDataDao extends BaseDao{
|
||||
" SET stock_qty = stock_qty+(?),oper_date=?;";
|
||||
Timestamp timestamp = new Timestamp(System.currentTimeMillis());
|
||||
try (PreparedStatement ps = conn.prepareStatement(sql)) {
|
||||
int batchSize = 100; // 每批处理1000条
|
||||
int batchSize = 1000; // 每批处理1000条
|
||||
int count = 0;
|
||||
Set<Map.Entry> sme=map.entrySet();
|
||||
for (Map.Entry entry : sme) {
|
||||
String key=entry.getKey().toString();
|
||||
String[] splitKey = key.split("-");
|
||||
if(splitKey.length!=2){
|
||||
continue;
|
||||
}
|
||||
String itemNo = splitKey[1];
|
||||
BigDecimal stock_qty= (BigDecimal) entry.getValue();
|
||||
|
||||
if(stock_qty.compareTo(BigDecimal.ZERO)==0){
|
||||
continue;
|
||||
}
|
||||
ProductQuantityConsumptionDto productQuantityConsumptionDto=pqMap.get(key);
|
||||
if(productQuantityConsumptionDto.getSaleAmount().compareTo(BigDecimal.ZERO)==0){
|
||||
continue;
|
||||
}
|
||||
RmSaleflow rmSaleflow = getRmSaleflow(productQuantityConsumptionDto, itemNo, stock_qty);
|
||||
rmSaleflow= fixRmSaleFlow(rmSaleflow,brachNo,itemInfoMap,dataBaseInfo.getSaleAccount());
|
||||
TRmPayflow trmPayflow=fixTRmPayflow(rmSaleflow);
|
||||
|
||||
rmSaleflowList.add(rmSaleflow);
|
||||
tRmPayflowList.add(trmPayflow);
|
||||
|
||||
ps.setString(1, itemNo);
|
||||
ps.setDouble(2, stock_qty.doubleValue());
|
||||
ps.setString(1, (String) entry.getKey());
|
||||
ps.setDouble(2, (double) entry.getValue());
|
||||
ps.setTimestamp(3, timestamp);
|
||||
ps.addBatch(); // 添加至批处理
|
||||
count++;
|
||||
@ -550,393 +492,27 @@ public class SxDataDao extends BaseDao{
|
||||
}
|
||||
// 执行剩余未满 batchSize 的批次
|
||||
int[] remainingCounts = ps.executeBatch();
|
||||
|
||||
//todo 新增流水
|
||||
updateStoreSaleFlow(conn,rmSaleflowList,tRmPayflowList);
|
||||
|
||||
List<String> consumIds=productQuantityConsumptionDtoList
|
||||
.stream()
|
||||
.map(ProductQuantityConsumptionDto::getConsumeId)
|
||||
.collect(Collectors.toList());
|
||||
Gson gson=new Gson();
|
||||
String jsonString=gson.toJson(consumIds);
|
||||
JSONArray jsonArray = JSONUtil.parseArray(jsonString);
|
||||
String sign= CommonUtil.generateOpenSign(jsonString,commentModel.getAppKey(),commentModel.getAppId());
|
||||
String code= HttpUtils.postData(restTemplate,remoteIp+HttpUtils.URL_SYNC_POST_STORE_DATA_RESPONSE
|
||||
+"?appKey="+commentModel.getAppKey()
|
||||
+"&sign="+sign, jsonArray);
|
||||
if (!HttpUtils.SUCCESSCODE.equals(code)) {
|
||||
throw new Exception("服务器异常");
|
||||
}
|
||||
log.info("库存更新剩余批次更新数: {}", Arrays.toString(remainingCounts));
|
||||
log.info("剩余批次更新数: {}", Arrays.toString(remainingCounts));
|
||||
conn.commit(); // 最终提交事务
|
||||
log.info("批量更新完成,总记录数: {}" , count);
|
||||
//baseUpdateImBrancStock(dataBaseInfo);
|
||||
} catch (Exception e) {
|
||||
} catch (SQLException e) {
|
||||
conn.rollback(); // 出错时回滚整个事务
|
||||
log.info("业务失败:: {}", e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
log.info("sql失败:: {}", e.getMessage());
|
||||
e.printStackTrace();
|
||||
}finally {
|
||||
if(conn!=null){
|
||||
try {
|
||||
conn.close();
|
||||
} catch (SQLException e) {
|
||||
log.info("最后sql失败:: {}", e.getMessage());
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 封装对象
|
||||
* @param productQuantityConsumptionDto
|
||||
* @param itemNo
|
||||
* @param stock_qty
|
||||
* @return
|
||||
*/
|
||||
private RmSaleflow getRmSaleflow(ProductQuantityConsumptionDto productQuantityConsumptionDto, String itemNo, BigDecimal stock_qty) {
|
||||
BigDecimal unitPrice = productQuantityConsumptionDto.getUnitPrice();
|
||||
RmSaleflow rmSaleflow=new RmSaleflow();
|
||||
rmSaleflow.setItemNo(itemNo);
|
||||
rmSaleflow.setSalePrice(unitPrice);
|
||||
rmSaleflow.setSaleQnty(stock_qty);
|
||||
rmSaleflow.setSaleMoney(productQuantityConsumptionDto.getSaleAmount());
|
||||
// rmSaleflow.setSourcePrice(unitPrice);
|
||||
rmSaleflow.setFlownoRand(productQuantityConsumptionDto.getOrderId());//随机子单号 设置网上订单号
|
||||
return rmSaleflow;
|
||||
}
|
||||
|
||||
/**
|
||||
* 补充字段
|
||||
* @param rmSaleflow
|
||||
* @return
|
||||
*/
|
||||
public RmSaleflow fixRmSaleFlow(RmSaleflow rmSaleflow,String branchNo,Map<String,ItemInfo> itemInfoMap,String saleAccount){
|
||||
//自定义单号 start
|
||||
rmSaleflow.setFlowId(1);
|
||||
String orderId=rmSaleflow.getFlownoRand();
|
||||
String[] orderIdSplits= orderId.split("_");
|
||||
//String DateStr=DateUtil.format(new java.util.Date(),"yyyyMMdd");
|
||||
String DateStr=orderIdSplits[1];
|
||||
String number= String.format("%04d", Integer.valueOf(orderIdSplits[orderIdSplits.length-1]));
|
||||
String flowNo="99"+DateStr+number;
|
||||
rmSaleflow.setFlowNo(flowNo);//订单号 todo
|
||||
//自定义 单号 end
|
||||
|
||||
//判断取值 start
|
||||
rmSaleflow.setSellWay("B");
|
||||
rmSaleflow.setRetQnty(rmSaleflow.getSaleQnty());
|
||||
if(rmSaleflow.getSaleQnty().compareTo(BigDecimal.ZERO)<0){
|
||||
rmSaleflow.setSellWay("A");
|
||||
BigDecimal saleQnty=rmSaleflow.getSaleQnty();//销售数量
|
||||
rmSaleflow.setSaleQnty(saleQnty);
|
||||
rmSaleflow.setRetQnty(BigDecimal.ZERO);
|
||||
}
|
||||
// BigDecimal saleMoney=rmSaleflow.getSalePrice().multiply(rmSaleflow.getSaleQnty());
|
||||
// if(rmSaleflow.getSaleQnty().compareTo(BigDecimal.ZERO)<0){
|
||||
// saleMoney=saleMoney.multiply(new BigDecimal("-1"));
|
||||
// }
|
||||
// rmSaleflow.setSaleMoney(saleMoney);
|
||||
//判断取值 end
|
||||
|
||||
//数据库查询取值start todo
|
||||
ItemInfo itemInfo=itemInfoMap.get(rmSaleflow.getItemNo());
|
||||
if(itemInfo!=null){
|
||||
rmSaleflow.setInPrice(itemInfo.getPrice());
|
||||
rmSaleflow.setSourcePrice(itemInfo.getSalePrice());
|
||||
rmSaleflow.setOperDate(new Timestamp(System.currentTimeMillis()));
|
||||
}
|
||||
rmSaleflow.setBranchNo(branchNo);
|
||||
|
||||
//数据库查询取值end
|
||||
|
||||
//远程配置取值start todo
|
||||
rmSaleflow.setOperId(saleAccount);
|
||||
rmSaleflow.setSaleMan(saleAccount);
|
||||
rmSaleflow.setCounterNo(saleAccount);
|
||||
//远程配置取值end
|
||||
|
||||
//统一默认值 start
|
||||
rmSaleflow.setNStan(BigDecimal.ZERO);
|
||||
rmSaleflow.setChrStan("0");
|
||||
rmSaleflow.setFlownoType("0");
|
||||
rmSaleflow.setPrefAmt(BigDecimal.ZERO);
|
||||
rmSaleflow.setComFlag("0");
|
||||
rmSaleflow.setRemoteFlag("0");
|
||||
//统一默认值 end
|
||||
return rmSaleflow;
|
||||
}
|
||||
|
||||
/**
|
||||
* 支付流水赋值
|
||||
* @return
|
||||
*/
|
||||
public TRmPayflow fixTRmPayflow(RmSaleflow rmSaleflow){
|
||||
TRmPayflow rmPayflow=new TRmPayflow();
|
||||
rmPayflow.setFlowId(rmSaleflow.getFlowId());
|
||||
rmPayflow.setFlowNo(rmSaleflow.getFlowNo());
|
||||
// BigDecimal saleAmount=rmSaleflow.getSalePrice().multiply(rmSaleflow.getSaleQnty()).setScale(2, RoundingMode.HALF_UP);
|
||||
// if(saleAmount.compareTo(BigDecimal.ZERO)<0){
|
||||
// saleAmount=saleAmount.multiply(new BigDecimal("-1"));
|
||||
// }
|
||||
// rmPayflow.setSaleAmount(saleAmount);
|
||||
rmPayflow.setSaleAmount(rmSaleflow.getSaleMoney());
|
||||
rmPayflow.setBranchNo(rmSaleflow.getBranchNo());
|
||||
rmPayflow.setPayWay("RMB");//人民币
|
||||
rmPayflow.setSellWay(rmSaleflow.getSellWay());
|
||||
rmPayflow.setCardNo("");
|
||||
rmPayflow.setVipNo(null);
|
||||
rmPayflow.setCoinNo("RMB");//
|
||||
rmPayflow.setCoinRate(new BigDecimal("1"));//利率
|
||||
rmPayflow.setPayAmount(rmSaleflow.getSaleMoney());
|
||||
rmPayflow.setOperDate(new Timestamp(System.currentTimeMillis()));
|
||||
rmPayflow.setOperId(rmSaleflow.getOperId());
|
||||
rmPayflow.setCounterNo(rmSaleflow.getCounterNo());
|
||||
rmPayflow.setSaleMan(rmSaleflow.getSaleMan());
|
||||
rmPayflow.setMemo("");
|
||||
rmPayflow.setVoucherNo("");//退货单号 退货时要填
|
||||
rmPayflow.setRemoteFlag("0");
|
||||
rmPayflow.setExchangeFlag("0");
|
||||
rmPayflow.setShiftNo("");
|
||||
rmPayflow.setComFlag("0");
|
||||
rmPayflow.setPosid("01");
|
||||
rmPayflow.setUptime(null);
|
||||
rmPayflow.setFlownoRand(rmSaleflow.getFlownoRand());
|
||||
rmPayflow.setCiceroniNo("0");
|
||||
rmPayflow.setCiceroniId(null);
|
||||
rmPayflow.setFlownoType(rmSaleflow.getFlownoType());
|
||||
rmPayflow.setTransType(null);
|
||||
rmPayflow.setUpBatchno("");//todo
|
||||
rmPayflow.setUpVipacc("0");
|
||||
rmPayflow.setCashNo("00");
|
||||
if("B".equals(rmSaleflow.getSellWay())){//退货
|
||||
rmPayflow.setMemo("正常退货");
|
||||
rmPayflow.setVoucherNo("");//退货单号 退货时要填
|
||||
rmPayflow.setRemoteFlag("");
|
||||
rmPayflow.setExchangeFlag("0");
|
||||
rmPayflow.setUpVipacc(null);
|
||||
}
|
||||
|
||||
return rmPayflow;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询商品,返回map
|
||||
* @param dataBaseInfo
|
||||
* @param map
|
||||
* @return
|
||||
*/
|
||||
public Map<String,ItemInfo> findItemInfoList(DataBaseInfo dataBaseInfo,Map map){
|
||||
if(CollectionUtil.isEmpty(map)){
|
||||
return null;
|
||||
}
|
||||
Map<String,ItemInfo> resultMap=new HashMap<>();
|
||||
Set<Map.Entry> sme=map.entrySet();
|
||||
String where = "where 1=1 and ";
|
||||
List<String> itemNos = sme.stream()
|
||||
.map(entry -> {
|
||||
String key= (String) entry.getKey();
|
||||
String[] split = key.split("-");
|
||||
return split[1];
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
where += SqlBuilder.buildInCondition("item_no", itemNos);
|
||||
ResultDto resultDto= this.baseFindList(dataBaseInfo.getIp(),dataBaseInfo.getUserName(),dataBaseInfo.getPassword(),
|
||||
dataBaseInfo.getDbPort(),dataBaseInfo.getDataBaseName(),T_BD_ITEM_INFO,where);
|
||||
ResultSet rs= resultDto.getResultSet();
|
||||
try {
|
||||
while (rs.next()) {
|
||||
ItemInfo itemInfo=new ItemInfo();
|
||||
String itemNo=rs.getString("item_no").trim();
|
||||
itemInfo.setItemNo(itemNo);//
|
||||
if(StringUtils.isNotEmpty(rs.getString("item_subno"))){
|
||||
itemInfo.setItemSubno(rs.getString("item_subno").trim());
|
||||
}
|
||||
if(StringUtils.isNotEmpty(rs.getString("item_name"))){
|
||||
itemInfo.setItemName(rs.getString("item_name").trim());
|
||||
}
|
||||
if(StringUtils.isNotEmpty(rs.getString("item_brand"))){
|
||||
itemInfo.setItemBrand(rs.getString("item_brand").trim());//品牌
|
||||
}
|
||||
if(StringUtils.isNotEmpty(rs.getString("price"))){
|
||||
itemInfo.setPrice(rs.getBigDecimal("price"));//进货价
|
||||
}
|
||||
if(StringUtils.isNotEmpty(rs.getString("item_clsno"))){
|
||||
itemInfo.setItemClsno(rs.getString("item_clsno").trim());
|
||||
}
|
||||
if(StringUtils.isNotEmpty(rs.getString("sale_price"))){
|
||||
itemInfo.setSalePrice(rs.getBigDecimal("sale_price"));
|
||||
}
|
||||
resultMap.put(itemNo,itemInfo);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
} finally {
|
||||
try {
|
||||
resultDto.getConnection().close();
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
return resultMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量新增销售流水
|
||||
* @param conn
|
||||
* @param rmSaleflowList
|
||||
*/
|
||||
public void updateStoreSaleFlow(Connection conn,List<RmSaleflow> rmSaleflowList,List<TRmPayflow> payflowList){
|
||||
if(CollectionUtil.isEmpty(rmSaleflowList)){
|
||||
log.info("销售流水记录为空");
|
||||
return;
|
||||
}
|
||||
// Connection conn =getConnection(dataBaseInfo.getIp(),dataBaseInfo.getUserName(),
|
||||
// dataBaseInfo.getPassword(), dataBaseInfo.getDbPort(),dataBaseInfo.getDataBaseName());
|
||||
//try {
|
||||
//conn.setAutoCommit(false); // 关闭自动提交,开启事务
|
||||
String sql = "INSERT INTO t_rm_saleflow (" +
|
||||
"flow_id, flow_no, branch_no, item_no, source_price, sale_price, " +
|
||||
"sale_qnty, sale_money, sell_way, oper_id, sale_man, counter_no, " +
|
||||
"oper_date, remote_flag, shift_no, com_flag, spec_flag, pref_amt, " +
|
||||
"in_price, n_stan, chr_stan, posid, uptime, flowno_rand, ret_qnty, " +
|
||||
"flowno_type, spec_sheet_no, cic_sheet_no, share_cardid, item_no_Fresh" +
|
||||
") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
|
||||
String sql2 = "INSERT INTO t_rm_payflow (" +
|
||||
"flow_id, flow_no, sale_amount, branch_no, pay_way, sell_way, " +
|
||||
"card_no, vip_no, coin_no, coin_rate, pay_amount, oper_date, " +
|
||||
"oper_id, counter_no, sale_man, memo,remote_flag, " +
|
||||
"exchange_flag, shift_no, com_flag, uptime, flowno_rand, " +
|
||||
"ciceroni_no, ciceroni_id, flowno_type, trans_type, up_batchno, " +
|
||||
"remark, cash_no" +
|
||||
") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
|
||||
try {
|
||||
PreparedStatement ps = conn.prepareStatement(sql);//销售流水
|
||||
PreparedStatement ps2 = conn.prepareStatement(sql2);//资金流水
|
||||
int batchSize = 10; // 每批处理10条
|
||||
int count = 0;
|
||||
for (int i=0;i<rmSaleflowList.size();i++) {
|
||||
//rmSaleflow start-------------
|
||||
RmSaleflow rmSaleflow=rmSaleflowList.get(i);
|
||||
ps.setInt(1,rmSaleflow.getFlowId());
|
||||
ps.setString(2, rmSaleflow.getFlowNo());
|
||||
ps.setString(3, rmSaleflow.getBranchNo());
|
||||
ps.setString(4, rmSaleflow.getItemNo());
|
||||
ps.setBigDecimal(5, rmSaleflow.getSourcePrice());
|
||||
ps.setBigDecimal(6, rmSaleflow.getSalePrice());
|
||||
|
||||
BigDecimal saleQnty=rmSaleflow.getSaleQnty();
|
||||
if(saleQnty.compareTo(BigDecimal.ZERO)<0){
|
||||
saleQnty=saleQnty.multiply(new BigDecimal("-1"));
|
||||
}
|
||||
ps.setBigDecimal(7,saleQnty);
|
||||
|
||||
ps.setBigDecimal(8, rmSaleflow.getSaleMoney());
|
||||
ps.setString(9, rmSaleflow.getSellWay());
|
||||
ps.setString(10, rmSaleflow.getOperId());
|
||||
ps.setString(11, rmSaleflow.getSaleMan());
|
||||
ps.setString(12, rmSaleflow.getCounterNo());
|
||||
|
||||
ps.setTimestamp(13, rmSaleflow.getOperDate());//OperDate
|
||||
ps.setString(14, rmSaleflow.getRemoteFlag());
|
||||
ps.setString(15, "");//ShiftNo
|
||||
ps.setString(16, rmSaleflow.getComFlag());
|
||||
ps.setString(17, "");//SpecFlag
|
||||
ps.setBigDecimal(18, rmSaleflow.getPrefAmt());
|
||||
|
||||
ps.setBigDecimal(19, rmSaleflow.getInPrice());
|
||||
ps.setBigDecimal(20, rmSaleflow.getNStan());
|
||||
ps.setString(21, rmSaleflow.getChrStan());
|
||||
ps.setString(22, rmSaleflow.getPosid());
|
||||
ps.setTimestamp(23, null);//Uptime
|
||||
ps.setString(24, rmSaleflow.getFlownoRand());
|
||||
ps.setBigDecimal(25, rmSaleflow.getRetQnty());
|
||||
|
||||
ps.setString(26, rmSaleflow.getFlownoType());
|
||||
ps.setString(27, rmSaleflow.getSpecSheetNo());
|
||||
ps.setString(28, "");//CicSheetNo
|
||||
ps.setString(29, rmSaleflow.getShareCardid());
|
||||
ps.setString(30, rmSaleflow.getItemNoFresh());
|
||||
|
||||
ps.addBatch(); // 添加至批处理
|
||||
//rmSaleflow end-------------
|
||||
|
||||
//rmPayflow start-------------
|
||||
TRmPayflow rmPayflow=payflowList.get(i);
|
||||
|
||||
//rmPayflow end-------------
|
||||
ps2.setInt(1,rmPayflow.getFlowId());
|
||||
ps2.setString(2, rmPayflow.getFlowNo());
|
||||
ps2.setBigDecimal(3, rmPayflow.getSaleAmount());
|
||||
ps2.setString(4, rmPayflow.getBranchNo());
|
||||
ps2.setString(5, rmPayflow.getPayWay());
|
||||
ps2.setString(6, rmPayflow.getSellWay());
|
||||
|
||||
ps2.setString(7, rmPayflow.getCardNo());
|
||||
ps2.setString(8, rmPayflow.getVipNo());
|
||||
ps2.setString(9, rmPayflow.getCoinNo());
|
||||
ps2.setBigDecimal(10, rmPayflow.getCoinRate());
|
||||
ps2.setBigDecimal(11, rmPayflow.getPayAmount());
|
||||
ps2.setTimestamp(12, rmPayflow.getOperDate());
|
||||
|
||||
ps2.setString(13, rmPayflow.getOperId());//OperDate
|
||||
ps2.setString(14, rmPayflow.getCounterNo());
|
||||
ps2.setString(15, rmPayflow.getSaleMan());
|
||||
ps2.setString(16, rmPayflow.getMemo());
|
||||
// ps2.setString(17, rmPayflow.getVoucherNo());
|
||||
ps2.setString(17, rmPayflow.getRemoteFlag());
|
||||
|
||||
ps2.setString(18, rmPayflow.getExchangeFlag());
|
||||
ps2.setString(19, rmPayflow.getShiftNo());
|
||||
ps2.setString(20, rmPayflow.getComFlag());
|
||||
//ps2.setString(22, rmPayflow.getPosid());
|
||||
ps2.setTimestamp(21, null);//Uptime
|
||||
ps2.setString(22, rmPayflow.getFlownoRand());
|
||||
|
||||
ps2.setString(23, rmPayflow.getCiceroniNo());
|
||||
ps2.setString(24, rmPayflow.getCiceroniId());
|
||||
ps2.setString(25, rmPayflow.getFlownoType());
|
||||
ps2.setString(26, rmPayflow.getTransType());
|
||||
ps2.setString(27, rmPayflow.getUpBatchno());
|
||||
|
||||
|
||||
// ps2.setString(30, rmPayflow.getUpVipacc());
|
||||
ps2.setString(28, rmPayflow.getRemark());
|
||||
ps2.setString(29, rmPayflow.getCashNo());
|
||||
// ps2.setString(33, rmPayflow.getCheckData());
|
||||
|
||||
ps2.addBatch(); // 添加至批处理
|
||||
count++;
|
||||
if (count % batchSize == 0) {
|
||||
ps.executeBatch();
|
||||
ps2.executeBatch();
|
||||
|
||||
ps.clearBatch();
|
||||
ps2.clearBatch();
|
||||
log.info("已提交批次: {}", count);
|
||||
}
|
||||
}
|
||||
// 执行剩余未满 batchSize 的批次
|
||||
int[] remainingCounts = ps.executeBatch();
|
||||
int[] remainingCounts2 = ps2.executeBatch();
|
||||
log.info("销售流水记录剩余批次更新数: {}", Arrays.toString(remainingCounts));
|
||||
log.info("支付流水记录剩余批次更新数: {}", Arrays.toString(remainingCounts2));
|
||||
//conn.commit(); // 最终提交事务
|
||||
log.info("销售-支付-流水记录批量更新完成,总记录数: {}" , count);
|
||||
//baseUpdateImBrancStock(dataBaseInfo);
|
||||
} catch (Exception e) {
|
||||
// conn.rollback(); // 出错时回滚整个事务
|
||||
log.info("销售支付流水记录业务失败:: {}", e.getMessage());
|
||||
throw new RuntimeException("销售支付流水记录业务失败:: {}"+e.getMessage());
|
||||
}
|
||||
// } catch (SQLException e) {
|
||||
// log.info("sql失败:: {}", e.getMessage());
|
||||
// throw new RuntimeException("sql失败:: {}"+e.getMessage());
|
||||
// }
|
||||
}
|
||||
|
||||
/**
|
||||
*获取促销活动价格 时段特价单
|
||||
* @param dataBaseInfo
|
||||
@ -991,7 +567,7 @@ public class SxDataDao extends BaseDao{
|
||||
activeDto.setActivityTypeId(3);
|
||||
activeDto.setActiveMaxDesList(activeMaxDesList);
|
||||
}
|
||||
activeDto.setFlowNo(rs.getString("other3"));
|
||||
activeDto.setFlowNo(rs.getString("flow_no"));
|
||||
activeDto.setActivityReleasetime(rs.getDate("oper_date"));
|
||||
activeDto.setActivityStarttime(rs.getDate("start_date"));
|
||||
activeDto.setActivityEndtime(rs.getDate("end_date"));
|
||||
@ -1025,17 +601,6 @@ public class SxDataDao extends BaseDao{
|
||||
where);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param dataBaseInfo
|
||||
* @return
|
||||
*/
|
||||
public Integer getNewActiveCount(DataBaseInfo dataBaseInfo){
|
||||
String where=dataBaseInfo.getWhere()+" and rule_no in('DD','PS','PM') and range_flag='I'";
|
||||
return getBaseTotal(dataBaseInfo.getIp(),dataBaseInfo.getUserName(),dataBaseInfo.getPassword(),dataBaseInfo.getDbPort(),dataBaseInfo.getDataBaseName(),
|
||||
T_PUB_PLAN_MASTER+" b",where);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param dataBaseInfo
|
||||
@ -1092,10 +657,9 @@ public class SxDataDao extends BaseDao{
|
||||
activeShopInfo.setActivityName("满"+total1+"减"+max1+",满"+total2+"减"+max2);
|
||||
activeShopInfo.setActivityTypeId(3);
|
||||
}
|
||||
activeShopInfo.setActivityItemMinQuantity(rs.getBigDecimal("sale_qty"));
|
||||
activeShopInfo.setActivityStarttime(rs.getDate("start_date"));
|
||||
activeShopInfo.setActivityEndtime(rs.getDate("end_date"));
|
||||
activeShopInfo.setFlowNo(rs.getString("other3"));
|
||||
activeShopInfo.setFlowNo(rs.getString("flow_no"));
|
||||
if(DateUtil.compare(activeShopInfo.getActivityEndtime(),DateUtil.date())>0){
|
||||
activeShopInfo.setActivityState(1);//正常进行中
|
||||
}else {
|
||||
@ -1147,191 +711,4 @@ public class SxDataDao extends BaseDao{
|
||||
return clsBrandDtos;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*获取促销活动价格 时段特价单
|
||||
* @param dataBaseInfo
|
||||
* DD-直接折扣 t_pub_plan_sendext t_pub_plan_detail_b
|
||||
* PS-直接特价 t_pub_plan_detail_b
|
||||
* PM-im促销 t_pub_plan_detail_b
|
||||
* range_flag='I' 代表按商品维度促销
|
||||
* @return
|
||||
*/
|
||||
public List<ActiveDto> getNewActiveList(DataBaseInfo dataBaseInfo,int pageNo,int pageSize){
|
||||
String where=dataBaseInfo.getWhere()+" and rule_no in('DD','PS','PM') and range_flag='I'";
|
||||
ResultDto resultDto=baseFindListPage(dataBaseInfo.getIp()
|
||||
,dataBaseInfo.getUserName()
|
||||
,dataBaseInfo.getPassword()
|
||||
,dataBaseInfo.getDbPort()
|
||||
,dataBaseInfo.getDataBaseName()
|
||||
,T_PUB_PLAN_MASTER +" b"
|
||||
,PLAN_NO
|
||||
,pageNo
|
||||
,pageSize
|
||||
,where);
|
||||
ResultSet rs= resultDto.getResultSet();
|
||||
List<ActiveDto> activeDtos=new ArrayList<>();
|
||||
try {
|
||||
while (rs.next()) {
|
||||
ActiveDto activeDto=new ActiveDto();
|
||||
String specialType=rs.getString("rule_no").trim();
|
||||
String activityName=rs.getString("plan_name").trim();
|
||||
if(specialType.equals("DD")){//折扣
|
||||
activeDto.setActivityTypeId(2);
|
||||
}
|
||||
if(specialType.equals("PS")||specialType.equals("PM")){//特价(秒杀)
|
||||
activeDto.setActivityTypeId(1);
|
||||
}
|
||||
if(specialType.equals("E")){//满减 todo
|
||||
|
||||
}
|
||||
activeDto.setActivityName(activityName);
|
||||
activeDto.setActivity_remark(rs.getString("plan_memo").trim());
|
||||
activeDto.setFlowNo(rs.getString("plan_no"));
|
||||
activeDto.setActivityReleasetime(rs.getDate("oper_date"));
|
||||
activeDto.setActivityStarttime(rs.getDate("begin_date"));
|
||||
activeDto.setActivityEndtime(rs.getDate("end_date"));
|
||||
if(DateUtil.compare(activeDto.getActivityEndtime(),DateUtil.date())>0){
|
||||
activeDto.setActivityState(1);//正常进行中
|
||||
}else {
|
||||
activeDto.setActivityState(2);//结束
|
||||
}
|
||||
activeDtos.add(activeDto);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
} finally {
|
||||
try {
|
||||
resultDto.getConnection().close();
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
return activeDtos;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取折扣商品
|
||||
* @param dataBaseInfo
|
||||
* @return
|
||||
*/
|
||||
public List<ActiveShopInfo> getSpecShops(DataBaseInfo dataBaseInfo,int pageNo,int pageSize){
|
||||
String where=dataBaseInfo.getWhere()+" and b.range_flag='I' and rule_no in('DD','PS','PM')";
|
||||
ResultDto resultDto=baseFindListJoinPage(dataBaseInfo.getIp(),dataBaseInfo.getUserName(),dataBaseInfo.getPassword(),dataBaseInfo.getDbPort(),dataBaseInfo.getDataBaseName(),
|
||||
T_PUB_PLAN_DETAIL_B,T_PUB_PLAN_MASTER,"plan_no","plan_no","flow_id","t.rule_no,t.plan_name,t.begin_date,t.end_date",pageNo,pageSize,where);
|
||||
ResultSet rs= resultDto.getResultSet();
|
||||
List<ActiveShopInfo> activeShopInfos=new ArrayList<>();
|
||||
try {
|
||||
while (rs.next()) {
|
||||
ActiveShopInfo activeShopInfo=new ActiveShopInfo();
|
||||
activeShopInfo.setItemNo(rs.getString("item_no").trim());
|
||||
String specialType=rs.getString("rule_no").trim();
|
||||
String activityName=rs.getString("plan_name").trim();
|
||||
if(specialType.equals("DD")){//折扣 折扣和满减分类比较多,目前只同步商品级别的
|
||||
BigDecimal discount=rs.getBigDecimal("value");
|
||||
//String discountStr=BigDecimalFormatter.formatWithoutTrailingZeros(discount.multiply(new BigDecimal(10)));
|
||||
// activeShopInfo.setActivityName(activityName);
|
||||
activeShopInfo.setDiscount(discount);
|
||||
activeShopInfo.setActivityTypeId(2);
|
||||
}
|
||||
if(specialType.equals("PS")||specialType.equals("PM")){//特价(秒杀)
|
||||
//activeShopInfo.setActivityName(activityName);
|
||||
activeShopInfo.setOldPrice(rs.getBigDecimal("num2"));
|
||||
activeShopInfo.setSpecPrice(rs.getBigDecimal("value"));
|
||||
activeShopInfo.setActivityTypeId(1);
|
||||
}
|
||||
// if(specialType.equals("FR")){//满减 todo 没有同步
|
||||
// String total1=BigDecimalFormatter.formatWithoutTrailingZeros(rs.getBigDecimal("old_price"));
|
||||
// String max1=BigDecimalFormatter.formatWithoutTrailingZeros(rs.getBigDecimal("spe_price"));
|
||||
// String max2=BigDecimalFormatter.formatWithoutTrailingZeros(rs.getBigDecimal("spe_price").add(rs.getBigDecimal("new_price1")));
|
||||
// String total2=BigDecimalFormatter.formatWithoutTrailingZeros(rs.getBigDecimal("old_price").add(rs.getBigDecimal("old_price1")));
|
||||
// activeShopInfo.setActivityName("满"+total1+"减"+max1+",满"+total2+"减"+max2);
|
||||
// activeShopInfo.setActivityTypeId(3);
|
||||
// }
|
||||
activeShopInfo.setActivityName(activityName);
|
||||
activeShopInfo.setActivityItemMinQuantity(rs.getBigDecimal("limit_qty"));
|
||||
activeShopInfo.setActivityStarttime(rs.getDate("begin_date"));
|
||||
activeShopInfo.setActivityEndtime(rs.getDate("end_date"));
|
||||
activeShopInfo.setFlowNo(rs.getString("plan_no"));
|
||||
activeShopInfo.setItemNo(rs.getString("item_no").trim());
|
||||
if(DateUtil.compare(activeShopInfo.getActivityEndtime(),DateUtil.date())>0){
|
||||
activeShopInfo.setActivityState(1);//正常进行中
|
||||
}else {
|
||||
activeShopInfo.setActivityState(2);//结束
|
||||
}
|
||||
activeShopInfos.add(activeShopInfo);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
} finally {
|
||||
try {
|
||||
resultDto.getConnection().close();
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
return activeShopInfos;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param dataBaseInfo
|
||||
* @return
|
||||
*/
|
||||
public Integer getTotalSpecShop(DataBaseInfo dataBaseInfo){
|
||||
String where=dataBaseInfo.getWhere()+" and d.range_flag='I' and rule_no in('DD','PS','PM')";
|
||||
return getTotalSpecShop(dataBaseInfo.getIp(),dataBaseInfo.getUserName(),dataBaseInfo.getPassword(),dataBaseInfo.getDbPort(),
|
||||
dataBaseInfo.getDataBaseName(),where);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取本地仓库
|
||||
* @return
|
||||
*/
|
||||
public String getLocalBranch(DataBaseInfo dataBaseInfo){
|
||||
ResultDto resultDto= this.baseFindList(dataBaseInfo.getIp(),dataBaseInfo.getUserName(),dataBaseInfo.getPassword(),
|
||||
dataBaseInfo.getDbPort(),dataBaseInfo.getDataBaseName(),T_BD_BRANCH_INFO,"where property =2 ");
|
||||
ResultSet rs= resultDto.getResultSet();
|
||||
String branch_no = "";
|
||||
try {
|
||||
while (rs.next()) {
|
||||
branch_no=rs.getString("branch_no");//
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
} finally {
|
||||
try {
|
||||
resultDto.getConnection().close();
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
return branch_no;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取小发账号
|
||||
* @return
|
||||
*/
|
||||
public String getTRmCashier(DataBaseInfo dataBaseInfo,String accountNo){
|
||||
ResultDto resultDto= this.baseFindList(dataBaseInfo.getIp(),dataBaseInfo.getUserName(),dataBaseInfo.getPassword(),
|
||||
dataBaseInfo.getDbPort(),dataBaseInfo.getDataBaseName(),T_RM_CASHIER,"where cashier_id='"+accountNo+"'");
|
||||
ResultSet rs= resultDto.getResultSet();
|
||||
String cashier_id = "";
|
||||
try {
|
||||
while (rs.next()) {
|
||||
cashier_id=rs.getString("cashier_id");//
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
} finally {
|
||||
try {
|
||||
resultDto.getConnection().close();
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
return cashier_id;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user