FengChaoYu vor 6 Monaten
Ursprung
Commit
b7d832bfed

+ 17 - 0
mall-miniapp-service/src/main/java/com/gree/mall/miniapp/bean/worker/WebsitWorkerBean.java

@@ -0,0 +1,17 @@
+package com.gree.mall.miniapp.bean.worker;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+@Data
+@ApiModel
+public class WebsitWorkerBean {
+
+    @ApiModelProperty(value = "师傅编号")
+    private String workerId;
+
+    @ApiModelProperty(value = "师傅名称")
+    private String workerName;
+
+}

+ 65 - 0
mall-miniapp-service/src/main/java/com/gree/mall/miniapp/controller/worker/WorkerTeamController.java

@@ -0,0 +1,65 @@
+package com.gree.mall.miniapp.controller.worker;
+
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.gree.mall.miniapp.bean.worker.WebsitWorkerBean;
+import com.gree.mall.miniapp.enums.ExamineStatusEnum;
+import com.gree.mall.miniapp.exception.RemoteServiceException;
+import com.gree.mall.miniapp.helper.ResponseHelper;
+import com.gree.mall.miniapp.logic.worker.WorkerTeamLogic;
+import com.gree.mall.miniapp.plus.entity.WorkerTeamApply;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiParam;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.web.bind.annotation.*;
+
+import javax.annotation.Resource;
+import java.util.List;
+
+@Slf4j
+@RestController
+@Api(value = "师傅组别", tags = {"师傅组别"})
+@RequestMapping(value = "/worker/team", produces = "application/json; charset=utf-8")
+public class WorkerTeamController {
+
+    @Resource
+    WorkerTeamLogic workerTeamLogic;
+
+
+    @PostMapping("/page")
+    @ApiOperation(value = "列表")
+    public ResponseHelper<Page<WorkerTeamApply>> page(
+            @ApiParam(value = "页号", required = true) @RequestParam Integer pageNum,
+            @ApiParam(value = "页大小", required = true) @RequestParam Integer pageSize
+
+    ) throws RemoteServiceException {
+        IPage<WorkerTeamApply> page = workerTeamLogic.page(pageNum, pageSize);
+        return ResponseHelper.success(page);
+    }
+
+    @PostMapping("/add")
+    @ApiOperation("新增")
+    public ResponseHelper add(@RequestBody WorkerTeamApply workerTeam) throws RemoteServiceException {
+        workerTeamLogic.add(workerTeam);
+        return ResponseHelper.success();
+    }
+
+    @PostMapping("/confirm")
+    @ApiOperation("确认")
+    public ResponseHelper confirm(
+            @ApiParam(value = "申请id", required = true) @RequestParam String id,
+            @ApiParam(value = "确认状态 OK=同意 FAIL=不同意", required = true) @RequestParam ExamineStatusEnum status) throws RemoteServiceException {
+        workerTeamLogic.confirm(id, status);
+        return ResponseHelper.success();
+    }
+
+    @PostMapping("/query/websit/worker")
+    @ApiOperation("查询网点入驻的师傅")
+    public ResponseHelper<List<WebsitWorkerBean>> queryWebsitWorker (
+            @ApiParam(value = "网点编号", required = true) @RequestParam String websitId
+    ) {
+        List<WebsitWorkerBean> list = workerTeamLogic.queryWebsitWorker(websitId);
+        return ResponseHelper.success(list);
+    }
+}

+ 123 - 0
mall-miniapp-service/src/main/java/com/gree/mall/miniapp/logic/worker/WorkerTeamLogic.java

@@ -0,0 +1,123 @@
+package com.gree.mall.miniapp.logic.worker;
+
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.gree.mall.miniapp.bean.user.CurrentCompanyWechat;
+import com.gree.mall.miniapp.bean.worker.WebsitWorkerBean;
+import com.gree.mall.miniapp.enums.ExamineStatusEnum;
+import com.gree.mall.miniapp.enums.StateEnum;
+import com.gree.mall.miniapp.exception.RemoteServiceException;
+import com.gree.mall.miniapp.logic.common.CommonLogic;
+import com.gree.mall.miniapp.plus.entity.User;
+import com.gree.mall.miniapp.plus.entity.WebsitUser;
+import com.gree.mall.miniapp.plus.entity.WorkerTeam;
+import com.gree.mall.miniapp.plus.entity.WorkerTeamApply;
+import com.gree.mall.miniapp.plus.service.UserService;
+import com.gree.mall.miniapp.plus.service.WebsitUserService;
+import com.gree.mall.miniapp.plus.service.WorkerTeamApplyService;
+import com.gree.mall.miniapp.plus.service.WorkerTeamService;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.Resource;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+@Service
+@Slf4j
+public class WorkerTeamLogic {
+
+    @Resource
+    WorkerTeamService workerTeamService;
+    @Resource
+    WorkerTeamApplyService workerTeamApplyService;
+    @Resource
+    CommonLogic commonLogic;
+    @Resource
+    UserService userService;
+    @Resource
+    WebsitUserService websitUserService;
+
+
+    public IPage<WorkerTeamApply> page(Integer pageNum, Integer pageSize) {
+        CurrentCompanyWechat current = commonLogic.getCurrentCompanyWechat();
+        final Page<WorkerTeamApply> page = workerTeamApplyService.lambdaQuery()
+                .eq(WorkerTeamApply::getCompanyWechatId, current.getUser().getCompanyWechatId())
+                .and(v -> v.eq(WorkerTeamApply::getMasterWorkerId, current.getUser().getWorkerNumber())
+                        .or()
+                        .eq(WorkerTeamApply::getAssistantWorkerId, current.getUser().getWorkerNumber())
+                )
+                .page(new Page<>(pageNum, pageSize));
+        return page;
+    }
+
+    public void add(WorkerTeamApply workerTeam) {
+        CurrentCompanyWechat current = commonLogic.getCurrentCompanyWechat();
+        workerTeam.setCompanyWechatId(current.getUser().getCompanyWechatId())
+                .setCompanyWechatName(current.getUser().getCompanyName());
+        if (StringUtils.isBlank(workerTeam.getWebsitId())) {
+            throw new RemoteServiceException("网点编号不能为空");
+        }
+        if (StringUtils.isBlank(workerTeam.getMasterWorkerId()) || StringUtils.isBlank(workerTeam.getMasterWorkerName())) {
+            workerTeam.setMasterWorkerId(current.getUser().getWorkerNumber())
+                    .setMasterWorkerName(current.getUser().getNickName());
+        }
+        if (StringUtils.isBlank(workerTeam.getAssistantWorkerId()) || StringUtils.isBlank(workerTeam.getAssistantWorkerName())) {
+            throw new RemoteServiceException("组队师傅不能为空");
+        }
+        final Integer count = workerTeamService.lambdaQuery()
+                .eq(WorkerTeam::getWebsitId, workerTeam.getWebsitId())
+                .eq(WorkerTeam::getMasterWorkerId, workerTeam.getMasterWorkerId())
+                .eq(WorkerTeam::getAssistantWorkerId, workerTeam.getAssistantWorkerId())
+                .count();
+        if (count > 0) {
+            throw new RemoteServiceException("已和 " + workerTeam.getAssistantWorkerName() + " 师傅组队");
+        }
+        workerTeam.insert();
+    }
+
+    public void confirm(String id, ExamineStatusEnum status) {
+        CurrentCompanyWechat current = commonLogic.getCurrentCompanyWechat();
+        final WorkerTeamApply apply = workerTeamApplyService.getById(id);
+        if (status.getKey().equals(ExamineStatusEnum.OK.getKey())) {
+            new WorkerTeam()
+                    .setCompanyWechatId(apply.getCompanyWechatId())
+                    .setCompanyWechatName(apply.getCompanyWechatName())
+                    .setWebsitId(apply.getWebsitId())
+                    .setMasterWorkerId(apply.getMasterWorkerId())
+                    .setMasterWorkerName(apply.getMasterWorkerName())
+                    .setAssistantWorkerId(apply.getAssistantWorkerId())
+                    .setAssistantWorkerName(apply.getAssistantWorkerName())
+                    .setStatus(StateEnum.ON.getKey())
+                    .insert();
+        } else {
+            apply.setStatus(status.getKey())
+                    .updateById();
+        }
+    }
+
+    public List<WebsitWorkerBean> queryWebsitWorker(String websitId) {
+        CurrentCompanyWechat current = commonLogic.getCurrentCompanyWechat();
+        final List<WebsitUser> websitUsers = websitUserService.lambdaQuery()
+                .eq(WebsitUser::getCompanyWechatId, current.getUser().getCompanyWechatId())
+                .eq(WebsitUser::getWebsitId, websitId)
+                .eq(WebsitUser::getExamineStatus, ExamineStatusEnum.OK.getKey())
+                .list();
+        final List<User> userList = userService.lambdaQuery()
+                .eq(User::getCompanyWechatId, current.getUser().getCompanyWechatId())
+                .in(User::getUserId, websitUsers.stream().map(WebsitUser::getUserId).collect(Collectors.toList()))
+                .list();
+        final Map<String, String> userMap = userList.stream().collect(Collectors.toMap(User::getWorkerNumber, User::getNickName));
+        List<WebsitWorkerBean> beanList = new ArrayList<>();
+        for (WebsitUser websitUser : websitUsers) {
+            WebsitWorkerBean bean = new WebsitWorkerBean();
+            bean.setWorkerId(websitUser.getWorkerNumber());
+            bean.setWorkerName(userMap.get(websitUser.getWorkerNumber()));
+            beanList.add(bean);
+        }
+        return beanList;
+    }
+}

+ 16 - 0
mall-server-api/src/main/java/com/gree/mall/manager/bean/worker/WebsitWorkerBean.java

@@ -0,0 +1,16 @@
+package com.gree.mall.manager.bean.worker;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+@ApiModel
+@Data
+public class WebsitWorkerBean {
+
+    @ApiModelProperty(value = "师傅编号")
+    private String workerId;
+
+    @ApiModelProperty(value = "师傅名称")
+    private String workerName;
+}

+ 26 - 8
mall-server-api/src/main/java/com/gree/mall/manager/controller/worker/WorkerTeamController.java

@@ -3,7 +3,7 @@ package com.gree.mall.manager.controller.worker;
 import cn.hutool.core.lang.TypeReference;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.gree.mall.manager.annotation.ZfireList;
-import com.gree.mall.manager.bean.admin.AdminWebsitNewBean;
+import com.gree.mall.manager.bean.worker.WebsitWorkerBean;
 import com.gree.mall.manager.bean.worker.WorkerTeamVO;
 import com.gree.mall.manager.exception.RemoteServiceException;
 import com.gree.mall.manager.helper.ResponseHelper;
@@ -13,16 +13,15 @@ import com.gree.mall.manager.zfire.bean.ZfireParamBean;
 import com.gree.mall.manager.zfire.util.FieldUtils;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiParam;
 import lombok.extern.slf4j.Slf4j;
-import me.chanjar.weixin.common.error.WxErrorException;
-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;
 
 import javax.annotation.Resource;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
+import java.util.List;
 
 @Slf4j
 @RestController
@@ -53,15 +52,34 @@ public class WorkerTeamController {
 
     @PostMapping("/add")
     @ApiOperation("新增")
-    public ResponseHelper add(@RequestBody WorkerTeam workerTeam) throws RemoteServiceException, WxErrorException {
+    public ResponseHelper add(@RequestBody WorkerTeam workerTeam) throws RemoteServiceException {
         workerTeamLogic.add(workerTeam);
         return ResponseHelper.success();
     }
 
     @PostMapping("/update")
     @ApiOperation("修改")
-    public ResponseHelper update(@RequestBody WorkerTeam workerTeam) throws RemoteServiceException, WxErrorException {
+    public ResponseHelper update(@RequestBody WorkerTeam workerTeam) throws RemoteServiceException {
         workerTeamLogic.update(workerTeam);
         return ResponseHelper.success();
     }
+
+    @PostMapping("/query/websit/worker")
+    @ApiOperation("查询网点入驻的师傅")
+    public ResponseHelper<List<WebsitWorkerBean>> queryWebsitWorker (
+            @ApiParam(value = "网点编号", required = true) @RequestParam String websitId,
+            @ApiParam(value = "已选师傅编号") @RequestParam(required = false) String workerId
+    ) {
+        List<WebsitWorkerBean> list = workerTeamLogic.queryWebsitWorker(websitId, workerId);
+        return ResponseHelper.success(list);
+    }
+
+    @PostMapping("/import")
+    @ApiOperation(value = "网点管理-导入(下载模板:师傅组队导入模板.xlsx)")
+    public ResponseHelper<String> importData(
+            @RequestPart("file") MultipartFile file
+    ) throws Exception {
+        workerTeamLogic.importData(file);
+        return ResponseHelper.success();
+    }
 }

+ 110 - 0
mall-server-api/src/main/java/com/gree/mall/manager/logic/worker/WorkerTeamLogic.java

@@ -1,20 +1,36 @@
 package com.gree.mall.manager.logic.worker;
 
+import cn.hutool.core.collection.CollectionUtil;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.gree.mall.manager.bean.admin.AdminUserCom;
+import com.gree.mall.manager.bean.worker.WebsitWorkerBean;
 import com.gree.mall.manager.bean.worker.WorkerTeamVO;
 import com.gree.mall.manager.commonmapper.CommonMapper;
+import com.gree.mall.manager.enums.ExamineStatusEnum;
+import com.gree.mall.manager.enums.material.StateEnum;
 import com.gree.mall.manager.exception.RemoteServiceException;
 import com.gree.mall.manager.logic.common.CommonLogic;
+import com.gree.mall.manager.plus.entity.User;
+import com.gree.mall.manager.plus.entity.WebsitUser;
 import com.gree.mall.manager.plus.entity.WorkerTeam;
+import com.gree.mall.manager.plus.service.UserService;
+import com.gree.mall.manager.plus.service.WebsitUserService;
 import com.gree.mall.manager.plus.service.WorkerTeamService;
+import com.gree.mall.manager.utils.CommonUtils;
+import com.gree.mall.manager.utils.excel.ExcelUtils;
 import com.gree.mall.manager.zfire.bean.ZfireParamBean;
 import com.gree.mall.manager.zfire.util.FieldUtils;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.web.multipart.MultipartFile;
+
+import java.io.IOException;
+import java.util.*;
+import java.util.stream.Collectors;
 
 @Service
 @Slf4j
@@ -24,6 +40,8 @@ public class WorkerTeamLogic {
     private final CommonLogic commonLogic;
     private final CommonMapper commonMapper;
     private final WorkerTeamService workerTeamService;
+    private final WebsitUserService websitUserService;
+    private final UserService userService;
 
     public IPage<WorkerTeamVO> list(ZfireParamBean zfireParamBean) {
         AdminUserCom adminUser = commonLogic.getAdminUser();
@@ -75,4 +93,96 @@ public class WorkerTeamLogic {
             throw new RemoteServiceException(workerTeam.getWebsitId() + "已存在一组同样师傅的记录" + workerTeam.getAssistantWorkerId() + "," + workerTeam.getAssistantWorkerId());
         }
     }
+
+    public List<WebsitWorkerBean> queryWebsitWorker(String websitId, String workerId) {
+        AdminUserCom adminUser = commonLogic.getAdminUser();
+        final List<WebsitUser> websitUsers = websitUserService.lambdaQuery()
+                .eq(WebsitUser::getCompanyWechatId, adminUser.getCompanyWechatId())
+                .eq(WebsitUser::getWebsitId, websitId)
+                .ne(StringUtils.isNotBlank(workerId), WebsitUser::getWorkerNumber, workerId)
+                .eq(WebsitUser::getExamineStatus, ExamineStatusEnum.OK.getKey())
+                .list();
+        final List<User> userList = userService.lambdaQuery()
+                .eq(User::getCompanyWechatId, adminUser.getCompanyWechatId())
+                .in(User::getUserId, websitUsers.stream().map(WebsitUser::getUserId).collect(Collectors.toList()))
+                .list();
+        final Map<String, String> userMap = userList.stream().collect(Collectors.toMap(User::getWorkerNumber, User::getNickName));
+        List<WebsitWorkerBean> beanList = new ArrayList<>();
+        for (WebsitUser websitUser : websitUsers) {
+            WebsitWorkerBean bean = new WebsitWorkerBean();
+            bean.setWorkerId(websitUser.getWorkerNumber());
+            bean.setWorkerName(userMap.get(websitUser.getWorkerNumber()));
+            beanList.add(bean);
+        }
+        return beanList;
+    }
+
+    @Transactional
+    public void importData(MultipartFile file) throws IOException {
+        AdminUserCom adminUser = commonLogic.getAdminUser();
+
+        String companyWechatId = Objects.nonNull(adminUser.getAdminCompanyWechat()) ? adminUser.getAdminCompanyWechat().getCompanyWechatId() : null;
+        String companyName = Objects.nonNull(adminUser.getAdminCompanyWechat()) ? adminUser.getAdminCompanyWechat().getCompanyName() : null;
+
+        if (org.apache.commons.lang3.StringUtils.isBlank(companyWechatId)) {
+            throw new RemoteServiceException("商户编号缺失,导入中止");
+        }
+
+        List<Object> objects = ExcelUtils.importExcel(file);
+
+        List<WorkerTeam> workerTeamList = new ArrayList<>();
+        for (int i = 0; i < objects.size(); i++) {
+            int rowIndex = i + 2;
+            List<Object> row = (List<Object>) objects.get(i);
+            CommonUtils.initList2(row, 3);
+            if (Objects.isNull(row.get(0)) || org.apache.commons.lang3.StringUtils.isBlank(row.get(0).toString())) {
+                throw new RemoteServiceException("第" + rowIndex + "行, 网点编号不能为空");
+            }
+            if (Objects.isNull(row.get(1)) || org.apache.commons.lang3.StringUtils.isBlank(row.get(1).toString())) {
+                throw new RemoteServiceException("第" + rowIndex + "行, 大工师傅编号不能为空");
+            }
+            if (Objects.isNull(row.get(2)) || org.apache.commons.lang3.StringUtils.isBlank(row.get(2).toString())) {
+                throw new RemoteServiceException("第" + rowIndex + "行, 小工师傅编号不能为空");
+            }
+            WorkerTeam workerTeam = new WorkerTeam();
+            workerTeam.setCompanyWechatId(companyWechatId)
+                    .setCompanyWechatName(companyName)
+                    .setWebsitId(row.get(0).toString().trim())
+                    .setMasterWorkerId(row.get(0).toString().trim())
+                    .setAssistantWorkerId(row.get(0).toString().trim())
+                    .setStatus(StateEnum.ON.getKey());
+            workerTeamList.add(workerTeam);
+        }
+
+        List<User> userList = userService.lambdaQuery()
+                .eq(User::getCompanyWechatId, companyWechatId)
+                .in(User::getWorkerNumber, workerTeamList.stream()
+                        .map(WorkerTeam::getMasterWorkerId)
+                        .collect(Collectors.toList()))
+                .list();
+
+        List<User> userList2 = userService.lambdaQuery()
+                .eq(User::getCompanyWechatId, companyWechatId)
+                .in(User::getWorkerNumber, workerTeamList.stream()
+                        .map(WorkerTeam::getAssistantWorkerId)
+                        .collect(Collectors.toList()))
+                .list();
+
+        userList.addAll(userList2);
+
+        Map<String, String> userMap = new HashMap<>();
+        if (CollectionUtil.isNotEmpty(userList)) {
+            userMap = userList.stream()
+                    .collect(Collectors.toMap(User::getWorkerNumber, User::getNickName, (key1, key2) -> key2));
+        }
+
+        for (WorkerTeam workerTeam : workerTeamList) {
+            String masterWorkerName = userMap.get(workerTeam.getMasterWorkerId());
+            String assistantWorkerName = userMap.get(workerTeam.getAssistantWorkerId());
+            workerTeam.setMasterWorkerName(masterWorkerName)
+                    .setAssistantWorkerName(assistantWorkerName);
+            this.checkUniqueTeam(workerTeam);
+            workerTeam.insert();
+        }
+    }
 }

BIN
mall-server-api/src/main/resources/template/师傅组队导入模板.xlsx