|
@@ -5,13 +5,12 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
import com.qs.mp.admin.domain.excel.ChannelExcel;
|
|
|
-import com.qs.mp.admin.domain.excel.UserTicketOrderItemExcel;
|
|
|
+import com.qs.mp.admin.domain.excel.ChannelImportExcel;
|
|
|
import com.qs.mp.admin.domain.param.ChannelQueryParam;
|
|
|
+import com.qs.mp.admin.domain.vo.ChannelImportErrorVO;
|
|
|
import com.qs.mp.admin.domain.vo.TicketCntVO;
|
|
|
import com.qs.mp.admin.service.ITicketService;
|
|
|
import com.qs.mp.channel.domain.Channel;
|
|
|
-import com.qs.mp.channel.domain.ChannelOrder;
|
|
|
-import com.qs.mp.channel.domain.ChannelOrderDetail;
|
|
|
import com.qs.mp.channel.domain.ChannelUserRel;
|
|
|
import com.qs.mp.channel.domain.param.ChannelParam;
|
|
|
import com.qs.mp.channel.domain.param.SaleSiteEditParam;
|
|
@@ -28,10 +27,8 @@ import com.qs.mp.common.core.page.TableDataInfo;
|
|
|
import com.qs.mp.common.enums.BusinessType;
|
|
|
import com.qs.mp.common.enums.ChannelRoleEnum;
|
|
|
import com.qs.mp.common.enums.ErrorCodeEnum;
|
|
|
-import com.qs.mp.common.enums.UserTicketOrderStatusEnum;
|
|
|
-import com.qs.mp.system.domain.SysUser;
|
|
|
+import com.qs.mp.common.exception.ServiceException;
|
|
|
import com.qs.mp.system.service.ISysUserService;
|
|
|
-import com.qs.mp.user.domain.UserTicketOrder;
|
|
|
import com.qs.mp.user.service.IUserTicketOrderService;
|
|
|
import com.qs.mp.utils.ExcelUtil;
|
|
|
import com.qs.mp.web.controller.common.BaseApiController;
|
|
@@ -41,23 +38,18 @@ import io.swagger.annotations.ApiResponse;
|
|
|
import io.swagger.annotations.ApiResponses;
|
|
|
import ma.glasnost.orika.MapperFacade;
|
|
|
|
|
|
-import java.math.BigDecimal;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
import java.util.Objects;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.security.access.prepost.PreAuthorize;
|
|
|
-import org.springframework.stereotype.Component;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
-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 org.springframework.web.bind.annotation.*;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
/**
|
|
|
* @auther zhongcp
|
|
@@ -174,6 +166,108 @@ public class SaleSiteMgrController extends BaseApiController {
|
|
|
return "";
|
|
|
}
|
|
|
|
|
|
+ @PostMapping("/template/download")
|
|
|
+ @ApiOperation("下载门店导入模板")
|
|
|
+ public AjaxResult siteTemplateDownLoad() {
|
|
|
+ ExcelUtil<ChannelImportExcel> excelUtil = new ExcelUtil<>(ChannelImportExcel.class);
|
|
|
+ return excelUtil.exportExcel(null, "门店导入模板", false);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @PostMapping("/import")
|
|
|
+ @ApiOperation("导入门店信息")
|
|
|
+ @PreAuthorize("@ss.hasPermi('business::salesite:import')")
|
|
|
+ public AjaxResult saleSiteImport(@RequestParam("file") MultipartFile file) {
|
|
|
+
|
|
|
+ try {
|
|
|
+ // 解析excel数据
|
|
|
+ ExcelUtil<ChannelImportExcel> excelUtil = new ExcelUtil<>(ChannelImportExcel.class);
|
|
|
+ List<ChannelImportExcel> siteList = excelUtil.importExcel(file.getInputStream());
|
|
|
+ if (CollectionUtils.isEmpty(siteList)) {
|
|
|
+ return AjaxResult.error("导入数据为空");
|
|
|
+ }
|
|
|
+ // 校验导入门店手机号是否重复
|
|
|
+ List<String> mobileList = new ArrayList<>();
|
|
|
+ for (ChannelImportExcel channelImportExcel : siteList) {
|
|
|
+ if (StringUtils.isEmpty(channelImportExcel.getMobile())) {
|
|
|
+ return AjaxResult.error("导入的手机号存在空值");
|
|
|
+ }
|
|
|
+ if (StringUtils.isEmpty(channelImportExcel.getName())) {
|
|
|
+ return AjaxResult.error("导入的门店名称存在空值");
|
|
|
+ }
|
|
|
+ if (StringUtils.isEmpty(channelImportExcel.getParentsName())) {
|
|
|
+ return AjaxResult.error("导入的上级渠道为空");
|
|
|
+ }
|
|
|
+ if (channelImportExcel.getCommRate() == null) {
|
|
|
+ return AjaxResult.error("导入的佣金比例为空");
|
|
|
+ }
|
|
|
+ mobileList.add(channelImportExcel.getMobile());
|
|
|
+ }
|
|
|
+ long count = mobileList.stream().distinct().count();
|
|
|
+ if (siteList.size() != count) {
|
|
|
+ return AjaxResult.error("导入的手机号存在重复值");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 该账号是否已注册 门店是否已注册
|
|
|
+// checkIsRegister(mobileList);
|
|
|
+
|
|
|
+ // 门店名称不能重复
|
|
|
+ long nameCount = siteList.stream().map(ChannelImportExcel::getName).distinct().count();
|
|
|
+ if (siteList.size() != nameCount) {
|
|
|
+ return AjaxResult.error("导入的门店名称存在重复");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 判断上级渠道是否存在
|
|
|
+ List<ChannelImportErrorVO> channelImportErrorVOS = new ArrayList<>();
|
|
|
+ siteList.forEach(importExcel -> {
|
|
|
+ ChannelImportErrorVO importErrorVO = mapperFacade.map(importExcel, ChannelImportErrorVO.class);
|
|
|
+ Channel parentsChannel = channelService.getOne(new QueryWrapper<Channel>().eq("name", importExcel.getParentsName()));
|
|
|
+ if (parentsChannel == null) {
|
|
|
+ importErrorVO.setErrorReason("上级渠道不存在");
|
|
|
+ } else {
|
|
|
+ if (importExcel.getCommRate().compareTo(parentsChannel.getCommRate()) > 0) {
|
|
|
+ importErrorVO.setErrorReason("佣金比例大于上级渠道");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Channel site = channelService.getOne(
|
|
|
+ new LambdaQueryWrapper<Channel>().eq(Channel::getMobile, importExcel.getMobile()));
|
|
|
+ if (site != null) {
|
|
|
+ importErrorVO.setErrorReason(importErrorVO.getErrorReason() == null ? "" : importErrorVO.getErrorReason() + "/" + "门店已被注册");
|
|
|
+ }
|
|
|
+ if (UserConstants.NOT_UNIQUE.equals(userService.checkUserNameUnique(importExcel.getMobile()))) {
|
|
|
+ importErrorVO.setErrorReason(importErrorVO.getErrorReason() == null ? "" : importErrorVO.getErrorReason() + "/" + "手机号已被注册");
|
|
|
+ }
|
|
|
+ if (importErrorVO.getErrorReason() != null) {
|
|
|
+ channelImportErrorVOS.add(importErrorVO);
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ if (!CollectionUtils.isEmpty(channelImportErrorVOS)) {
|
|
|
+ return AjaxResult.error("导入信息有误", channelImportErrorVOS);
|
|
|
+ }
|
|
|
+ // 导入门店 并注册账号
|
|
|
+ channelService.importSite(siteList);
|
|
|
+ } catch (Exception e) {
|
|
|
+ logger.error(e.getMessage());
|
|
|
+ return AjaxResult.error(e.getMessage());
|
|
|
+ }
|
|
|
+ return AjaxResult.success();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void checkIsRegister(List<String> mobileList) {
|
|
|
+ mobileList.forEach(mobile -> {
|
|
|
+ int mobileCount = channelService.count(
|
|
|
+ new LambdaQueryWrapper<Channel>().eq(Channel::getMobile, mobile));
|
|
|
+ if (mobileCount > 0) {
|
|
|
+ throw new ServiceException("手机号码" + mobile + "已注册!");
|
|
|
+ }
|
|
|
+ if (UserConstants.NOT_UNIQUE.equals(userService.checkUserNameUnique(mobile))) {
|
|
|
+ throw new ServiceException("手机号码" + mobile + "已注册!");
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
@PostMapping("/export")
|
|
|
@PreAuthorize("@ss.hasPermi('business:salesite:export')")
|
|
|
@ApiOperation("导出经销商信息")
|