java-mall/client/src/main/java/com/small/client/dao/SxDataDao.java
2025-08-02 17:21:02 +08:00

867 lines
39 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package com.small.client.dao;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DateUtil;
import com.small.client.Utils.BigDecimalFormatter;
import com.small.client.dto.*;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.math.NumberUtils;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.sql.*;
import java.util.*;
/**
* 考虑到每个思迅软件都是自己的数据,所以采用动态获取的方式获取数据
* 数据库为MS SQL
* todo 如果考虑到数据量需要分页多线程
*/
@Service
@Slf4j
public class SxDataDao extends BaseDao{
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_RM_VIP_INFO="t_rm_vip_info";//会员表
private final static String ITEM_CLSNO="item_clsno";//商品分类排序字段
private final static String ITEM_NO="item_no";//商品排序字段
private final static String CARD_ID="card_id";//会员表排序字段
private final static String T_BD_BASE_CODE="t_bd_base_code";//品牌表
private final static String T_BD_BASECODE_TYPE="t_bd_basecode_type";//品牌表
private final static String TYPE_NO="type_no";//品牌排序字段
//private final static String T_IM_BRANCH_STOCK="t_im_branch_stock";//库存表
private final static String T_IM_BRANCH_STOCK="(" +
"select * from( " +
" select ROW_NUMBER() OVER( " +
" partition BY tib.item_no order by tib.oper_date desc) as rn, " +
" tib.* " +
" from t_im_branch_stock tib)tib where tib.rn=1) ";
private final static String T_RM_SPEC_PRICE="t_rm_spec_price";//活动表
public final static Integer PAGESIZE=500;
public final static Integer PAGESIZE_MEMBER=300;
public final static String DEFALTWHERE="where 1=1";
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
*/
public List<SxSyncCategory> findTBdItemClsList(DataBaseInfo dataBaseInfo){
ResultDto resultDto=baseFindList(dataBaseInfo.getIp(),dataBaseInfo.getUserName(),dataBaseInfo.getPassword(),dataBaseInfo.getDbPort(),dataBaseInfo.getDataBaseName(),T_BD_ITEM_CLS,DEFALTWHERE);
ResultSet rs= resultDto.getResultSet();
List<SxSyncCategory> sxSyncCategories=new ArrayList<>();
SxSyncCategory sxSyncCategory=null;
try {
while (rs.next()) {
sxSyncCategory=new SxSyncCategory();
sxSyncCategory.setItem_clsname(rs.getString("item_clsname").trim());//分类名称
if(null!=rs.getString("cls_parent")){
sxSyncCategory.setCls_parent(rs.getString("cls_parent").trim());//父级编码
}
sxSyncCategory.setItem_clsno(rs.getString("item_clsno").trim());//分类编码
// System.out.printf(rs.getString("item_clsno"));//分类编码
// System.out.printf(rs.getString("item_clsname")+"\t");//分类名称
// System.out.print(rs.getString("cls_parent")+"\t");//父级编码
// System.out.print(rs.getString("item_flag")+"\t" + "\n");//显示标识
sxSyncCategories.add(sxSyncCategory);
}
} catch (SQLException e) {
throw new RuntimeException(e);
} finally {
try {
resultDto.getConnection().close();
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
return sxSyncCategories;
}
/**
* 分页查找商品分类数据
* @param dataBaseInfo
* @param pageNo
* @param pageSize
*/
public List<SxSyncCategory> findTBdItemClsListPage(DataBaseInfo dataBaseInfo, int pageNo, int pageSize){
ResultDto resultDto=baseFindListPage(dataBaseInfo.getIp(),dataBaseInfo.getUserName(),dataBaseInfo.getPassword(),dataBaseInfo.getDbPort(),dataBaseInfo.getDataBaseName(),T_BD_ITEM_CLS,ITEM_CLSNO,pageNo,pageSize,DEFALTWHERE);
ResultSet rs= resultDto.getResultSet();
List<SxSyncCategory> sxSyncCategories=new ArrayList<>();
SxSyncCategory sxSyncCategory=null;
try {
while (rs.next()) {
sxSyncCategory=new SxSyncCategory();
sxSyncCategory.setItem_clsname(rs.getString("item_clsname"));//分类名称
sxSyncCategory.setCls_parent(rs.getString("cls_parent"));//父级编码
sxSyncCategory.setItem_clsno(rs.getString("item_clsno"));//分类编码
// System.out.printf(rs.getString("item_clsno"));//分类编码
// log.info(rs.getString("item_clsname")+"\t");//分类名称
//log.info(rs.getString("cls_parent")+"\t");//父级编码
//log.info(rs.getString("item_flag")+"\t" + "\n");//显示标识
sxSyncCategories.add(sxSyncCategory);
}
} catch (SQLException e) {
throw new RuntimeException(e);
} finally {
try {
resultDto.getConnection().close();
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
return sxSyncCategories;
}
/**
* 获取商品分类TBdItemCls表的数量
* @param dataBaseInfo
* @return
*/
public Integer getTBdItemClsTotal(DataBaseInfo dataBaseInfo){
return getBaseTotal(dataBaseInfo.getIp(),dataBaseInfo.getUserName(),dataBaseInfo.getPassword(),dataBaseInfo.getDbPort(),dataBaseInfo.getDataBaseName(),T_BD_ITEM_CLS,DEFALTWHERE);
}
/**
* 获取商品表t_bd_item_info表的数量
* @param dataBaseInfo
* @return
*/
public int getTBditemInfoTotal(DataBaseInfo dataBaseInfo){
// String where =DEFALTWHERE;
// if(syncGoodsSearchModel!=null){
// if(dataBaseInfo.getWhere()!=null){
// where+= dataBaseInfo.getWhere();
// }
// }
return getBaseTotal(dataBaseInfo.getIp(),dataBaseInfo.getUserName(),dataBaseInfo.getPassword(),dataBaseInfo.getDbPort(),dataBaseInfo.getDataBaseName(),T_BD_ITEM_INFO,dataBaseInfo.getWhere());
}
/**
* 获取商品表t_bd_item_info表的数量
* @param dataBaseInfo
* @return
*/
public int getTBditemInfoJoninTotal(DataBaseInfo dataBaseInfo){
return getBaseGoodsJoinTotal(dataBaseInfo.getIp(),dataBaseInfo.getUserName(),dataBaseInfo.getPassword(),dataBaseInfo.getDbPort(),dataBaseInfo.getDataBaseName()
,dataBaseInfo.getWhere()==null?DEFALTWHERE:dataBaseInfo.getWhere());
}
/**
* 获取会员表t_rm_vip_info表的数量
* @param dataBaseInfo
* @return
*/
public int getTrmVipInfoTotal(DataBaseInfo dataBaseInfo){
return getVipBaseTotal(dataBaseInfo.getIp(),dataBaseInfo.getUserName(),dataBaseInfo.getPassword(),dataBaseInfo.getDbPort(),dataBaseInfo.getDataBaseName(),T_RM_VIP_INFO,dataBaseInfo.getWhere());
}
/**
* 分页查找商品数据
* 表T_BD_ITEM_INFO
* @param dataBaseInfo
* @param pageNo
* @param pageSize
*/
public List<SxSyncGoods> findBditemInfoListPage(DataBaseInfo dataBaseInfo,int pageNo,int pageSize){
ResultDto resultDto=baseFindGoodsListJoinPage(dataBaseInfo.getIp(),dataBaseInfo.getUserName(),dataBaseInfo.getPassword(),dataBaseInfo.getDbPort(),dataBaseInfo.getDataBaseName()
,pageNo,pageSize,dataBaseInfo.getWhere()==null?DEFALTWHERE:dataBaseInfo.getWhere());
ResultSet rs= resultDto.getResultSet();
List<SxSyncGoods> sxSyncGoodses=new ArrayList<>();
SxSyncGoods sxSyncGoods=null;
try {
while (rs.next()) {
sxSyncGoods=new SxSyncGoods();
BigDecimal price=new BigDecimal(rs.getString("price"));
BigDecimal salePrice=new BigDecimal(rs.getString("sale_price"));
if(salePrice.compareTo(new BigDecimal("0"))>0){
try{
BigDecimal gross= salePrice.subtract(price).divide(salePrice,4, RoundingMode.HALF_UP);
sxSyncGoods.setGross_margin(gross);//毛利率
}catch (RuntimeException e){
log.info("运行错误:{}",e.getMessage());
log.info(String.valueOf(rs.getString("sale_price")));
}
}else {
sxSyncGoods.setGross_margin(new BigDecimal("0"));//毛利率
}
sxSyncGoods.setItem_no(rs.getString("item_no"));//货号
sxSyncGoods.setItem_subname(rs.getString("item_name"));//商品名称
sxSyncGoods.setItem_subno(rs.getString("item_subno"));//商品条码
sxSyncGoods.setBig_cls_name("9999");//商品大类 todo 如何关联
sxSyncGoods.setSmall_cls_name(rs.getString("item_clsno").trim());//商品小类 todo 如何关联
sxSyncGoods.setItem_size(rs.getString("item_size"));//规格
sxSyncGoods.setUnit_no(rs.getString("unit_no"));//单位
if(null==rs.getBigDecimal("stock_qty")){
sxSyncGoods.setStock(BigDecimal.ZERO);
}else {
sxSyncGoods.setStock(rs.getBigDecimal("stock_qty"));//库存数量
}
sxSyncGoods.setPrice(rs.getBigDecimal("price"));//进货价
sxSyncGoods.setSale_price(rs.getBigDecimal("sale_price"));//零售价
sxSyncGoods.setVip_price(rs.getBigDecimal("vip_price"));//会员价
sxSyncGoods.setVip_acc_flag(rs.getBigDecimal("vip_acc_flag"));//允许积分
sxSyncGoods.setVip_acc_num(rs.getBigDecimal("vip_acc_num"));//积分值
//sxSyncGoods.setSale_flag(rs.getInt("main_Sale_flag"));//商品状态 todo 是main_Sale_flag?
sxSyncGoods.setItem_rem(rs.getString("item_rem"));//助记码
sxSyncGoods.setBuild_date(rs.getString("build_date"));//生产日期 todo
sxSyncGoods.setValid_days(getStopDate(rs));//保质期 todo stop_date-build_date
sxSyncGoods.setItem_brand_name(rs.getString("item_brandname"));
sxSyncGoods.setItemBrand(rs.getString("item_brand").trim());
sxSyncGoods.setItem_clsno(rs.getString("item_clsno").trim());
sxSyncGoods.setItem_size(rs.getString("item_size"));
sxSyncGoodses.add(sxSyncGoods);
}
} catch (SQLException e) {
throw new RuntimeException(e);
} finally {
try {
resultDto.getConnection().close();
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
return sxSyncGoodses;
}
private static String getStopDate(ResultSet rs) throws SQLException {
return rs.getString("stop_date");
}
/**
* 分页查找会员数据
* RM_VIP_INFO
* @param dataBaseInfo
* @param pageNo
* @param pageSize
*/
public List<SxSyncVip> findRmVipInfoListPage(DataBaseInfo dataBaseInfo, int pageNo, int pageSize){
ResultDto resultDto=baseVipFindListPage(dataBaseInfo.getIp(),dataBaseInfo.getUserName(),dataBaseInfo.getPassword(),dataBaseInfo.getDbPort(),dataBaseInfo.getDataBaseName(),T_RM_VIP_INFO,CARD_ID,pageNo,pageSize,dataBaseInfo.getWhere());
ResultSet rs= resultDto.getResultSet();
List<SxSyncVip> sxSyncVips=new ArrayList<>();
SxSyncVip sxSyncVip=null;
try {
while (rs.next()) {
sxSyncVip = new SxSyncVip();
int cardStatus=rs.getInt("card_status");
if(cardStatus!=1){
sxSyncVip.setVip_name(rs.getString("vip_name"));//会员名称
sxSyncVip.setVip_sex(rs.getString("vip_sex").trim());//性别
sxSyncVip.setMobile(rs.getString("mobile"));//手机号
sxSyncVip.setBirthday(rs.getString("birthday"));//会员生日
sxSyncVip.setCard_type(rs.getString("card_type")==null?"v1":rs.getString("card_type"));//会员生日
sxSyncVip.setCard_no(rs.getString("card_id"));//会员卡号
BigDecimal now_acc_num=null;
try {
now_acc_num=rs.getBigDecimal("now_acc_num");
}catch (Exception e){
//log.info("now_acc_num错误now_acc_num{}",e.getMessage());
now_acc_num = rs.getBigDecimal("acc_num");
}
sxSyncVip.setNow_acc_num(now_acc_num);//会员积分
String residual_amtStr=rs.getString("residual_amt");
if(NumberUtils.isCreatable(residual_amtStr)){
BigDecimal residual_amt=new BigDecimal(residual_amtStr);
sxSyncVip.setResidual_amt(residual_amt);//储值余额
}else {
sxSyncVip.setResidual_amtStr(residual_amtStr);
}
sxSyncVip.setVip_date(rs.getTimestamp("vip_start_date"));//建档日期
sxSyncVip.setUser_nickname(rs.getString("vip_name"));
sxSyncVip.setUser_realname(rs.getString("vip_name"));
}
sxSyncVips.add(sxSyncVip);
}
}catch (SQLException e){
throw new RuntimeException(e);
}
return sxSyncVips;
}
/**
* 获取品牌数据
* @param dataBaseInfo
*/
public List<BrandModel> getBdBrandList(DataBaseInfo dataBaseInfo) {
String where="where t.type_name='品牌'";
ResultDto resultDto=baseFindListJoin(dataBaseInfo.getIp()
,dataBaseInfo.getUserName()
,dataBaseInfo.getPassword()
,dataBaseInfo.getDbPort()
,dataBaseInfo.getDataBaseName()
,T_BD_BASE_CODE
,"t_bd_basecode_type"
,"type_no"
,"type_no"
,"t.type_name"
,where);
ResultSet rs= resultDto.getResultSet();
List<BrandModel> brandModels=new ArrayList<>();
try {
while (rs.next()) {
BrandModel brandModel=new BrandModel();
brandModel.setBrand_name(rs.getString("code_name").trim());
brandModel.setBrand_desc(rs.getString("code_name").trim());
brandModel.setCodeId(rs.getString("code_id").trim());
brandModel.setBrand_image("");
//brandModel.setCategory("0");
brandModel.setBrand_recommend("0");//是否推荐
brandModels.add(brandModel);
// log.info(rs.getString("type_no")+"--"+rs.getString("code_name"));//分类编码-分类名称
}
} catch (SQLException e) {
throw new RuntimeException(e);
} finally {
try {
resultDto.getConnection().close();
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
return brandModels;
}
/**
* 获取库存数据
* @return
*/
public List<ImBranchStock> getImBranchStockList(DataBaseInfo dataBaseInfo,String where){
ResultDto resultDto=baseFindList(dataBaseInfo.getIp()
,dataBaseInfo.getUserName()
,dataBaseInfo.getPassword()
,dataBaseInfo.getDbPort()
,dataBaseInfo.getDataBaseName()
,T_IM_BRANCH_STOCK
,where);
ResultSet rs= resultDto.getResultSet();
List<ImBranchStock> branchStocks=new ArrayList<>();
try {
while (rs.next()) {
ImBranchStock brandModel=new ImBranchStock();
brandModel.setBranchNo(rs.getString("branch_no"));
brandModel.setStockQty(rs.getBigDecimal("stock_qty"));
brandModel.setItemNo(rs.getString("item_no"));
brandModel.setPerDate(rs.getString("oper_date"));
branchStocks.add(brandModel);
}
} catch (SQLException e) {
throw new RuntimeException(e);
} finally {
try {
resultDto.getConnection().close();
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
return branchStocks;
}
/**
*获取促销活动价格 时段特价单
* @param dataBaseInfo
* @return
*/
public List<SpecPriceDto> getSpecPriceList(DataBaseInfo dataBaseInfo){
ResultDto resultDto=baseFindList(dataBaseInfo.getIp()
,dataBaseInfo.getUserName()
,dataBaseInfo.getPassword()
,dataBaseInfo.getDbPort()
,dataBaseInfo.getDataBaseName()
,"T_RM_SPEC_PRICE"
,"where special_type ='0'");
ResultSet rs= resultDto.getResultSet();
List<SpecPriceDto> specPriceDtos=new ArrayList<>();
try {
while (rs.next()) {
SpecPriceDto specPriceDto=new SpecPriceDto();
specPriceDto.setItemNo(rs.getString("item_no"));//
specPriceDto.setOldPrice(rs.getBigDecimal("old_price"));//原价
specPriceDto.setSpecPrice(rs.getBigDecimal("spe_price"));//特价
specPriceDto.setSpecPrice(rs.getBigDecimal("sale_qty"));//限购
specPriceDto.setDiscountType("0");
specPriceDtos.add(specPriceDto);
}
} catch (SQLException e) {
throw new RuntimeException(e);
} finally {
try {
resultDto.getConnection().close();
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
return specPriceDtos;
}
/**
* 折扣商品
* @param dataBaseInfo
* @return
*/
public List<SpecPriceDto> getDiscountPriceList(DataBaseInfo dataBaseInfo){
ResultDto resultDto=baseFindList(dataBaseInfo.getIp()
,dataBaseInfo.getUserName()
,dataBaseInfo.getPassword()
,dataBaseInfo.getDbPort()
,dataBaseInfo.getDataBaseName()
,T_RM_SPEC_PRICE
,"where special_type in('6','G')");
ResultSet rs= resultDto.getResultSet();
List<SpecPriceDto> specPriceDtos=new ArrayList<>();
try {
while (rs.next()) {
SpecPriceDto specPriceDto=new SpecPriceDto();
specPriceDto.setItemNo(rs.getString("item_no"));//
specPriceDto.setDiscount(rs.getBigDecimal("discount"));//原价
specPriceDto.setDiscountType("1");
specPriceDtos.add(specPriceDto);
}
} catch (SQLException e) {
throw new RuntimeException(e);
} finally {
try {
resultDto.getConnection().close();
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
return specPriceDtos;
}
/**
* 批量更新商品库存
* @param dataBaseInfo
* @param map
*/
public void updateStoreData(DataBaseInfo dataBaseInfo, Map map){
if(CollectionUtil.isEmpty(map)){
log.info("同步数据为空");
return;
}
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=?";
String sql = "WITH TopStock AS ( " +
" SELECT TOP(1) * " +
" FROM t_im_branch_stock " +
" WHERE item_no = ? " +
" ORDER BY oper_date DESC " +
") " +
" UPDATE TopStock " +
" SET stock_qty = stock_qty+(?),oper_date=?;";
Timestamp timestamp = new Timestamp(System.currentTimeMillis());
try (PreparedStatement ps = conn.prepareStatement(sql)) {
int batchSize = 1000; // 每批处理1000条
int count = 0;
Set<Map.Entry> sme=map.entrySet();
for (Map.Entry entry : sme) {
ps.setString(1, (String) entry.getKey());
ps.setDouble(2, (double) entry.getValue());
ps.setTimestamp(3, timestamp);
ps.addBatch(); // 添加至批处理
count++;
if (count % batchSize == 0) {
ps.executeBatch();
ps.clearBatch();
log.info("已提交批次: {}", count);
}
}
// 执行剩余未满 batchSize 的批次
int[] remainingCounts = ps.executeBatch();
log.info("剩余批次更新数: {}", Arrays.toString(remainingCounts));
conn.commit(); // 最终提交事务
log.info("批量更新完成,总记录数: {}" , count);
//baseUpdateImBrancStock(dataBaseInfo);
} catch (SQLException e) {
conn.rollback(); // 出错时回滚整个事务
e.printStackTrace();
}
} catch (SQLException e) {
e.printStackTrace();
}finally {
if(conn!=null){
try {
conn.close();
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
}
}
/**
*获取促销活动价格 时段特价单
* @param dataBaseInfo
* @return
*/
public List<ActiveDto> getActiveList(DataBaseInfo dataBaseInfo,int pageNo,int pageSize){
String where=dataBaseInfo.getWhere()+" and special_type in('6','G','0','E')";
ResultDto resultDto=baseFindSpecListPage(dataBaseInfo.getIp()
,dataBaseInfo.getUserName()
,dataBaseInfo.getPassword()
,dataBaseInfo.getDbPort()
,dataBaseInfo.getDataBaseName()
,pageNo
,pageSize
,where);
ResultSet rs= resultDto.getResultSet();
List<ActiveDto> activeDtos=new ArrayList<>();
try {
while (rs.next()) {
ActiveDto activeDto=new ActiveDto();
String specialType=rs.getString("special_type").trim();
if(specialType.equals("6")||specialType.equals("G")){//折扣
BigDecimal discount=rs.getBigDecimal("discount");
String discountStr=BigDecimalFormatter.formatWithoutTrailingZeros(rs.getBigDecimal("discount").multiply(new BigDecimal(10)));
activeDto.setActivityName(discountStr+"折商品");
activeDto.setActivityTypeId(2);
activeDto.setDiscount(discount);
}
if(specialType.equals("0")){//特价(秒杀)
activeDto.setActivityName("限时特价秒杀");
activeDto.setActivityTypeId(1);
}
if(specialType.equals("E")){//满减
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")));
activeDto.setActivityName(""+total1+""+max1+",满"+total2+""+max2);
List<ActiveMaxDes> activeMaxDesList=new ArrayList<>();
ActiveMaxDes activeMaxDes=new ActiveMaxDes();
activeMaxDes.setMaxNum(rs.getBigDecimal("spe_price"));
activeMaxDes.setTotal(rs.getBigDecimal("old_price"));
activeMaxDesList.add(activeMaxDes);
BigDecimal new_price1=rs.getBigDecimal("new_price1");
BigDecimal old_price1=rs.getBigDecimal("old_price1");
if(new_price1.compareTo(BigDecimal.ZERO)>0&&old_price1.compareTo(BigDecimal.ZERO)>0){
ActiveMaxDes activeMaxDes2=new ActiveMaxDes();
activeMaxDes2.setMaxNum(rs.getBigDecimal("spe_price").add(rs.getBigDecimal("new_price1")));
activeMaxDes2.setTotal(rs.getBigDecimal("old_price").add(rs.getBigDecimal("old_price1")));
activeMaxDesList.add(activeMaxDes2);
}
activeDto.setActivityTypeId(3);
activeDto.setActiveMaxDesList(activeMaxDesList);
}
activeDto.setFlowNo(rs.getString("other3"));
activeDto.setActivityReleasetime(rs.getDate("oper_date"));
activeDto.setActivityStarttime(rs.getDate("start_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 Integer getActiveCount(DataBaseInfo dataBaseInfo){
String where=dataBaseInfo.getWhere()+" and special_type in('6','G','0','E')";
return getBaseSpecTotal(dataBaseInfo.getIp(),dataBaseInfo.getUserName(),dataBaseInfo.getPassword(),dataBaseInfo.getDbPort(),dataBaseInfo.getDataBaseName(),
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,where);
}
/**
*
* @param dataBaseInfo
* @return
*/
public Integer getAllSpecCount(DataBaseInfo dataBaseInfo){
String where=dataBaseInfo.getWhere()+" and special_type in('6','G','0','E')";
return getBaseTotal(dataBaseInfo.getIp(),dataBaseInfo.getUserName(),dataBaseInfo.getPassword(),dataBaseInfo.getDbPort(),
dataBaseInfo.getDataBaseName(),T_RM_SPEC_PRICE,where);
}
/**
* 折扣商品
* @param dataBaseInfo
* @return
*/
public List<ActiveShopInfo> getAllSpecPriceList(DataBaseInfo dataBaseInfo,int pageNo,int pageSize){
String where=dataBaseInfo.getWhere()+" and special_type in('6','G','0','E')";
ResultDto resultDto=baseFindListPage(dataBaseInfo.getIp()
,dataBaseInfo.getUserName()
,dataBaseInfo.getPassword()
,dataBaseInfo.getDbPort()
,dataBaseInfo.getDataBaseName()
,T_RM_SPEC_PRICE
,ITEM_NO
,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("special_type").trim();
if(specialType.equals("6")||specialType.equals("G")){//折扣
BigDecimal discount=rs.getBigDecimal("discount");
String discountStr=BigDecimalFormatter.formatWithoutTrailingZeros(discount.multiply(new BigDecimal(10)));
activeShopInfo.setActivityName(discountStr+"折商品");
activeShopInfo.setActivityTypeId(2);
}
if(specialType.equals("0")){//特价(秒杀)
activeShopInfo.setActivityName("限时特价秒杀");
activeShopInfo.setOldPrice(rs.getBigDecimal("old_price"));
activeShopInfo.setSpecPrice(rs.getBigDecimal("spe_price"));
activeShopInfo.setActivityTypeId(1);
}
if(specialType.equals("E")){//满减
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.setActivityItemMinQuantity(rs.getBigDecimal("sale_qty"));
activeShopInfo.setActivityStarttime(rs.getDate("start_date"));
activeShopInfo.setActivityEndtime(rs.getDate("end_date"));
activeShopInfo.setFlowNo(rs.getString("other3"));
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 List<ClsBrandDto> getclsMapBrand(DataBaseInfo dataBaseInfo){
ResultDto resultDto=getclsMapBrand(dataBaseInfo.getIp()
,dataBaseInfo.getUserName()
,dataBaseInfo.getPassword()
,dataBaseInfo.getDbPort()
,dataBaseInfo.getDataBaseName());
ResultSet rs= resultDto.getResultSet();
List<ClsBrandDto> clsBrandDtos=new ArrayList<>();
try {
while (rs.next()) {
ClsBrandDto clsBrandDto=new ClsBrandDto();
clsBrandDto.setItemClsname(rs.getString("item_clsname").trim());
clsBrandDto.setCodeName(rs.getString("code_name").trim());
clsBrandDtos.add(clsBrandDto);
}
} catch (SQLException e) {
throw new RuntimeException(e);
} finally {
try {
resultDto.getConnection().close();
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
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
,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);
}
}