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

同步终端记录

上级 5006fb36
......@@ -16,7 +16,7 @@ import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice;
/**
* @author : liqiulin
* @date : 2024-03-28 17
* @describe : todo 自动封装
* @describe : 自动封装
*/
@RestControllerAdvice
public class ControllerResponseAdvice implements ResponseBodyAdvice<Object> {
......
......@@ -3,13 +3,18 @@ package com.wangxiaolu.promotion.controller.activity.temporary;
import com.alibaba.fastjson.JSONObject;
import com.wangxiaolu.promotion.common.redis.RedisKeys;
import com.wangxiaolu.promotion.common.redis.service.RedisCache;
import com.wangxiaolu.promotion.exception.FlowException;
import com.wangxiaolu.promotion.pojo.activity.temporary.dto.PromotionStoreDto;
import com.wangxiaolu.promotion.pojo.activity.temporary.vo.TemporaryClockVo;
import com.wangxiaolu.promotion.result.basedata.R;
import com.wangxiaolu.promotion.result.basedata.RCode;
import com.wangxiaolu.promotion.service.activity.temporary.PromotionStoreCoreService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.Objects;
/**
* @author : liqiulin
* @date : 2024-06-18 13
......@@ -27,6 +32,9 @@ public class PromotionStoreCoreController {
@PostMapping("/save")
public R saveStore(@RequestHeader("Authorization") String authorization, @RequestBody PromotionStoreDto promotionStoreDto) {
// 是否重复提交
repetitiveSaveStore(authorization);
// 在缓存中查询
JSONObject userJson = redisCache.getToJson(RedisKeys.UserKeys.TEMPORARY_TOKEN.getKey() + authorization);
......@@ -37,8 +45,16 @@ public class PromotionStoreCoreController {
promotionStoreDto.setChargerQcId(userJson.getString("chargerQcId"));
promotionStoreDto.setChargerName(userJson.getString("chargerName"));
promotionStoreCoreService.saveStore(promotionStoreDto);
return R.success();
}
private void repetitiveSaveStore(String authorization) {
String recordKey = RedisKeys.TemporaryKeys.TEMPORARY_SAVE_STORE_REPETITIVE.getKey() + authorization;
String record = redisCache.get(recordKey);
if (Objects.nonNull(record)) {
throw new FlowException(RCode.PROMOTION_STORE_SAVE_ERROR.getCode(), String.format(RCode.PROMOTION_STORE_SAVE_ERROR.getMsg(), "3"));
}
redisCache.addToJsonToMinute(recordKey, authorization, 3);
}
}
package com.wangxiaolu.promotion.controller.activity.temporary;
import com.alibaba.fastjson.JSONObject;
import com.wangxiaolu.promotion.common.redis.RedisKeys;
import com.wangxiaolu.promotion.common.redis.service.RedisCache;
import com.wangxiaolu.promotion.enums.activity.ClockType;
import com.wangxiaolu.promotion.exception.FlowException;
import com.wangxiaolu.promotion.exception.ParamException;
import com.wangxiaolu.promotion.pojo.activity.temporary.dto.TemporaryClockDto;
import com.wangxiaolu.promotion.pojo.activity.temporary.vo.TemporaryClockVo;
......@@ -9,9 +11,7 @@ import com.wangxiaolu.promotion.result.basedata.R;
import com.wangxiaolu.promotion.result.basedata.RCode;
import com.wangxiaolu.promotion.service.activity.temporary.TemporaryActivityCoreService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
......@@ -32,6 +32,8 @@ public class TemporaryActivityClockCoreController {
@Autowired
private TemporaryActivityCoreService tempActivityCoreService;
@Autowired
RedisCache redisCache;
/**
* 促销员当日打卡信息保存
......@@ -53,11 +55,8 @@ public class TemporaryActivityClockCoreController {
// 根据打卡经纬度判断与打卡店铺的距离,距离超过100米不能打卡
// tempActivityCoreService.clockStoreCalDistance(clockVo.getStoreQcId(),clockVo.getId(),clockVo.getClockCoordinates());
/**
* todo redis打卡-限制重复提交
* todo 后续添加,基于redis
*/
// 限制重复提交
repetitiveClock(clockVo);
Date clockTime = new Date();
TemporaryClockDto dto = new TemporaryClockDto(clockVo.getClockType(), clockVo.getId(), clockVo.getTemporaryId(), clockVo.getTemporaryName(), clockVo.getClockProvince(), clockVo.getClockCity());
......@@ -75,9 +74,22 @@ public class TemporaryActivityClockCoreController {
return R.success();
}
/**
* redis打卡-限制重复提交
*/
private void repetitiveClock(TemporaryClockVo clockVo) {
String clockRecordKey = RedisKeys.TemporaryKeys.TEMPORARY_CLOCK_RECIRD.getKey() + clockVo.getTemporaryId() + "_" + clockVo.getClockType();
String record = redisCache.get(clockRecordKey);
if (Objects.nonNull(record)) {
throw new FlowException(RCode.USER_REPETITIVE_CLOCK_MINUTE.getCode(), String.format(RCode.USER_REPETITIVE_CLOCK_MINUTE.getMsg(), "2"));
}
redisCache.addToJsonToMinute(clockRecordKey, clockVo.getTemporaryName(), 2);
}
// 上班打卡
private void builderClockInData(TemporaryClockVo clockVo, TemporaryClockDto clockDto, Date dateTime) {
// todo if (!DateUtils.parseTime(new Date(), ClockType.TEMPORARY_CLOCK_IN_BEGIN_TIME, ClockType.TEMPORARY_CLOCK_IN_END_TIME)) {
// if (!DateUtils.parseTime(new Date(), ClockType.TEMPORARY_CLOCK_IN_BEGIN_TIME, ClockType.TEMPORARY_CLOCK_IN_END_TIME)) {
// throw new ParamException(RCode.CLOCK_DETAIL_TIME_ERROR, null);
// }
......@@ -93,7 +105,7 @@ public class TemporaryActivityClockCoreController {
// 午休下班卡
private void builderNoonClockOutData(TemporaryClockVo clockVo, TemporaryClockDto clockDto, Date dateTime) {
// todo if (!DateUtils.parseTime(new Date(), ClockType.TEMPORARY_NOON_CLOCK_OUT_BEGIN_TIME, ClockType.TEMPORARY_NOON_CLOCK_OUT_END_TIME)) {
// if (!DateUtils.parseTime(new Date(), ClockType.TEMPORARY_NOON_CLOCK_OUT_BEGIN_TIME, ClockType.TEMPORARY_NOON_CLOCK_OUT_END_TIME)) {
// throw new ParamException(RCode.CLOCK_DETAIL_TIME_ERROR, null);
// }
clockDto.setId(clockVo.getId())
......@@ -106,7 +118,7 @@ public class TemporaryActivityClockCoreController {
// 午休上班卡
private void builderNoonClockInData(TemporaryClockVo clockVo, TemporaryClockDto clockDto, Date dateTime) {
// todo if (!DateUtils.parseTime(new Date(), ClockType.TEMPORARY_NOON_CLOCK_IN_BEGIN_TIME, ClockType.TEMPORARY_NOON_CLOCK_IN_END_TIME)) {
// if (!DateUtils.parseTime(new Date(), ClockType.TEMPORARY_NOON_CLOCK_IN_BEGIN_TIME, ClockType.TEMPORARY_NOON_CLOCK_IN_END_TIME)) {
// throw new ParamException(RCode.CLOCK_DETAIL_TIME_ERROR, null);
// }
clockDto.setId(clockVo.getId())
......@@ -118,7 +130,7 @@ public class TemporaryActivityClockCoreController {
// 下班卡
private void builderClockOutData(TemporaryClockVo clockVo, TemporaryClockDto clockDto, Date dateTime) {
// todo if (!DateUtils.parseTime(new Date(), ClockType.TEMPORARY_CLOCK_OUT_BEGIN_TIME, ClockType.TEMPORARY_CLOCK_OUT_END_TIME)) {
// if (!DateUtils.parseTime(new Date(), ClockType.TEMPORARY_CLOCK_OUT_BEGIN_TIME, ClockType.TEMPORARY_CLOCK_OUT_END_TIME)) {
// throw new ParamException(RCode.CLOCK_DETAIL_TIME_ERROR, null);
// }
clockDto.setId(clockVo.getId())
......
......@@ -10,6 +10,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.validation.constraints.NotNull;
import java.util.Objects;
/**
* @author : liqiulin
......@@ -69,7 +70,7 @@ public class TemporaryActivityQueryController {
*/
@GetMapping("/today/reported/market_cell/{id}")
public R findActivityMarketCellByDb(@PathVariable("id") Long activityId) {
if (activityId <= 0){
if (Objects.isNull(activityId) || (activityId <= 0)) {
return R.success();
}
return R.success(temporaryActivityQueryService.findActivityMarketCellByDb(activityId));
......
package com.wangxiaolu.promotion.domain.activity.dao;
import com.alibaba.fastjson.JSONArray;
import com.wangxiaolu.promotion.domain.activity.wrapperQo.PromotionStoreWrapper;
import com.wangxiaolu.promotion.pojo.activity.temporary.dto.PromotionStoreDto;
import com.wangxiaolu.promotion.pojo.activity.temporary.vo.PromotionStoreVo;
......@@ -19,4 +20,5 @@ public interface PromotionStoreDao {
PromotionStoreDto selectOneById(Long id);
void qinceShopDetailAllTask(JSONArray responseDatas);
}
package com.wangxiaolu.promotion.domain.activity.dao.impl;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.wangxiaolu.promotion.domain.activity.dao.PromotionStoreDao;
import com.wangxiaolu.promotion.domain.activity.mapper.PromotionStoreMapper;
import com.wangxiaolu.promotion.domain.activity.mapper.entity.PromotionStoreDO;
import com.wangxiaolu.promotion.domain.activity.wrapperQo.PromotionStoreWrapper;
import com.wangxiaolu.promotion.domain.user.mapper.entity.QinCeClienteleStoreDO;
import com.wangxiaolu.promotion.domain.user.mapper.entity.QinCeDepartmentDO;
import com.wangxiaolu.promotion.exception.ParamException;
import com.wangxiaolu.promotion.pojo.activity.temporary.dto.PromotionStoreDto;
import com.wangxiaolu.promotion.result.basedata.RCode;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
......@@ -35,6 +40,14 @@ public class PromotionStoreDaoImpl implements PromotionStoreDao {
*/
@Override
public void save(PromotionStoreDto promotionStoreDto) {
// 查询是否重名
PromotionStoreWrapper psw = new PromotionStoreWrapper()
.setStoreName(promotionStoreDto.getStoreName());
int coud = findCoud(psw);
if (coud > 0 ){
throw new ParamException(RCode.PROMOTION_STORE_HAS_NAME,null);
}
PromotionStoreDO storeDo = new PromotionStoreDO();
BeanUtils.copyProperties(promotionStoreDto, storeDo);
promotionStoreMapper.insert(storeDo);
......@@ -56,6 +69,32 @@ public class PromotionStoreDaoImpl implements PromotionStoreDao {
return transitionDto(promotionStoreDO);
}
@Override
public void qinceShopDetailAllTask(JSONArray responseDatas) {
for (Object responseData : responseDatas) {
JSONObject jo = JSONObject.parseObject(JSONObject.toJSONString(responseData));
try {
PromotionStoreDO storeDo = new PromotionStoreDO();
storeDo.setQcId(jo.getString("id"))
.setStoreName(jo.getString("store_name"))
.setProvince(jo.getString("store_mss_province"))
.setCity(jo.getString("store_mss_city"))
.setArea(jo.getString("store_mss_area"))
.setStreet(jo.getString("store_mss_street"))
.setAddress(jo.getString("store_addr"))
.setTemporaryId(0)
.setTemporaryName("系统同步");
promotionStoreMapper.insert(storeDo);
} catch (Exception e) {
log.error("勤策-同步终端store数据异常,异常数据:{}", responseData);
log.error("勤策-同步终端store数据异常\n{}", e.getMessage());
}
}
}
private LambdaQueryWrapper<PromotionStoreDO> buildWrapper(PromotionStoreWrapper promotionStoreWrapper){
LambdaQueryWrapper<PromotionStoreDO> lqw = new LambdaQueryWrapper<>();
if (StringUtils.isNotBlank(promotionStoreWrapper.getArea())){
......@@ -64,6 +103,12 @@ public class PromotionStoreDaoImpl implements PromotionStoreDao {
return lqw;
}
private int findCoud(PromotionStoreWrapper promotionStoreWrapper){
LambdaQueryWrapper<PromotionStoreDO> qw = buildWrapper(promotionStoreWrapper);
Integer count = promotionStoreMapper.selectCount(qw);
return count;
}
/**
* DO to DTO (单个对象)
......
......@@ -7,6 +7,7 @@ import com.baomidou.mybatisplus.annotation.TableName;
import java.io.Serializable;
import java.util.Date;
import lombok.Data;
import lombok.experimental.Accessors;
/**
* 促销店铺数据
......@@ -14,6 +15,7 @@ import lombok.Data;
*/
@TableName(value ="promotion_store")
@Data
@Accessors(chain = true)
public class PromotionStoreDO implements Serializable {
/**
* 主键id
......@@ -21,6 +23,11 @@ public class PromotionStoreDO implements Serializable {
@TableId(type = IdType.AUTO)
private Long id;
/**
* qc_id
*/
private String qcId;
/**
* 店铺名称
*/
......
......@@ -24,4 +24,5 @@ public class PromotionStoreWrapper {
private String area;
private String storeNameLike;
private String storeName;
}
......@@ -2,6 +2,7 @@ package com.wangxiaolu.promotion.service.user.impl;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.wangxiaolu.promotion.domain.activity.dao.PromotionStoreDao;
import com.wangxiaolu.promotion.domain.user.dao.*;
import com.wangxiaolu.promotion.service.user.QinCeDataTaskService;
import com.wangxiaolu.promotion.utils.OkHttp;
......@@ -33,6 +34,8 @@ public class QinCeDataTaskServiceImpl implements QinCeDataTaskService {
QinceProductTypeDao qinceProductTypeDao;
@Autowired
QinceProductInfoDao qinceProductInfoDao;
@Autowired
PromotionStoreDao promotionStoreDao;
@Override
public void departmentSyncTask() {
......@@ -118,7 +121,8 @@ public class QinCeDataTaskServiceImpl implements QinCeDataTaskService {
}
log.info("勤策-同步终端store数据,查询到第{}页数据「{}」条", pageNum, responseDatas.size());
qinCeClienteleShopDao.shopDetailAllTask(responseDatas);
// qinCeClienteleShopDao.shopDetailAllTask(responseDatas);
promotionStoreDao.qinceShopDetailAllTask(responseDatas);
return true;
}
}
......@@ -126,7 +126,7 @@ public class QinCeUtils {
params.put("page_number", pageNum);
// 记录状态。0:已删除,1:正常
// 0:已删除:客户回收站中的终端数据
params.put("status", "");
params.put("status", "1");
// 勤策的门店唯一ID
params.put("id", "");
// 来源于第三方系统的门店唯一ID,对应新增门店 (store_id)字段,只有当数据来源于新增接口时才有值,如果数据从勤策系统中直接创建则该字段值为空。 如果两个值同时存在则优先顺序为store_waiqin_id、store_id
......@@ -140,9 +140,9 @@ public class QinCeUtils {
// 门店类型编码,store_type、store_type_code如果同时存在优先取store_type_code
params.put("store_type_code", "");
// 门店类型
params.put("store_type", "");
// 门店所属销售区域,此字段需要销售区域的完整层级结构, 多层级间以“,”分隔,如:华中大区,南京分区,秦淮社区
params.put("store_district", "");
params.put("store_status", "1");
// 门店审批状态。1:待审批,2:审批打回,3:审批通过
params.put("store_approval_status", "3");
return params;
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论