Commit 35b05022 by 墨竹

fix:埋点增加判断

parent 33b6873c
...@@ -10,6 +10,8 @@ import com.gic.haoban.manage.api.dto.MaidianLogDTO; ...@@ -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.api.service.MaidianLogApiService;
import com.gic.haoban.manage.web.errCode.HaoBanErrCode; import com.gic.haoban.manage.web.errCode.HaoBanErrCode;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
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;
...@@ -17,39 +19,57 @@ import org.springframework.web.bind.annotation.RestController; ...@@ -17,39 +19,57 @@ import org.springframework.web.bind.annotation.RestController;
import java.util.List; import java.util.List;
@RestController @RestController
public class MaidianLogController extends WebBaseController{ public class MaidianLogController extends WebBaseController {
private static final Logger logger = LoggerFactory.getLogger(MaidianLogController.class);
@Autowired
private MaidianLogApiService maidianLogApiService; @Autowired
@Autowired private MaidianLogApiService maidianLogApiService;
private ClerkService clerkService; @Autowired
@Autowired private ClerkService clerkService;
private StoreService storeService; @Autowired
private StoreService storeService;
@RequestMapping("save-maidian-log")
@IgnoreLogin @RequestMapping("save-maidian-log")
public HaobanResponse saveUserLoginLog(String maidianLogStr) { @IgnoreLogin
if(StringUtils.isBlank(maidianLogStr)){ public HaobanResponse saveUserLoginLog(String maidianLogStr) {
return resultResponse(HaoBanErrCode.ERR_2); if (StringUtils.isBlank(maidianLogStr)) {
} return resultResponse(HaoBanErrCode.ERR_2);
List<MaidianLogDTO> maidianLogDTOList = JSON.parseArray(maidianLogStr,MaidianLogDTO.class); }
for (MaidianLogDTO maidianLogDTO : maidianLogDTOList) { if (!isJsonArray(maidianLogStr)) {
String options = maidianLogDTO.getOptions(); logger.error("埋点格式不正确:{}", maidianLogStr);
if(StringUtils.isNotBlank(options) && options.length() > 2000){ return resultResponse(HaoBanErrCode.ERR_1);
maidianLogDTO.setOptions(options.substring(0,1999)); }
} List<MaidianLogDTO> maidianLogDTOList = JSON.parseArray(maidianLogStr, MaidianLogDTO.class);
StoreDTO store = storeService.getStore(maidianLogDTO.getStoreId()); for (MaidianLogDTO maidianLogDTO : maidianLogDTOList) {
if(store != null){ String options = maidianLogDTO.getOptions();
com.gic.clerk.api.dto.ClerkDTO clerkDTO = clerkService.getClerkByClerkCode(store.getEnterpriseId(), maidianLogDTO.getClerkCode()); if (StringUtils.isNotBlank(options) && options.length() > 2000) {
maidianLogDTO.setEnterpriseId(store.getEnterpriseId()); maidianLogDTO.setOptions(options.substring(0, 1999));
if(clerkDTO != null){ }
maidianLogDTO.setClerkId(clerkDTO.getClerkId()); StoreDTO store = storeService.getStore(maidianLogDTO.getStoreId());
} if (store != null) {
} com.gic.clerk.api.dto.ClerkDTO clerkDTO = clerkService.getClerkByClerkCode(store.getEnterpriseId(), maidianLogDTO.getClerkCode());
maidianLogApiService.insert(maidianLogDTO); maidianLogDTO.setEnterpriseId(store.getEnterpriseId());
} if (clerkDTO != null) {
return resultResponse(HaoBanErrCode.ERR_1); maidianLogDTO.setClerkId(clerkDTO.getClerkId());
}
} }
maidianLogApiService.insert(maidianLogDTO);
}
return resultResponse(HaoBanErrCode.ERR_1);
}
/**
* 检查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