shichongfu
2023-05-31 6f9405da1b729783c9c0811b5b475d03793c1da2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package com.product.mobile.core.controller;
 
import javax.servlet.http.HttpServletRequest;
 
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
 
import com.product.core.config.CoreConst;
import com.product.core.controller.support.AbstractBaseController;
import com.product.core.entity.FieldSetEntity;
import com.product.core.entity.RequestParameterEntity;
import com.product.core.log.SystemLogger;
import com.product.core.spring.context.SpringMVCContextHolder;
import com.product.mobile.core.config.MobileCoreCode;
import com.product.module.sys.version.ApiVersion;
 
/**
 * APP日志记录,存储到日志表中,或打印到后台。
 *
 * @author shicf
 */
@RequestMapping("/api/mobile")
@RestController
public class MobileLoggerController extends AbstractBaseController {
    /**
     * @param request
     * @return
     */
    @RequestMapping(value = "/system/log/{version}", method = RequestMethod.POST)
    @ApiVersion(1)
    public String writeLog(HttpServletRequest request) {
        FieldSetEntity fse = null;
        Object bean = request.getAttribute(CoreConst.API_POST_REQUEST_DATA);
        RequestParameterEntity reqp=null;
        if (bean != null) {
            reqp = (RequestParameterEntity) bean;
            fse = reqp.getFormData();
        }
        if (bean == null || fse == null) {
            SpringMVCContextHolder.getSystemLogger().error(MobileCoreCode.SYSTEM_FORM_NODATA.getValue(),
                    MobileCoreCode.SYSTEM_FORM_NODATA.getText());
            return this.error(MobileCoreCode.SYSTEM_FORM_NODATA.getValue(),
                    MobileCoreCode.SYSTEM_FORM_NODATA.getText());
        }
        if(fse.getString("log_type")==null || SystemLogger.LOG_TYPES_INFO.equals(fse.getString("log_type"))) {//普通日志
            if(fse.getBoolean("isSave")) {
                SpringMVCContextHolder.getSystemLogger().writeLog(fse.getString(CoreConst.CLIENT_TYPE)+"----- "+fse.getString("content"), reqp);
            }else {
                SpringMVCContextHolder.getSystemLogger().info(fse.getString(CoreConst.CLIENT_TYPE)+"------ "+fse.getString("content"));
            }
            
        }else if( SystemLogger.LOG_TYPES_ERROR.equals(fse.getString("log_type"))) {
            if(fse.getBoolean("isSave")) {
                SpringMVCContextHolder.getSystemLogger().writeLog(fse.getString(CoreConst.CLIENT_TYPE)+"------ "+fse.getString("content"), reqp);
            }else {
                SpringMVCContextHolder.getSystemLogger().error(fse.getString(CoreConst.CLIENT_TYPE)+"----- "+fse.getString("content"));
            }
        }
        
        return this.OK();
    }
}