Commit a8b5493a authored by muhong's avatar muhong

修改 小程序目录

parent be7597bf
package com.wwdz.ch.wx.annotation.support; package com.wwdz.ch.wx.annotation.support;
import com.wwdz.ch.wx.service.UserTokenManager; import com.wwdz.ch.wx.manager.UserTokenManager;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.MethodParameter; import org.springframework.core.MethodParameter;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
......
...@@ -12,7 +12,7 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; ...@@ -12,7 +12,7 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import java.util.List; import java.util.List;
@Configuration @Configuration
public class WxWebMvcConfiguration implements WebMvcConfigurer { public class WebMvcConfiguration implements WebMvcConfigurer {
@Bean @Bean
LoginInterceptor loginInterceptor() { LoginInterceptor loginInterceptor() {
return new LoginInterceptor(); return new LoginInterceptor();
......
...@@ -21,7 +21,7 @@ import com.wwdz.ch.wx.entity.request.FavoritesRequestDto; ...@@ -21,7 +21,7 @@ import com.wwdz.ch.wx.entity.request.FavoritesRequestDto;
import com.wwdz.ch.wx.entity.request.UserRequestDto; import com.wwdz.ch.wx.entity.request.UserRequestDto;
import com.wwdz.ch.wx.service.FavoritesService; import com.wwdz.ch.wx.service.FavoritesService;
import com.wwdz.ch.wx.service.UserService; import com.wwdz.ch.wx.service.UserService;
import com.wwdz.ch.wx.service.UserTokenManager; import com.wwdz.ch.wx.manager.UserTokenManager;
import com.wwdz.ch.wx.service.WxLoginService; import com.wwdz.ch.wx.service.WxLoginService;
import com.wwdz.ch.wx.util.IpUtil; import com.wwdz.ch.wx.util.IpUtil;
import com.wwdz.ch.wx.util.StringUtil; import com.wwdz.ch.wx.util.StringUtil;
......
package com.wwdz.ch.wx.service; package com.wwdz.ch.wx.manager;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.HashMap; import java.util.HashMap;
......
package com.wwdz.ch.wx.service; package com.wwdz.ch.wx.manager;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.HashMap; import java.util.HashMap;
......
package com.wwdz.ch.wx.service; package com.wwdz.ch.wx.manager;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.wwdz.ch.core.util.CharUtil; import com.wwdz.ch.core.util.CharUtil;
......
package com.wwdz.ch.wx.service;
import com.wwdz.ch.db.dao.dts.DtsUserDao;
import com.wwdz.ch.wx.dao.UserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;
import com.wwdz.ch.db.domain.User;
@Service
public class UserInfoService {
@Autowired
private DtsUserDao dtsUserDao;
public UserInfo getInfo(Long userId) {
User user = dtsUserDao.findById(userId);
Assert.state(user != null, "用户不存在");
UserInfo userInfo = new UserInfo();
userInfo.setNickName(user.getNickname());
userInfo.setAvatarUrl(user.getAvatar());
return userInfo;
}
}
package com.wwdz.ch.wx.web;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.validation.constraints.NotNull;
import com.wwdz.ch.db.impl.CategoryDaoImpl;
import com.wwdz.ch.db.domain.Category;
import com.wwdz.ch.wx.service.HomeCacheManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.alibaba.fastjson.JSONObject;
import com.wwdz.ch.core.util.ResponseUtil;
/**
* 类目服务
*/
@RestController
@RequestMapping("/wx/catalog")
@Validated
public class WxCatalogController {
private static final Logger logger = LoggerFactory.getLogger(WxCatalogController.class);
@Autowired
private CategoryDaoImpl categoryManager;
/**
* 分类详情
*
* @param id
* 分类类目ID。 如果分类类目ID是空,则选择第一个分类类目。 需要注意,这里分类类目是一级类目
* @return 分类详情
*/
@GetMapping("index")
public Object index(Integer id) {
logger.info("【请求开始】分类详情,请求参数,id:{}", id);
List<Category> l1CatList;
// 当前一级分类目录
Category currentCategory = null;
// 所有一级分类目录
if (null == id || 0 == id) {
l1CatList = categoryManager.queryByLevel(1, 1, 100);
currentCategory = l1CatList.get(0);
} else {
currentCategory = categoryManager.findById(id);
l1CatList = new ArrayList<>();
l1CatList.add(currentCategory);
}
// 当前一级分类目录对应的二级分类目录
List<Category> currentSubCategory = null;
if (null != currentCategory) {
currentSubCategory = categoryManager.queryByPid(currentCategory.getId());
}
Map<String, Object> data = new HashMap<String, Object>();
data.put("categoryList", l1CatList);
data.put("currentCategory", currentCategory);
data.put("currentSubCategory", currentSubCategory);
logger.info("【请求结束】分类详情,响应结果:{}", JSONObject.toJSONString(data));
return ResponseUtil.ok(data);
}
/**
* 所有分类数据
*
* @return 所有分类数据
*/
@GetMapping("all")
public Object queryAll() {
logger.info("【请求开始】所有分类查询...");
// 优先从缓存中读取
if (HomeCacheManager.hasData(HomeCacheManager.CATALOG)) {
return ResponseUtil.ok(HomeCacheManager.getCacheData(HomeCacheManager.CATALOG));
}
// 所有一级分类目录
List<Category> l1CatList = categoryManager.queryByLevel(1, 1, 100);
// 所有子分类列表
Map<Integer, List<Category>> allList = new HashMap<>();
List<Category> sub;
for (Category category : l1CatList) {
sub = categoryManager.queryByPid(category.getId());
allList.put(category.getId(), sub);
}
// 当前一级分类目录
Category currentCategory = l1CatList.get(0);
// 当前一级分类目录对应的二级分类目录
List<Category> currentSubCategory = null;
if (null != currentCategory) {
currentSubCategory = categoryManager.queryByPid(currentCategory.getId());
}
Map<String, Object> data = new HashMap<String, Object>();
data.put("categoryList", l1CatList);
data.put("allList", allList);
data.put("currentCategory", currentCategory);
data.put("currentSubCategory", currentSubCategory);
// 缓存数据
try {
HomeCacheManager.loadData(HomeCacheManager.CATALOG, data);
} catch (Exception e) {
logger.error("所有分类查询出错:缓存分类数据错误:{}", e.getMessage());
e.printStackTrace();
}
logger.info("【请求结束】所有分类查询,响应结果:{}", JSONObject.toJSONString(data));
return ResponseUtil.ok(data);
}
/**
* 当前分类栏目
*
* @param id
* 分类类目ID
* @return 当前分类栏目
*/
@GetMapping("current")
public Object current(@NotNull Integer id) {
logger.info("【请求开始】当前分类栏目查询,id:{}", id);
// 当前分类
Category currentCategory = categoryManager.findById(id);
List<Category> currentSubCategory = categoryManager.queryByPid(currentCategory.getId());
Map<String, Object> data = new HashMap<String, Object>();
data.put("currentCategory", currentCategory);
data.put("currentSubCategory", currentSubCategory);
logger.info("【请求结束】当前分类栏目查询,响应结果:{}", JSONObject.toJSONString(data));
return ResponseUtil.ok(data);
}
}
\ No newline at end of file
package com.wwdz.ch.wx.web; package com.wwdz.ch.wx.web;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageInfo;
import com.wwdz.ch.core.type.Result; import com.wwdz.ch.core.type.Result;
import com.wwdz.ch.core.util.JacksonUtil;
import com.wwdz.ch.core.util.ResponseUtil;
import com.wwdz.ch.db.dao.ItemDao;
import com.wwdz.ch.db.dao.dts.DtsFootprintDao;
import com.wwdz.ch.db.domain.Footprint;
import com.wwdz.ch.db.domain.Item;
import com.wwdz.ch.wx.annotation.LoginUser;
import com.wwdz.ch.wx.entity.request.FootPrintRequestDto; import com.wwdz.ch.wx.entity.request.FootPrintRequestDto;
import com.wwdz.ch.wx.entity.request.KlDataRequestDto; import com.wwdz.ch.wx.entity.request.KlDataRequestDto;
import com.wwdz.ch.wx.service.FootPrintService; import com.wwdz.ch.wx.service.FootPrintService;
...@@ -19,9 +10,13 @@ import org.slf4j.Logger; ...@@ -19,9 +10,13 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.*; import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** /**
...@@ -32,102 +27,9 @@ import java.util.stream.Collectors; ...@@ -32,102 +27,9 @@ import java.util.stream.Collectors;
@Validated @Validated
public class WxFootprintController { public class WxFootprintController {
private static final Logger logger = LoggerFactory.getLogger(WxFootprintController.class); private static final Logger logger = LoggerFactory.getLogger(WxFootprintController.class);
@Autowired
private DtsFootprintDao dtsFootprintDao;
@Autowired
private ItemDao itemDao;
@Autowired @Autowired
private FootPrintService footPrintService; private FootPrintService footPrintService;
/**
* 删除用户足迹
*
* @param userId
* 用户ID
* @param body
* 请求内容, { id: xxx }
* @return 删除操作结果
*/
@PostMapping("delete")
public Object delete(@LoginUser Long userId, @RequestBody String body) {
logger.info("【请求开始】删除用户足迹,请求参数,userId:{},body:{}", userId, body);
if (userId == null) {
logger.error("删除用户足迹:用户未登录!!!");
return ResponseUtil.unlogin();
}
if (body == null) {
return ResponseUtil.badArgument();
}
Long footprintId = JacksonUtil.parseLong(body, "id");
if (footprintId == null) {
return ResponseUtil.badArgument();
}
Footprint footprint = dtsFootprintDao.findById(footprintId);
if (footprint == null) {
return ResponseUtil.badArgumentValue();
}
if (!footprint.getUserId().equals(userId)) {
return ResponseUtil.badArgumentValue();
}
dtsFootprintDao.deleteById(footprintId);
logger.info("【请求结束】删除用户足迹成功!");
return ResponseUtil.ok();
}
/**
* 用户足迹列表
*
* @param page
* 分页页数
* @param size
* 分页大小
* @return 用户足迹列表
*/
@GetMapping("list")
public Object list(@LoginUser Long userId, @RequestParam(defaultValue = "1") Integer page,
@RequestParam(defaultValue = "10") Integer size) {
logger.info("【请求开始】用户足迹列表查询,请求参数,userId:{}", userId);
if (userId == null) {
logger.error("删除用户足迹:用户未登录!!!");
return ResponseUtil.unlogin();
}
List<Footprint> footprintList = dtsFootprintDao.queryByAddTime(userId, page, size);
long count = PageInfo.of(footprintList).getTotal();
int totalPages = (int) Math.ceil((double) count / size);
List<Object> footprintVoList = new ArrayList<>(footprintList.size());
for (Footprint footprint : footprintList) {
Map<String, Object> c = new HashMap<String, Object>();
c.put("id", footprint.getId());
c.put("coinsId", footprint.getItemId());
c.put("addTime", footprint.getAddTime());
Item item = itemDao.findById(footprint.getItemId().longValue());
c.put("name", item.getName());
c.put("retailPrice", item.getPrice());
c.put("image", item.getImages().split(";")[0]);
footprintVoList.add(c);
}
Map<String, Object> result = new HashMap<>();
result.put("footprintList", footprintVoList);
result.put("totalPages", totalPages);
logger.info("【请求结束】添加意见反馈,响应结果:{}", JSONObject.toJSONString(result));
return ResponseUtil.ok(result);
}
@PostMapping("/page") @PostMapping("/page")
public Result page(@RequestBody KlDataRequestDto klDataRequestDto) { public Result page(@RequestBody KlDataRequestDto klDataRequestDto) {
String json = klDataRequestDto.getKl_data(); String json = klDataRequestDto.getKl_data();
......
package com.wwdz.ch.wx.web; package com.wwdz.ch.wx.web;
import java.util.*; import com.alibaba.fastjson.JSONObject;
import java.util.concurrent.ArrayBlockingQueue; import com.wwdz.ch.core.util.ResponseUtil;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.FutureTask;
import java.util.concurrent.RejectedExecutionHandler;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import javax.validation.constraints.NotNull;
import com.wwdz.ch.db.dao.ItemDao; import com.wwdz.ch.db.dao.ItemDao;
import com.wwdz.ch.db.impl.CategoryDaoImpl; import com.wwdz.ch.db.impl.CategoryDaoImpl;
import com.wwdz.ch.wx.annotation.LoginUser; import com.wwdz.ch.wx.annotation.LoginUser;
import com.wwdz.ch.wx.service.HomeCacheManager; import com.wwdz.ch.wx.manager.HomeCacheManager;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -24,8 +14,12 @@ import org.springframework.web.bind.annotation.GetMapping; ...@@ -24,8 +14,12 @@ import org.springframework.web.bind.annotation.GetMapping;
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;
import com.alibaba.fastjson.JSONObject; import javax.validation.constraints.NotNull;
import com.wwdz.ch.core.util.ResponseUtil; import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.*;
/** /**
* 首页服务 * 首页服务
......
package com.wwdz.ch.wx.web; package com.wwdz.ch.wx.web;
import com.alibaba.fastjson.JSONObject;
import com.wwdz.ch.core.type.Result; import com.wwdz.ch.core.type.Result;
import com.wwdz.ch.core.util.ResponseUtil;
import com.wwdz.ch.db.domain.UserAccountObsolete;
import com.wwdz.ch.db.dao.dts.DtsAccountDao;
import com.wwdz.ch.wx.annotation.LoginUser;
import com.wwdz.ch.wx.constant.CacheCodeConstants; import com.wwdz.ch.wx.constant.CacheCodeConstants;
import com.wwdz.ch.wx.entity.request.KlDataRequestDto; import com.wwdz.ch.wx.entity.request.KlDataRequestDto;
import com.wwdz.ch.wx.entity.request.UserRequestDto; import com.wwdz.ch.wx.entity.request.UserRequestDto;
...@@ -18,11 +13,12 @@ import org.slf4j.Logger; ...@@ -18,11 +13,12 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects; import java.util.Objects;
/** /**
...@@ -33,63 +29,10 @@ import java.util.Objects; ...@@ -33,63 +29,10 @@ import java.util.Objects;
@Validated @Validated
public class WxUserController { public class WxUserController {
private static final Logger logger = LoggerFactory.getLogger(WxUserController.class); private static final Logger logger = LoggerFactory.getLogger(WxUserController.class);
@Autowired
private DtsAccountDao accountService;
@Autowired @Autowired
private UserService userService; private UserService userService;
/**
* 用户个人页面数据
* <p>
* @param userId
* 用户ID
* @return 用户个人页面数据
*/
@GetMapping("index")
public Object list(@LoginUser Long userId) {
logger.info("【请求开始】用户个人页面数据,请求参数,userId:{}", userId);
if (userId == null) {
logger.error("用户个人页面数据查询失败:用户未登录!!!");
return ResponseUtil.unlogin();
}
Map<Object, Object> data = new HashMap<Object, Object>();
logger.info("【请求结束】用户个人页面数据,响应结果:{}", JSONObject.toJSONString(data));
return ResponseUtil.ok(data);
}
/**
* 获取用户
* <p>
* @param userId
* 用户ID
* @return 用户个人页面数据
*/
@GetMapping("getSharedUrl")
public Object getSharedUrl(@LoginUser Integer userId) {
logger.info("【请求开始】获取用户推广二维码图片URL,请求参数,userId:{}", userId);
Map<String, Object> data = new HashMap<>();
data.put("userSharedUrl", "");//默认设置没有
if (userId == null) {
logger.error("获取用户推广二维码图片URL:用户未登录!!!");
} else {
UserAccountObsolete userAccount = accountService.findShareUserAccountByUserId(userId);
//如果没申请,数据则不存在,存在数据且审批通过则会形成推广二维码
if (userAccount != null && StringUtils.isNotBlank(userAccount.getShareUrl())) {
data.put("userSharedUrl", userAccount.getShareUrl());
}
}
logger.info("【请求结束】获取用户推广二维码图片URL,响应结果:{}", JSONObject.toJSONString(data));
return ResponseUtil.ok(data);
}
@ApiOperation(value = "微信登录") @ApiOperation(value = "微信登录")
@PostMapping("/loginByWx") @PostMapping("/loginByWx")
public Result loginByWx(@RequestBody KlDataRequestDto klDataRequestDto, HttpServletRequest request) { public Result loginByWx(@RequestBody KlDataRequestDto klDataRequestDto, HttpServletRequest request) {
......
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