| | |
| | | import com.ks.daylucky.exception.UserInfoException; |
| | | import com.ks.daylucky.exception.UserInfoExtraException; |
| | | import com.ks.daylucky.pojo.DO.UserInfo; |
| | | import com.ks.daylucky.pojo.DO.UserInfoExtra; |
| | | import com.ks.daylucky.pojo.DO.UserMsg; |
| | | import com.ks.daylucky.pojo.DTO.AlipayUserInfo; |
| | | import com.ks.daylucky.pojo.DTO.TokenDTO; |
| | | import com.ks.daylucky.pojo.DTO.UserMsgSettings; |
| | | import com.ks.daylucky.pojo.VO.AcceptData; |
| | | import com.ks.daylucky.pojo.VO.UserConfigVO; |
| | | import com.ks.daylucky.pojo.VO.UserMsgVO; |
| | | import com.ks.daylucky.service.UserInfoExtraService; |
| | | import com.ks.daylucky.service.UserInfoService; |
| | | import com.ks.daylucky.service.UserMsgService; |
| | | import com.ks.daylucky.util.Constant; |
| | | import com.ks.daylucky.util.RSAUtil; |
| | | import com.ks.daylucky.util.UserInfoUtil; |
| | | import com.ks.daylucky.util.factory.vo.UserMsgVOFactory; |
| | | import net.sf.json.JSONObject; |
| | | import org.springframework.stereotype.Controller; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.io.ByteArrayInputStream; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | @Controller |
| | | @RequestMapping("api/client/user") |
| | | @RequestMapping(value = "api/client/user", produces = "application/json;charset=utf-8") |
| | | public class UserController { |
| | | @Resource |
| | | private UserInfoService userInfoService; |
| | |
| | | user = new UserInfo(); |
| | | user.setAppId(acceptData.getApp().getId()); |
| | | user.setIdentifyCode(identifyCode); |
| | | user.setAlipayUid(identifyCode); |
| | | try { |
| | | Long uid = userInfoService.addUserInfo(user); |
| | | user.setId(uid); |
| | |
| | | if (user == null) { |
| | | return JsonUtil.loadFalseResult("用户不存在"); |
| | | } |
| | | return JsonUtil.loadTrueResult(JsonUtil.getApiCommonGson().toJson(user)); |
| | | } |
| | | |
| | | /** |
| | | * 支付宝用户信息上传 |
| | | * |
| | | * @param acceptData |
| | | * @param userInfo |
| | | * @return |
| | | */ |
| | | @ResponseBody |
| | | @RequestMapping("uploadAlipayUserInfo") |
| | | public String uploadAlipayUserInfo(AcceptData acceptData, String userInfo) { |
| | | String decryptStr = RSAUtil.decrypt(userInfo); |
| | | if (StringUtil.isNullOrEmpty(decryptStr)) { |
| | | return JsonUtil.loadFalseResult("用户信息获取失败"); |
| | | } |
| | | AlipayUserInfo alipayUserInfo = JsonUtil.getSimpleGson().fromJson(decryptStr, AlipayUserInfo.class); |
| | | |
| | | UserInfo user = new UserInfo(); |
| | | user.setId(acceptData.getUid()); |
| | | user.setPortrait(alipayUserInfo.getAvatar()); |
| | | user.setNickName(alipayUserInfo.getNickName()); |
| | | user.setAlipayNickName(alipayUserInfo.getNickName()); |
| | | user.setAlipayPortrait(alipayUserInfo.getAvatar()); |
| | | userInfoService.updateUserInfo(user); |
| | | |
| | | user = userInfoService.getUserDetail(user.getId()); |
| | | |
| | | return JsonUtil.loadTrueResult(JsonUtil.getApiCommonGson().toJson(user)); |
| | | } |
| | | |
| | |
| | | @RequestMapping("getUserMsgList") |
| | | public String getUserMsgList(AcceptData acceptData, int page) { |
| | | List<UserMsg> msgList = userMsgService.getUserMsgList(acceptData.getUid(), page, Constant.PAGE_SIZE); |
| | | List<UserMsgVO> voList = new ArrayList<>(); |
| | | if (msgList != null) { |
| | | for (UserMsg userMsg : msgList) { |
| | | voList.add(UserMsgVOFactory.create(userMsg)); |
| | | } |
| | | } |
| | | |
| | | |
| | | long count = userMsgService.countUserMsg(acceptData.getUid()); |
| | | Gson gson = JsonUtil.getConvertDateToShortNameBuilder(new GsonBuilder().excludeFieldsWithoutExposeAnnotation()).create(); |
| | | Gson gson = JsonUtil.getConvertDateToShortNameBuilder(new GsonBuilder()).create(); |
| | | |
| | | JSONObject data = new JSONObject(); |
| | | data.put("data", gson.toJson(msgList)); |
| | | data.put("data", gson.toJson(voList)); |
| | | data.put("count", count); |
| | | return JsonUtil.loadTrueResult(data); |
| | | } |
| | | |
| | | @ResponseBody |
| | | @RequestMapping("getUserConfig") |
| | | public String getUserConfig(AcceptData acceptData) { |
| | | //消息未读数 |
| | | UserInfoExtra extra = userInfoExtraService.getUserInfoExtra(acceptData.getUid()); |
| | | if (extra == null) { |
| | | return JsonUtil.loadFalseResult("用户不存在"); |
| | | } |
| | | UserConfigVO vo = new UserConfigVO(); |
| | | vo.setMsgCount(extra.getMsgUnreadCount()); |
| | | return JsonUtil.loadTrueResult(vo); |
| | | } |
| | | |
| | | |
| | | } |