admin
2024-09-05 ab35ac8b769b2d9816dffb33a64f2c6f7bd5dd6e
src/main/java/com/yeshi/buwan/controller/api/UserController.java
@@ -1,6 +1,6 @@
package com.yeshi.buwan.controller.api;
import com.google.gson.Gson;
import com.google.gson.*;
import com.yeshi.buwan.controller.parser.UserParser;
import com.yeshi.buwan.domain.user.LoginUser;
import com.yeshi.buwan.domain.user.LoginUserExtra;
@@ -13,12 +13,16 @@
import com.yeshi.buwan.util.factory.vo.UserInfoVOFactory;
import com.yeshi.buwan.vo.AcceptData;
import com.yeshi.buwan.vo.client.user.UserInfoVO;
import org.json.JSONObject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.lang.reflect.Type;
import java.text.DateFormat;
import java.util.Date;
@Controller
@RequestMapping("api/v2/user")
@@ -63,8 +67,34 @@
                loginUserService.setUtdId(loginUid, acceptData.getUtdId());
            }
        });
        return JsonUtil.loadTrueJson(new Gson().toJson(vo));
        if ("ios".equalsIgnoreCase(acceptData.getPlatform())) {
            if(StringUtil.isNullOrEmpty(vo.getBirthday())){
                vo.setBirthday(loginUser.getBirthday());
            }
            if(StringUtil.isNullOrEmpty(vo.getSex())){
                vo.setSex(loginUser.getSex());
            }
            if(StringUtil.isNullOrEmpty(vo.getSign())){
                vo.setSign(loginUser.getSign());
            }
            Gson gson = new GsonBuilder().enableComplexMapKeySerialization()
                    .setDateFormat(DateFormat.LONG).registerTypeAdapter(Date.class, new JsonSerializer<Date>() {
                        @Override
                        public JsonElement serialize(Date value, Type theType, JsonSerializationContext context) {
                            if (value == null) {
                                return new JsonPrimitive("0");
                            } else {
                                return new JsonPrimitive(value.getTime());
                            }
                        }
                    }).setFieldNamingPolicy(FieldNamingPolicy.UPPER_CAMEL_CASE)// 会把字段首字母大写
                    .setPrettyPrinting().setVersion(1.0).create();
            net.sf.json.JSONObject root= net.sf.json.JSONObject.fromObject(gson.toJson(vo));
            root.put("Nickname",vo.getNickName());
            return JsonUtil.loadTrueJson(root.toString());
        } else {
            return JsonUtil.loadTrueJson(new Gson().toJson(vo));
        }
    }