Commit 35b05022 by 墨竹

fix:埋点增加判断

parent 33b6873c
......@@ -10,6 +10,8 @@ import com.gic.haoban.manage.api.dto.MaidianLogDTO;
import com.gic.haoban.manage.api.service.MaidianLogApiService;
import com.gic.haoban.manage.web.errCode.HaoBanErrCode;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
......@@ -17,7 +19,8 @@ import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@RestController
public class MaidianLogController extends WebBaseController{
public class MaidianLogController extends WebBaseController {
private static final Logger logger = LoggerFactory.getLogger(MaidianLogController.class);
@Autowired
private MaidianLogApiService maidianLogApiService;
......@@ -29,20 +32,24 @@ public class MaidianLogController extends WebBaseController{
@RequestMapping("save-maidian-log")
@IgnoreLogin
public HaobanResponse saveUserLoginLog(String maidianLogStr) {
if(StringUtils.isBlank(maidianLogStr)){
if (StringUtils.isBlank(maidianLogStr)) {
return resultResponse(HaoBanErrCode.ERR_2);
}
List<MaidianLogDTO> maidianLogDTOList = JSON.parseArray(maidianLogStr,MaidianLogDTO.class);
if (!isJsonArray(maidianLogStr)) {
logger.error("埋点格式不正确:{}", maidianLogStr);
return resultResponse(HaoBanErrCode.ERR_1);
}
List<MaidianLogDTO> maidianLogDTOList = JSON.parseArray(maidianLogStr, MaidianLogDTO.class);
for (MaidianLogDTO maidianLogDTO : maidianLogDTOList) {
String options = maidianLogDTO.getOptions();
if(StringUtils.isNotBlank(options) && options.length() > 2000){
maidianLogDTO.setOptions(options.substring(0,1999));
if (StringUtils.isNotBlank(options) && options.length() > 2000) {
maidianLogDTO.setOptions(options.substring(0, 1999));
}
StoreDTO store = storeService.getStore(maidianLogDTO.getStoreId());
if(store != null){
if (store != null) {
com.gic.clerk.api.dto.ClerkDTO clerkDTO = clerkService.getClerkByClerkCode(store.getEnterpriseId(), maidianLogDTO.getClerkCode());
maidianLogDTO.setEnterpriseId(store.getEnterpriseId());
if(clerkDTO != null){
if (clerkDTO != null) {
maidianLogDTO.setClerkId(clerkDTO.getClerkId());
}
}
......@@ -52,4 +59,17 @@ public class MaidianLogController extends WebBaseController{
}
/**
* 检查JSON数据合法性
*/
public boolean isJsonArray(String str) {
try {
JSON.parseArray(str);
return true;
} catch (Exception e) {
logger.error("埋点格式不正确:{}", str, e);
return false;
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment