会员同步和活动同步调试问题修复

This commit is contained in:
liyj 2025-07-04 15:41:16 +08:00
parent 33414896c9
commit af2627bad5
9 changed files with 211 additions and 76 deletions

View File

@ -0,0 +1,21 @@
package com.small.client.Adapter;
import com.google.gson.*;
import java.lang.reflect.Type;
import java.math.BigDecimal;
public class BigDecimalTypeAdapter implements JsonSerializer<BigDecimal>, JsonDeserializer<BigDecimal> {
@Override
public JsonElement serialize(BigDecimal value, Type type, JsonSerializationContext context) {
if (value == null) {
return JsonNull.INSTANCE;
}
// 去除末尾的 0并避免科学计数法
return new JsonPrimitive(value.stripTrailingZeros().toPlainString());
}
@Override
public BigDecimal deserialize(JsonElement json, Type type, JsonDeserializationContext context) {
return json.isJsonNull() ? null : new BigDecimal(json.getAsString());
}
}

View File

@ -33,7 +33,7 @@ public class DynamicTaskScheduler {
this.sxDataService = sxDataService; this.sxDataService = sxDataService;
} }
//@PostConstruct @PostConstruct
public void initTasks() { public void initTasks() {
refreshTasks(); refreshTasks();
// 每5分钟检查一次数据库更新 // 每5分钟检查一次数据库更新

View File

@ -7,6 +7,7 @@ import com.small.client.dto.DataBaseInfo;
import com.small.client.service.SxDataService; import com.small.client.service.SxDataService;
import com.small.client.service.WebClientService; import com.small.client.service.WebClientService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
@ -61,7 +62,19 @@ public class WebController {
public void synvip(){ public void synvip(){
log.info("synvip"); log.info("synvip");
// sxDataService.getAppSign(); // sxDataService.getAppSign();
sxDataService.SyncVipList(new DataBaseInfo(),sxDataService.getCommentModel()); CommentModel commentModel= sxDataService.getCommentModel();
DataBaseInfo dataBaseInfo=sxDataService.getDataBaseInfo(commentModel);
if(dataBaseInfo==null){
log.error("syncGoods dataBaseInfo is null");
return;
}
if(StringUtils.isEmpty(commentModel.getSyncTime())){
commentModel =sxDataService.getCommentModel();
}
if(ObjectUtil.isNotEmpty(dataBaseInfo.getRefreshTime())){
commentModel.setSyncTime(DateUtil.formatDateTime(dataBaseInfo.getRefreshTime()));
}
sxDataService.SyncVipList(new DataBaseInfo(),commentModel);
} }
// @RequestMapping("/getAppSign") // @RequestMapping("/getAppSign")
@ -96,12 +109,38 @@ public class WebController {
@RequestMapping("/syncActives") @RequestMapping("/syncActives")
public void syncActives(){ public void syncActives(){
sxDataService.syncAtive(new DataBaseInfo(),sxDataService.getCommentModel()); CommentModel commentModel= sxDataService.getCommentModel();
DataBaseInfo dataBaseInfo=sxDataService.getDataBaseInfo(commentModel);
if(dataBaseInfo==null){
log.error("syncGoods dataBaseInfo is null");
return;
}
if(StringUtils.isEmpty(commentModel.getSyncTime())){
commentModel =sxDataService.getCommentModel();
}
if(ObjectUtil.isNotEmpty(dataBaseInfo.getRefreshTime())){
commentModel.setSyncTime(DateUtil.formatDateTime(dataBaseInfo.getRefreshTime()));
}
sxDataService.syncAtive(new DataBaseInfo(),commentModel);
// sxDataService.syncAtive(new DataBaseInfo(),new CommentModel());
} }
@RequestMapping("/syncAtiveShops") @RequestMapping("/syncAtiveShops")
public void syncAtiveShops(){ public void syncAtiveShops(){
sxDataService.syncAtiveShops(new DataBaseInfo(),sxDataService.getCommentModel()); CommentModel commentModel= sxDataService.getCommentModel();
DataBaseInfo dataBaseInfo=sxDataService.getDataBaseInfo(commentModel);
if(dataBaseInfo==null){
log.error("syncGoods dataBaseInfo is null");
return;
}
if(StringUtils.isEmpty(commentModel.getSyncTime())){
commentModel =sxDataService.getCommentModel();
}
if(ObjectUtil.isNotEmpty(dataBaseInfo.getRefreshTime())){
commentModel.setSyncTime(DateUtil.formatDateTime(dataBaseInfo.getRefreshTime()));
}
sxDataService.syncAtiveShops(new DataBaseInfo(),commentModel);
//sxDataService.syncAtiveShops(new DataBaseInfo(),new CommentModel());
} }
} }

View File

@ -16,7 +16,8 @@ import java.sql.SQLException;
public class BaseDao { public class BaseDao {
private final static String DEFAULT_IP="127.0.0.1"; private final static String DEFAULT_IP="127.0.0.1";
private final static String DEFAULT_DATABASE="hbposev9"; // private final static String DEFAULT_DATABASE="hbposev9";
private final static String DEFAULT_DATABASE="hbposv10";
private final static String DEFAULT_USERNAME="sa"; private final static String DEFAULT_USERNAME="sa";
private final static String DEFAULT_PWD="123456"; private final static String DEFAULT_PWD="123456";
private final static int PortNumber=1433; private final static int PortNumber=1433;
@ -123,6 +124,40 @@ public class BaseDao {
return resultDto; return resultDto;
} }
/**
* 带分页数据
* @param ip
* @param username
* @param password
* @param dataBaseName
* @param table
* @return
*/
public ResultDto baseVipFindListPage(String ip, String username, String password,Integer portNumber, String dataBaseName, String table,String orderColumn, int pageNo, int pageSize,String where){
Connection connection=getConnection(ip,username,password,portNumber,dataBaseName);
int start=(pageNo-1)*pageSize+1;
int end=pageNo*pageSize;
String sql=" select * from( " +
" select ROW_NUMBER() OVER( ORDER BY %s) as rowId," +
"ROW_NUMBER() OVER(partition by mobile ORDER BY vip_start_date desc) as rn," +
"* from %s %s" +
" ) as r where rn='1' and rowId between %s and %s";
sql=String.format(sql, orderColumn,table,where,start,end);
log.info(sql);
ResultDto resultDto=new ResultDto();
ResultSet rs=null;
try {
PreparedStatement ps= connection.prepareStatement(sql);
rs = ps.executeQuery();
} catch (SQLException e) {
log.info("数据库查询异常方法{},异常信息{}","com.suisung.mall.shop.sixun.dao.BaseDao.baseFindListPage",e.getMessage());
throw new RuntimeException(e);
}
resultDto.setResultSet(rs);
resultDto.setConnection(connection);
return resultDto;
}
public Integer getBaseTotal(String ip, String username, String password,Integer portNumber, String dataBaseName, String table,String where){ public Integer getBaseTotal(String ip, String username, String password,Integer portNumber, String dataBaseName, String table,String where){
int total=0; int total=0;
Connection connection=getConnection(ip,username,password,portNumber,dataBaseName); Connection connection=getConnection(ip,username,password,portNumber,dataBaseName);
@ -149,6 +184,34 @@ public class BaseDao {
return total; return total;
} }
public Integer getVipBaseTotal(String ip, String username, String password,Integer portNumber, String dataBaseName, String table,String where){
int total=0;
Connection connection=getConnection(ip,username,password,portNumber,dataBaseName);
try {
String sql=" select COUNT(1) from " +
"(select mobile from %s %s group by mobile " +
")t";
sql=String.format(sql, table,where);
log.info(sql);
PreparedStatement ps= connection.prepareStatement(sql);
ResultSet rs=ps.executeQuery();
while (rs.next()){
total=rs.getInt(1);
}
} catch (SQLException e) {
log.info("数据库查询异常方法{},异常信息{}","com.suisung.mall.shop.sixun.dao.BaseDao.getBaseTotal",e.getMessage());
throw new RuntimeException(e);
}
finally {
try {
connection.close();
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
return total;
}
public Integer getBaseJoinTotal(String ip, String username, String password,Integer portNumber, String dataBaseName, String table,String joinTable,String onLeft,String onRight,String orderColumn,String rightSelect,String where){ public Integer getBaseJoinTotal(String ip, String username, String password,Integer portNumber, String dataBaseName, String table,String joinTable,String onLeft,String onRight,String orderColumn,String rightSelect,String where){
int total=0; int total=0;

View File

@ -2,10 +2,13 @@ package com.small.client.dao;
import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil; import cn.hutool.core.date.DateUtil;
import com.small.client.Utils.BigDecimalFormatter; import com.small.client.Utils.BigDecimalFormatter;
import com.small.client.dto.*; import com.small.client.dto.*;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.math.NumberUtils;
import org.apache.commons.lang3.time.DateUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.math.BigDecimal; import java.math.BigDecimal;
@ -48,6 +51,7 @@ public class SxDataDao extends BaseDao{
private final static String T_RM_SPEC_PRICE="t_rm_spec_price";//活动表 private final static String T_RM_SPEC_PRICE="t_rm_spec_price";//活动表
public final static Integer PAGESIZE=500; 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 DEFALTWHERE="where 1=1";
@ -164,7 +168,7 @@ public class SxDataDao extends BaseDao{
* @return * @return
*/ */
public int getTrmVipInfoTotal(DataBaseInfo dataBaseInfo){ public int getTrmVipInfoTotal(DataBaseInfo dataBaseInfo){
return getBaseTotal(dataBaseInfo.getIp(),dataBaseInfo.getUserName(),dataBaseInfo.getPassword(),dataBaseInfo.getDbPort(),dataBaseInfo.getDataBaseName(),T_RM_VIP_INFO,dataBaseInfo.getWhere()); return getVipBaseTotal(dataBaseInfo.getIp(),dataBaseInfo.getUserName(),dataBaseInfo.getPassword(),dataBaseInfo.getDbPort(),dataBaseInfo.getDataBaseName(),T_RM_VIP_INFO,dataBaseInfo.getWhere());
} }
@ -255,7 +259,7 @@ public class SxDataDao extends BaseDao{
* @param pageSize * @param pageSize
*/ */
public List<SxSyncVip> findRmVipInfoListPage(DataBaseInfo dataBaseInfo, int pageNo, int pageSize){ public List<SxSyncVip> findRmVipInfoListPage(DataBaseInfo dataBaseInfo, int pageNo, int pageSize){
ResultDto resultDto=baseFindListPage(dataBaseInfo.getIp(),dataBaseInfo.getUserName(),dataBaseInfo.getPassword(),dataBaseInfo.getDbPort(),dataBaseInfo.getDataBaseName(),T_RM_VIP_INFO,CARD_ID,pageNo,pageSize,dataBaseInfo.getWhere()); 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(); ResultSet rs= resultDto.getResultSet();
List<SxSyncVip> sxSyncVips=new ArrayList<>(); List<SxSyncVip> sxSyncVips=new ArrayList<>();
SxSyncVip sxSyncVip=null; SxSyncVip sxSyncVip=null;
@ -269,21 +273,26 @@ public class SxDataDao extends BaseDao{
sxSyncVip.setMobile(rs.getString("mobile"));//会员名称 sxSyncVip.setMobile(rs.getString("mobile"));//会员名称
sxSyncVip.setBirthday(rs.getString("birthday"));//会员生日 sxSyncVip.setBirthday(rs.getString("birthday"));//会员生日
sxSyncVip.setCard_type(rs.getString("card_type")==null?"v1":rs.getString("card_type"));//会员生日 sxSyncVip.setCard_type(rs.getString("card_type")==null?"v1":rs.getString("card_type"));//会员生日
sxSyncVip.setCard_no(rs.getString("card_no"));//会员卡号 sxSyncVip.setCard_no(rs.getString("card_id"));//会员卡号
sxSyncVip.setCard_no(rs.getString("now_acc_num"));//会员积分 BigDecimal now_acc_num=null;
sxSyncVip.setCard_no(rs.getString("residual_amt"));//储值余额 try {
sxSyncVip.setCard_no(rs.getString("vip_start_date"));//建档日期 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");
}
log.info(rs.getString("vip_name"));//会员名称 sxSyncVip.setNow_acc_num(now_acc_num);//会员积分
log.info(rs.getString("mobile"));//会员手机号 String residual_amtStr=rs.getString("residual_amt");
log.info(rs.getString("vip_sex"));//会员性别 if(NumberUtils.isCreatable(residual_amtStr)){
log.info(rs.getString("birthday"));//会员生日 BigDecimal residual_amt=new BigDecimal(residual_amtStr);
log.info(rs.getString("card_no"));//会员卡号 sxSyncVip.setResidual_amt(residual_amt);//储值余额
log.info(rs.getString("card_type"));//会员等级 }else {
log.info("{}",rs.getBigDecimal("residual_amt"));//储值余额 sxSyncVip.setResidual_amtStr(residual_amtStr);
log.info("{}",rs.getBigDecimal("now_acc_num"));//会员积分 }
log.info(rs.getString("vip_start_date"));//建档日期 sxSyncVip.setVip_date(rs.getTimestamp("vip_start_date"));//建档日期
log.info("{}",rs.getInt("card_status"));//会员状态 sxSyncVip.setUser_nickname(rs.getString("vip_name"));
sxSyncVip.setUser_realname(rs.getString("vip_name"));
} }
sxSyncVips.add(sxSyncVip); sxSyncVips.add(sxSyncVip);
@ -531,12 +540,12 @@ public class SxDataDao extends BaseDao{
if(specialType.equals("6")||specialType.equals("G")){//折扣 if(specialType.equals("6")||specialType.equals("G")){//折扣
BigDecimal discount=rs.getBigDecimal("discount"); BigDecimal discount=rs.getBigDecimal("discount");
String discountStr=BigDecimalFormatter.formatWithoutTrailingZeros(rs.getBigDecimal("discount").multiply(new BigDecimal(10))); String discountStr=BigDecimalFormatter.formatWithoutTrailingZeros(rs.getBigDecimal("discount").multiply(new BigDecimal(10)));
activeDto.setActivityName(rs.getString(discountStr+"折商品")); activeDto.setActivityName(discountStr+"折商品");
activeDto.setActivityTypeId(2); activeDto.setActivityTypeId(2);
activeDto.setDiscount(discount); activeDto.setDiscount(discount);
} }
if(specialType.equals("0")){//特价秒杀 if(specialType.equals("0")){//特价秒杀
activeDto.setActivityName(rs.getString("限时特价秒杀")); activeDto.setActivityName("限时特价秒杀");
activeDto.setActivityTypeId(1); activeDto.setActivityTypeId(1);
} }
if(specialType.equals("E")){//满减 if(specialType.equals("E")){//满减
@ -544,7 +553,7 @@ public class SxDataDao extends BaseDao{
String max1=BigDecimalFormatter.formatWithoutTrailingZeros(rs.getBigDecimal("spe_price")); String max1=BigDecimalFormatter.formatWithoutTrailingZeros(rs.getBigDecimal("spe_price"));
String max2=BigDecimalFormatter.formatWithoutTrailingZeros(rs.getBigDecimal("spe_price").add(rs.getBigDecimal("new_price1"))); 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"))); String total2=BigDecimalFormatter.formatWithoutTrailingZeros(rs.getBigDecimal("old_price").add(rs.getBigDecimal("old_price1")));
activeDto.setActivityName(rs.getString("")+total1+""+max1+",满"+total2+""+max2); activeDto.setActivityName(""+total1+""+max1+",满"+total2+""+max2);
List<ActiveMaxDes> activeMaxDesList=new ArrayList<>(); List<ActiveMaxDes> activeMaxDesList=new ArrayList<>();
ActiveMaxDes activeMaxDes=new ActiveMaxDes(); ActiveMaxDes activeMaxDes=new ActiveMaxDes();
activeMaxDes.setMaxNum(rs.getBigDecimal("spe_price")); activeMaxDes.setMaxNum(rs.getBigDecimal("spe_price"));
@ -561,6 +570,7 @@ public class SxDataDao extends BaseDao{
activeDto.setActivityTypeId(3); activeDto.setActivityTypeId(3);
activeDto.setActiveMaxDesList(activeMaxDesList); activeDto.setActiveMaxDesList(activeMaxDesList);
} }
activeDto.setFlowNo(rs.getString("flow_no"));
activeDto.setActivityReleasetime(rs.getDate("oper_date")); activeDto.setActivityReleasetime(rs.getDate("oper_date"));
activeDto.setActivityStarttime(rs.getDate("start_date")); activeDto.setActivityStarttime(rs.getDate("start_date"));
activeDto.setActivityEndtime(rs.getDate("end_date")); activeDto.setActivityEndtime(rs.getDate("end_date"));
@ -633,13 +643,13 @@ public class SxDataDao extends BaseDao{
if(specialType.equals("6")||specialType.equals("G")){//折扣 if(specialType.equals("6")||specialType.equals("G")){//折扣
BigDecimal discount=rs.getBigDecimal("discount"); BigDecimal discount=rs.getBigDecimal("discount");
String discountStr=BigDecimalFormatter.formatWithoutTrailingZeros(discount.multiply(new BigDecimal(10))); String discountStr=BigDecimalFormatter.formatWithoutTrailingZeros(discount.multiply(new BigDecimal(10)));
activeShopInfo.setActivityName(rs.getString(discountStr+"折商品")); activeShopInfo.setActivityName(discountStr+"折商品");
activeShopInfo.setActivityTypeId(2); activeShopInfo.setActivityTypeId(2);
} }
if(specialType.equals("0")){//特价秒杀 if(specialType.equals("0")){//特价秒杀
activeShopInfo.setActivityName(rs.getString("限时特价秒杀")); activeShopInfo.setActivityName("限时特价秒杀");
activeShopInfo.setOldPrice(rs.getBigDecimal("old_price")); activeShopInfo.setOldPrice(rs.getBigDecimal("old_price"));
activeShopInfo.setSpecPrice(rs.getBigDecimal("spec_price")); activeShopInfo.setSpecPrice(rs.getBigDecimal("spe_price"));
activeShopInfo.setActivityTypeId(1); activeShopInfo.setActivityTypeId(1);
} }
if(specialType.equals("E")){//满减 if(specialType.equals("E")){//满减
@ -647,11 +657,12 @@ public class SxDataDao extends BaseDao{
String max1=BigDecimalFormatter.formatWithoutTrailingZeros(rs.getBigDecimal("spe_price")); String max1=BigDecimalFormatter.formatWithoutTrailingZeros(rs.getBigDecimal("spe_price"));
String max2=BigDecimalFormatter.formatWithoutTrailingZeros(rs.getBigDecimal("spe_price").add(rs.getBigDecimal("new_price1"))); 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"))); String total2=BigDecimalFormatter.formatWithoutTrailingZeros(rs.getBigDecimal("old_price").add(rs.getBigDecimal("old_price1")));
activeShopInfo.setActivityName(rs.getString("")+total1+""+max1+",满"+total2+""+max2); activeShopInfo.setActivityName(""+total1+""+max1+",满"+total2+""+max2);
activeShopInfo.setActivityTypeId(3); activeShopInfo.setActivityTypeId(3);
} }
activeShopInfo.setActivityStarttime(rs.getDate("start_date")); activeShopInfo.setActivityStarttime(rs.getDate("start_date"));
activeShopInfo.setActivityEndtime(rs.getDate("end_date")); activeShopInfo.setActivityEndtime(rs.getDate("end_date"));
activeShopInfo.setFlowNo(rs.getString("flow_no"));
if(DateUtil.compare(activeShopInfo.getActivityEndtime(),DateUtil.date())>0){ if(DateUtil.compare(activeShopInfo.getActivityEndtime(),DateUtil.date())>0){
activeShopInfo.setActivityState(1);//正常进行中 activeShopInfo.setActivityState(1);//正常进行中
}else { }else {

View File

@ -21,12 +21,10 @@ public class ActiveDto implements Serializable {
private Integer activityTypeId; private Integer activityTypeId;
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
@ApiModelProperty(value = "活动开始时间") @ApiModelProperty(value = "活动开始时间")
private Date activityStarttime; private Date activityStarttime;
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
@ApiModelProperty(value = "活动结束时间") @ApiModelProperty(value = "活动结束时间")
private Date activityEndtime; private Date activityEndtime;
@ -42,4 +40,7 @@ public class ActiveDto implements Serializable {
@ApiModelProperty(value = "满减规则") @ApiModelProperty(value = "满减规则")
private List<ActiveMaxDes> activeMaxDesList; private List<ActiveMaxDes> activeMaxDesList;
@ApiModelProperty(value = "活动id")
private String flowNo;
} }

View File

@ -41,4 +41,7 @@ public class ActiveShopInfo {
@ApiModelProperty(value = "折后价") @ApiModelProperty(value = "折后价")
private BigDecimal specPrice;//折后价 private BigDecimal specPrice;//折后价
@ApiModelProperty(value = "活动id")
private String flowNo;
} }

View File

@ -56,12 +56,14 @@ public class SxSyncVip implements Serializable {
@ApiModelProperty(value = "储值余额") @ApiModelProperty(value = "储值余额")
private BigDecimal residual_amt; private BigDecimal residual_amt;
@ApiModelProperty(value = "储值余额")
private String residual_amtStr;
@ApiModelProperty(value = "会员积分") @ApiModelProperty(value = "会员积分")
private BigDecimal now_acc_num; private BigDecimal now_acc_num;
@ApiModelProperty(value = "加入时间") @ApiModelProperty(value = "加入时间")
private String vip_date; private Date vip_date;
@ApiModelProperty(value = "会员状态") @ApiModelProperty(value = "会员状态")
private Integer card_status; private Integer card_status;
@ -77,4 +79,10 @@ public class SxSyncVip implements Serializable {
@ApiModelProperty(value = "更新时间") @ApiModelProperty(value = "更新时间")
private Date updated_at; private Date updated_at;
@ApiModelProperty("会员昵称")
private String user_nickname;
@ApiModelProperty("会员真实姓名")
private String user_realname;
} }

View File

@ -8,6 +8,8 @@ import cn.hutool.json.JSONUtil;
import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.small.client.Adapter.BigDecimalTypeAdapter;
import com.small.client.Cache.CommonCache; import com.small.client.Cache.CommonCache;
import com.small.client.Utils.*; import com.small.client.Utils.*;
import com.small.client.dao.SxDataDao; import com.small.client.dao.SxDataDao;
@ -34,6 +36,7 @@ import org.springframework.web.client.RestTemplate;
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.math.BigDecimal;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.nio.file.Files; import java.nio.file.Files;
import java.time.Duration; import java.time.Duration;
@ -88,7 +91,6 @@ public class SxDataServiceImp extends SxDataAbstService implements SxDataService
List<SxCategoryModel> sxCategoryModelList= ConVToSxCategoryModel(sxSyncCategories,allSxSyncCategories); List<SxCategoryModel> sxCategoryModelList= ConVToSxCategoryModel(sxSyncCategories,allSxSyncCategories);
JSONArray jsonArray =null; JSONArray jsonArray =null;
String jsonString=""; String jsonString="";
ObjectMapper objectMapper = new ObjectMapper();
try { try {
Gson gson=new Gson(); Gson gson=new Gson();
jsonString=gson.toJson(sxCategoryModelList); jsonString=gson.toJson(sxCategoryModelList);
@ -181,7 +183,7 @@ public class SxDataServiceImp extends SxDataAbstService implements SxDataService
@Override @Override
public void SyncVipList(DataBaseInfo dataBaseInfo, CommentModel commentModel) { public void SyncVipList(DataBaseInfo dataBaseInfo, CommentModel commentModel) {
dataBaseInfo= getDataBaseInfo(commentModel); dataBaseInfo= getDataBaseInfo(commentModel);
String where="where 1=1 "; String where="where mobile is not null and mobile <>'' ";
if(StringUtils.isNotEmpty(commentModel.getSyncTime())){ if(StringUtils.isNotEmpty(commentModel.getSyncTime())){
where+="and oper_date > '"+commentModel.getSyncTime()+"'"; where+="and oper_date > '"+commentModel.getSyncTime()+"'";
} }
@ -193,21 +195,16 @@ public class SxDataServiceImp extends SxDataAbstService implements SxDataService
return; return;
} }
// 总页数 // 总页数
int pages = CommonUtil.getPagesCount(total, SxDataDao.PAGESIZE); int pages = CommonUtil.getPagesCount(total, SxDataDao.PAGESIZE_MEMBER);
List<SyncThirdMemberReq> memberList=new ArrayList<>(); List<SyncThirdMemberReq> memberList=new ArrayList<>();
int syncCount =0; int syncCount =0;
for (int i = 1; i <=pages; i++) { for (int i = 1; i <=pages; i++) {
memberList.clear(); memberList.clear();
List<SxSyncVip> sxSyncVipList= sxDataDao.findRmVipInfoListPage(dataBaseInfo,i,SxDataDao.PAGESIZE); List<SxSyncVip> sxSyncVipList= sxDataDao.findRmVipInfoListPage(dataBaseInfo,i,SxDataDao.PAGESIZE_MEMBER);
//处理数据转换SxSyncVip>SyncThirdMemberReq //处理数据转换SxSyncVip>SyncThirdMemberReq
memberList=ConverList(sxSyncVipList); memberList=ConverList(sxSyncVipList);
String jsonString =""; Gson gson=new Gson();
ObjectMapper objectMapper = new ObjectMapper(); String jsonString = gson.toJson(memberList);
try {
jsonString = objectMapper.writeValueAsString(memberList);
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
}
String sign=CommonUtil.generateOpenSign(jsonString,commentModel.getAppId(),commentModel.getAppKey()); String sign=CommonUtil.generateOpenSign(jsonString,commentModel.getAppId(),commentModel.getAppKey());
String code= HttpUtils.postData(restTemplate,remoteIp+HttpUtils.URL_SYNC_MEMBER String code= HttpUtils.postData(restTemplate,remoteIp+HttpUtils.URL_SYNC_MEMBER
+"?appKey="+commentModel.getAppKey() +"?appKey="+commentModel.getAppKey()
@ -706,14 +703,9 @@ public class SxDataServiceImp extends SxDataAbstService implements SxDataService
public void syncAtive(DataBaseInfo dataBaseInfo, CommentModel commentModel) { public void syncAtive(DataBaseInfo dataBaseInfo, CommentModel commentModel) {
String where="where 1=1"; String where="where 1=1";
Integer total =0; Integer total =0;
if(DicEnum.SYNCTYPE_02.getCode().equals(dataBaseInfo.getSyncType())){
if(StringUtils.isNotEmpty(commentModel.getSyncTime())){ if(StringUtils.isNotEmpty(commentModel.getSyncTime())){
where+=" and b.modify_date>'"+commentModel.getSyncTime()+"' "; where+=" and b.start_date>'"+commentModel.getSyncTime()+"' ";
where+=" or b.build_date>'"+commentModel.getSyncTime()+"' "; where+=" or b.oper_date>'"+commentModel.getSyncTime()+"' ";
}
if(StringUtils.isNotEmpty(dataBaseInfo.getOperDate())){
where+=" and t.oper_date>'"+dataBaseInfo.getOperDate()+"' ";
}
} }
dataBaseInfo.setWhere(where); dataBaseInfo.setWhere(where);
total = sxDataDao.getActiveCount(dataBaseInfo); total = sxDataDao.getActiveCount(dataBaseInfo);
@ -724,20 +716,20 @@ public class SxDataServiceImp extends SxDataAbstService implements SxDataService
// 总页数 // 总页数
int pages = CommonUtil.getPagesCount(total, SxDataDao.PAGESIZE); int pages = CommonUtil.getPagesCount(total, SxDataDao.PAGESIZE);
int syncCount =0; int syncCount =0;
String encryptedData= getPrimaryKey(); // String encryptedData= getPrimaryKey();
Date tenMinutesAgo = Date.from(Instant.now());//刷新时间 Date tenMinutesAgo = Date.from(Instant.now());//刷新时间
Date refreshDate= DateUtil.date(tenMinutesAgo); Date refreshDate= DateUtil.date(tenMinutesAgo);
for (int i = 1; i <=pages; i++) { for (int i = 1; i <=pages; i++) {
List<ActiveDto> activeDtos= sxDataDao.getActiveList(dataBaseInfo,i,SxDataDao.PAGESIZE); List<ActiveDto> activeDtos= sxDataDao.getActiveList(dataBaseInfo,i,SxDataDao.PAGESIZE);
String jsonString=""; Gson gson=new GsonBuilder()
ObjectMapper objectMapper = new ObjectMapper(); .setDateFormat("yyyy-MM-dd HH:mm:ss") // 设置全局 Date 格式
try { .create();
jsonString = objectMapper.writeValueAsString(activeDtos); String jsonString= gson.toJson(activeDtos);
} catch (JsonProcessingException e) { JSONArray jsonArray = JSONUtil.parseArray(jsonString);
throw new RuntimeException(e); String sign=CommonUtil.generateOpenSign(jsonString,commentModel.getAppId(),commentModel.getAppKey());
}
String code= HttpUtils.postData(restTemplate,remoteIp+HttpUtils.URL_SYNC_ACTIVE String code= HttpUtils.postData(restTemplate,remoteIp+HttpUtils.URL_SYNC_ACTIVE
+"?primaryKey="+encryptedData, jsonString); +"?appKey="+commentModel.getAppKey()
+"&sign="+sign, jsonArray);
if (!HttpUtils.SUCCESSCODE.equals(code)) { if (!HttpUtils.SUCCESSCODE.equals(code)) {
continue; continue;
} }
@ -751,15 +743,11 @@ public class SxDataServiceImp extends SxDataAbstService implements SxDataService
public void syncAtiveShops(DataBaseInfo dataBaseInfo, CommentModel commentModel) { public void syncAtiveShops(DataBaseInfo dataBaseInfo, CommentModel commentModel) {
String where="where 1=1"; String where="where 1=1";
Integer total =0; Integer total =0;
if(DicEnum.SYNCTYPE_02.getCode().equals(dataBaseInfo.getSyncType())){
if(StringUtils.isNotEmpty(commentModel.getSyncTime())){ if(StringUtils.isNotEmpty(commentModel.getSyncTime())){
where+=" and b.modify_date>'"+commentModel.getSyncTime()+"' "; where+=" and start_date>'"+commentModel.getSyncTime()+"' ";
where+=" or b.build_date>'"+commentModel.getSyncTime()+"' "; where+=" or oper_date>'"+commentModel.getSyncTime()+"' ";
}
if(StringUtils.isNotEmpty(dataBaseInfo.getOperDate())){
where+=" and t.oper_date>'"+dataBaseInfo.getOperDate()+"' ";
}
} }
dataBaseInfo.setWhere(where); dataBaseInfo.setWhere(where);
total = sxDataDao.getAllSpecCount(dataBaseInfo); total = sxDataDao.getAllSpecCount(dataBaseInfo);
if(total==0){ if(total==0){
@ -769,20 +757,21 @@ public class SxDataServiceImp extends SxDataAbstService implements SxDataService
// 总页数 // 总页数
int pages = CommonUtil.getPagesCount(total, SxDataDao.PAGESIZE); int pages = CommonUtil.getPagesCount(total, SxDataDao.PAGESIZE);
int syncCount =0; int syncCount =0;
String encryptedData= getPrimaryKey(); // String encryptedData= getPrimaryKey();
Date tenMinutesAgo = Date.from(Instant.now());//刷新时间 Date tenMinutesAgo = Date.from(Instant.now());//刷新时间
Date refreshDate= DateUtil.date(tenMinutesAgo);//todo 要记录刷新时间 Date refreshDate= DateUtil.date(tenMinutesAgo);//todo 要记录刷新时间
for (int i = 1; i <=pages; i++) { for (int i = 1; i <=pages; i++) {
List<ActiveShopInfo> activeDtos= sxDataDao.getAllSpecPriceList(dataBaseInfo,i,SxDataDao.PAGESIZE); List<ActiveShopInfo> activeDtos= sxDataDao.getAllSpecPriceList(dataBaseInfo,i,SxDataDao.PAGESIZE);
String jsonString=""; Gson gson=new GsonBuilder()
ObjectMapper objectMapper = new ObjectMapper(); .setDateFormat("yyyy-MM-dd HH:mm:ss") // 设置全局 Date 格式
try { .registerTypeAdapter(BigDecimal.class,new BigDecimalTypeAdapter())
jsonString = objectMapper.writeValueAsString(activeDtos); .create();
} catch (JsonProcessingException e) { String jsonString=gson.toJson(activeDtos);
throw new RuntimeException(e); JSONArray jsonArray = JSONUtil.parseArray(jsonString);
} String sign=CommonUtil.generateOpenSign(jsonString,commentModel.getAppId(),commentModel.getAppKey());
String code= HttpUtils.postData(restTemplate,remoteIp+HttpUtils.URL_SYNC_ACTIVE_SHOP String code= HttpUtils.postData(restTemplate,remoteIp+HttpUtils.URL_SYNC_ACTIVE_SHOP
+"?primaryKey="+encryptedData, jsonString); +"?appKey="+commentModel.getAppKey()
+"&sign="+sign, jsonArray);
if (!HttpUtils.SUCCESSCODE.equals(code)) { if (!HttpUtils.SUCCESSCODE.equals(code)) {
continue; continue;
} }