|
- package com.simple.controller;
-
- import com.alibaba.fastjson.JSON;
- import com.alibaba.fastjson.JSONObject;
- import com.github.pagehelper.PageInfo;
- import com.simple.common.Result;
- import com.simple.common.ResultData;
- import com.simple.domain.dto.WxCUserBasicInfoDto;
- import com.simple.domain.po.*;
- import com.simple.exception.MallinkException;
- import com.simple.service.*;
- import io.swagger.annotations.Api;
- import io.swagger.annotations.ApiImplicitParam;
- import io.swagger.annotations.ApiImplicitParams;
- import io.swagger.annotations.ApiOperation;
- import org.apache.commons.lang3.StringUtils;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.transaction.annotation.Transactional;
- import org.springframework.web.bind.annotation.*;
- import org.springframework.web.multipart.MultipartFile;
-
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.Map;
-
- @RestController
- @RequestMapping("wxCUserBasicInfo")
- @Api(description = "会员管理相关接口")
- public class WxCUserBasicInfoController extends BaseController {
- private final Logger logger = LoggerFactory.getLogger(this.getClass());
-
- @Autowired
- private WxCUserBasicInfoService wxCUserBasicInfoService;
-
- @Autowired
- private WxCUserTagsService wxCUserTagsService;
-
- @Autowired
- private WxTagsService wxTagsService;
-
- @Autowired
- private WxCUserService wxCUserService;
-
- @Autowired
- private WxCouponOrderService wxCouponOrderService;
-
- @Autowired
- private WxCouponService wxCouponService;
-
- @ApiOperation("分页列表接口")
- @GetMapping("list")
- @ApiImplicitParams({
- @ApiImplicitParam(name = "pageNum", value = "页数", dataType = "int", paramType = "query", required = true),
- @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", paramType = "query", required = true)})
- public ResultData list(@ModelAttribute WxCUserBasicInfo wxCUserBasicInfo, Integer pageNum, Integer pageSize) {
- if (null == wxCUserBasicInfo) wxCUserBasicInfo = new WxCUserBasicInfo();
- String tenantId = getTenantId();
- wxCUserBasicInfo.setTenantId(tenantId);
- PageInfo<WxCUserBasicInfo> page = wxCUserBasicInfoService.listAsPage(wxCUserBasicInfo, pageNum, pageSize);
- return new ResultData(page);
- }
-
-
- private void createUserBasicInfo(WxCUser wxCUser) {
- String phone = wxCUser.getPhone();
- if (phone != null && phone.contains("*")) {
- phone = wxCUser.getVerifyCodePhone();
- }
- if (StringUtils.isBlank(phone))
- return;
- WxCUserBasicInfo wxCUserBasicInfo = new WxCUserBasicInfo();
- wxCUserBasicInfo.setId(wxCUser.getId());
- wxCUserBasicInfo.setPhone(wxCUser.getPhone());
- wxCUserBasicInfo.setTenantId(wxCUser.getTenantId());
- wxCUserBasicInfo.setNickName(wxCUser.getNickName());
- wxCUserBasicInfoService.saveOrUpdate(wxCUserBasicInfo);
-
- }
-
- // @ApiOperation("新增接口")
- // @PostMapping("add")
- // public ResultData add(@RequestBody WxCUserBasicInfo wxCUserBasicInfo) {
- // //Assert.notNull(wxCUserBasicInfo.getName(), "角色名不能为空");
- // //Assert.isTrue(!checkUnique(sysRole.getName(), null), "重复的角色名");
- // wxCUserBasicInfoService.saveOrUpdate(wxCUserBasicInfo);
- // return new ResultData();
- // }
-
- @ApiOperation("根据id更新接口")
- @PostMapping("update")
- public ResultData update(@RequestBody WxCUserBasicInfo wxCUserBasicInfo) {
- WxCUserBasicInfo info = wxCUserBasicInfoService.getById(wxCUserBasicInfo.getId());
- wxCUserBasicInfo.setTenantId(getTenantId());
- if (StringUtils.isNotBlank(wxCUserBasicInfo.getTagIds())) {
- WxCUserTags record = new WxCUserTags();
- record.setUserId(info.getId());
- record.setTenantId(getTenantId());
- PageInfo<WxCUserTags> page = wxCUserTagsService.listAsPage(record, 1, 1);
- if (page.getSize() > 0) {
- WxCUserTags t = page.getList().get(0);
- record.setId(t.getId());
- }
- String tags = wxCUserBasicInfo.getTagIds();
- List<Long> tagIdList = new ArrayList<>();
- for (String t : tags.split(",")) {
- tagIdList.add(Long.valueOf(t));
- }
- record.setTags(JSON.toJSONString(tagIdList));
- wxCUserTagsService.saveOrUpdate(record);
- wxCUserBasicInfo.setTagId(record.getId());
- }
- wxCUserBasicInfoService.saveOrUpdate(wxCUserBasicInfo);
- return new ResultData();
- }
-
- @ApiOperation("根据id删除接口")
- @GetMapping("/del")
- @ApiImplicitParam(name = "id", value = "id", dataType = "Long", paramType = "query", required = true)
- public ResultData delete(Long id) {
- wxCUserBasicInfoService.deleteById(id);
- return new ResultData(Result.SUCCESS, "删除成功", null);
- }
-
- @ApiOperation("根据id查询接口")
- @GetMapping("/findById")
- @ApiImplicitParam(name = "id", value = "id", dataType = "Long", paramType = "query", required = true)
- public ResultData findById(Long id) {
- WxCUserBasicInfo info = wxCUserBasicInfoService.getById(id);
- if (info != null) {
- if (info.getTagId() != null) {
- WxCUserTags uTag = wxCUserTagsService.getById(info.getTagId());
- if (StringUtils.isNotBlank(uTag.getTags())) {
- List<Long> ids = JSONObject.parseArray(uTag.getTags(), Long.class);
- WxTags wxTags = new WxTags();
- wxTags.setIds(ids);
- PageInfo<WxTags> page = wxTagsService.listAsPage(wxTags, 1, 5000);
- String tagNames = "";
- String tagIds = "";
- List<Long> tagIdList = new ArrayList<>();
- for (WxTags wt : page.getList()) {
- tagNames += wt.getName() + "/";
- tagIds += wt.getId() + ",";
- tagIdList.add(wt.getId());
- }
- if (StringUtils.isNotBlank(tagNames)) {
- info.setTagNames(tagNames.substring(0, tagNames.length() - 1));
- }
- if (StringUtils.isNoneBlank(tagIds)) {
- info.setTagIds(tagIds.substring(0, tagIds.length() - 1));
- }
- long count = wxCUserTagsService.findCountByTag(tagIdList);
- info.setCount(count);
- }
- }
- } else {
- info = new WxCUserBasicInfo();
- info.setId(id);
- WxCUser user = wxCUserService.getById(id);
- if (user != null) {
- info.setTenantId(user.getTenantId());
- info.setPhone(user.getPhone());
- info.setSex(user.getGender());
- }
- }
- return new ResultData(Result.SUCCESS, "查询成功", info);
- }
-
- @ApiOperation("根据userId查询交易记录接口")
- @GetMapping("/findOrderCouponByUserId")
- @ApiImplicitParam(name = "userId", value = "userId", dataType = "Long", paramType = "query", required = true)
- public ResultData findOrderCouponByUserId(Long userId, Integer pageNum, Integer pageSize) {
- WxCouponOrder corder = new WxCouponOrder();
- corder.setCUserId(userId);
- corder.setTenantId(getTenantId());
- PageInfo<WxCouponOrder> page = wxCouponOrderService.listAsPage(corder, pageNum, pageSize);
- if (page.getSize() > 0) {
- List<WxCouponOrder> list = page.getList();
- for (WxCouponOrder c : list) {
- WxCoupon coupon = wxCouponService.getById(c.getCouponId());
- c.setCouponName(coupon.getTitle());
- c.setSalePrice(coupon.getPrice());
- }
- }
- return new ResultData(Result.SUCCESS, "查询成功", page);
- }
-
- @RequestMapping("/exportData")
- public void exportData(HttpServletRequest request, HttpServletResponse response){
-
- wxCUserBasicInfoService.exportData(request,response,getTenantId());
-
- }
-
- @RequestMapping("/exportTemplate")
- public void exportTemplate(HttpServletRequest request, HttpServletResponse response){
-
- wxCUserBasicInfoService.exportTemplate(request,response,getTenantId());
-
- }
-
- @Transactional
- @RequestMapping("/importTemplate")
- public ResultData importTemplate(@RequestParam("file") MultipartFile file){
- if (file.isEmpty()) {
- throw new MallinkException(500,"上传文件不能为空");
- }
- return wxCUserBasicInfoService.importTemplate(file,getTenantId());
- }
-
-
- }
|