Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 
 
 

216 rader
8.7 KiB

  1. package com.simple.controller;
  2. import com.alibaba.fastjson.JSON;
  3. import com.alibaba.fastjson.JSONObject;
  4. import com.github.pagehelper.PageInfo;
  5. import com.simple.common.Result;
  6. import com.simple.common.ResultData;
  7. import com.simple.domain.dto.WxCUserBasicInfoDto;
  8. import com.simple.domain.po.*;
  9. import com.simple.exception.MallinkException;
  10. import com.simple.service.*;
  11. import io.swagger.annotations.Api;
  12. import io.swagger.annotations.ApiImplicitParam;
  13. import io.swagger.annotations.ApiImplicitParams;
  14. import io.swagger.annotations.ApiOperation;
  15. import org.apache.commons.lang3.StringUtils;
  16. import org.slf4j.Logger;
  17. import org.slf4j.LoggerFactory;
  18. import org.springframework.beans.factory.annotation.Autowired;
  19. import org.springframework.transaction.annotation.Transactional;
  20. import org.springframework.web.bind.annotation.*;
  21. import org.springframework.web.multipart.MultipartFile;
  22. import javax.servlet.http.HttpServletRequest;
  23. import javax.servlet.http.HttpServletResponse;
  24. import java.util.ArrayList;
  25. import java.util.List;
  26. import java.util.Map;
  27. @RestController
  28. @RequestMapping("wxCUserBasicInfo")
  29. @Api(description = "会员管理相关接口")
  30. public class WxCUserBasicInfoController extends BaseController {
  31. private final Logger logger = LoggerFactory.getLogger(this.getClass());
  32. @Autowired
  33. private WxCUserBasicInfoService wxCUserBasicInfoService;
  34. @Autowired
  35. private WxCUserTagsService wxCUserTagsService;
  36. @Autowired
  37. private WxTagsService wxTagsService;
  38. @Autowired
  39. private WxCUserService wxCUserService;
  40. @Autowired
  41. private WxCouponOrderService wxCouponOrderService;
  42. @Autowired
  43. private WxCouponService wxCouponService;
  44. @ApiOperation("分页列表接口")
  45. @GetMapping("list")
  46. @ApiImplicitParams({
  47. @ApiImplicitParam(name = "pageNum", value = "页数", dataType = "int", paramType = "query", required = true),
  48. @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", paramType = "query", required = true)})
  49. public ResultData list(@ModelAttribute WxCUserBasicInfo wxCUserBasicInfo, Integer pageNum, Integer pageSize) {
  50. if (null == wxCUserBasicInfo) wxCUserBasicInfo = new WxCUserBasicInfo();
  51. String tenantId = getTenantId();
  52. wxCUserBasicInfo.setTenantId(tenantId);
  53. PageInfo<WxCUserBasicInfo> page = wxCUserBasicInfoService.listAsPage(wxCUserBasicInfo, pageNum, pageSize);
  54. return new ResultData(page);
  55. }
  56. private void createUserBasicInfo(WxCUser wxCUser) {
  57. String phone = wxCUser.getPhone();
  58. if (phone != null && phone.contains("*")) {
  59. phone = wxCUser.getVerifyCodePhone();
  60. }
  61. if (StringUtils.isBlank(phone))
  62. return;
  63. WxCUserBasicInfo wxCUserBasicInfo = new WxCUserBasicInfo();
  64. wxCUserBasicInfo.setId(wxCUser.getId());
  65. wxCUserBasicInfo.setPhone(wxCUser.getPhone());
  66. wxCUserBasicInfo.setTenantId(wxCUser.getTenantId());
  67. wxCUserBasicInfo.setNickName(wxCUser.getNickName());
  68. wxCUserBasicInfoService.saveOrUpdate(wxCUserBasicInfo);
  69. }
  70. // @ApiOperation("新增接口")
  71. // @PostMapping("add")
  72. // public ResultData add(@RequestBody WxCUserBasicInfo wxCUserBasicInfo) {
  73. // //Assert.notNull(wxCUserBasicInfo.getName(), "角色名不能为空");
  74. // //Assert.isTrue(!checkUnique(sysRole.getName(), null), "重复的角色名");
  75. // wxCUserBasicInfoService.saveOrUpdate(wxCUserBasicInfo);
  76. // return new ResultData();
  77. // }
  78. @ApiOperation("根据id更新接口")
  79. @PostMapping("update")
  80. public ResultData update(@RequestBody WxCUserBasicInfo wxCUserBasicInfo) {
  81. WxCUserBasicInfo info = wxCUserBasicInfoService.getById(wxCUserBasicInfo.getId());
  82. wxCUserBasicInfo.setTenantId(getTenantId());
  83. if (StringUtils.isNotBlank(wxCUserBasicInfo.getTagIds())) {
  84. WxCUserTags record = new WxCUserTags();
  85. record.setUserId(info.getId());
  86. record.setTenantId(getTenantId());
  87. PageInfo<WxCUserTags> page = wxCUserTagsService.listAsPage(record, 1, 1);
  88. if (page.getSize() > 0) {
  89. WxCUserTags t = page.getList().get(0);
  90. record.setId(t.getId());
  91. }
  92. String tags = wxCUserBasicInfo.getTagIds();
  93. List<Long> tagIdList = new ArrayList<>();
  94. for (String t : tags.split(",")) {
  95. tagIdList.add(Long.valueOf(t));
  96. }
  97. record.setTags(JSON.toJSONString(tagIdList));
  98. wxCUserTagsService.saveOrUpdate(record);
  99. wxCUserBasicInfo.setTagId(record.getId());
  100. }
  101. wxCUserBasicInfoService.saveOrUpdate(wxCUserBasicInfo);
  102. return new ResultData();
  103. }
  104. @ApiOperation("根据id删除接口")
  105. @GetMapping("/del")
  106. @ApiImplicitParam(name = "id", value = "id", dataType = "Long", paramType = "query", required = true)
  107. public ResultData delete(Long id) {
  108. wxCUserBasicInfoService.deleteById(id);
  109. return new ResultData(Result.SUCCESS, "删除成功", null);
  110. }
  111. @ApiOperation("根据id查询接口")
  112. @GetMapping("/findById")
  113. @ApiImplicitParam(name = "id", value = "id", dataType = "Long", paramType = "query", required = true)
  114. public ResultData findById(Long id) {
  115. WxCUserBasicInfo info = wxCUserBasicInfoService.getById(id);
  116. if (info != null) {
  117. if (info.getTagId() != null) {
  118. WxCUserTags uTag = wxCUserTagsService.getById(info.getTagId());
  119. if (StringUtils.isNotBlank(uTag.getTags())) {
  120. List<Long> ids = JSONObject.parseArray(uTag.getTags(), Long.class);
  121. WxTags wxTags = new WxTags();
  122. wxTags.setIds(ids);
  123. PageInfo<WxTags> page = wxTagsService.listAsPage(wxTags, 1, 5000);
  124. String tagNames = "";
  125. String tagIds = "";
  126. List<Long> tagIdList = new ArrayList<>();
  127. for (WxTags wt : page.getList()) {
  128. tagNames += wt.getName() + "/";
  129. tagIds += wt.getId() + ",";
  130. tagIdList.add(wt.getId());
  131. }
  132. if (StringUtils.isNotBlank(tagNames)) {
  133. info.setTagNames(tagNames.substring(0, tagNames.length() - 1));
  134. }
  135. if (StringUtils.isNoneBlank(tagIds)) {
  136. info.setTagIds(tagIds.substring(0, tagIds.length() - 1));
  137. }
  138. long count = wxCUserTagsService.findCountByTag(tagIdList);
  139. info.setCount(count);
  140. }
  141. }
  142. } else {
  143. info = new WxCUserBasicInfo();
  144. info.setId(id);
  145. WxCUser user = wxCUserService.getById(id);
  146. if (user != null) {
  147. info.setTenantId(user.getTenantId());
  148. info.setPhone(user.getPhone());
  149. info.setSex(user.getGender());
  150. }
  151. }
  152. return new ResultData(Result.SUCCESS, "查询成功", info);
  153. }
  154. @ApiOperation("根据userId查询交易记录接口")
  155. @GetMapping("/findOrderCouponByUserId")
  156. @ApiImplicitParam(name = "userId", value = "userId", dataType = "Long", paramType = "query", required = true)
  157. public ResultData findOrderCouponByUserId(Long userId, Integer pageNum, Integer pageSize) {
  158. WxCouponOrder corder = new WxCouponOrder();
  159. corder.setCUserId(userId);
  160. corder.setTenantId(getTenantId());
  161. PageInfo<WxCouponOrder> page = wxCouponOrderService.listAsPage(corder, pageNum, pageSize);
  162. if (page.getSize() > 0) {
  163. List<WxCouponOrder> list = page.getList();
  164. for (WxCouponOrder c : list) {
  165. WxCoupon coupon = wxCouponService.getById(c.getCouponId());
  166. c.setCouponName(coupon.getTitle());
  167. c.setSalePrice(coupon.getPrice());
  168. }
  169. }
  170. return new ResultData(Result.SUCCESS, "查询成功", page);
  171. }
  172. @RequestMapping("/exportData")
  173. public void exportData(HttpServletRequest request, HttpServletResponse response){
  174. wxCUserBasicInfoService.exportData(request,response,getTenantId());
  175. }
  176. @RequestMapping("/exportTemplate")
  177. public void exportTemplate(HttpServletRequest request, HttpServletResponse response){
  178. wxCUserBasicInfoService.exportTemplate(request,response,getTenantId());
  179. }
  180. @Transactional
  181. @RequestMapping("/importTemplate")
  182. public ResultData importTemplate(@RequestParam("file") MultipartFile file){
  183. if (file.isEmpty()) {
  184. throw new MallinkException(500,"上传文件不能为空");
  185. }
  186. return wxCUserBasicInfoService.importTemplate(file,getTenantId());
  187. }
  188. }