|
@@ -0,0 +1,78 @@
|
|
|
+package com.gree.mall.manager.logic.worker;
|
|
|
+
|
|
|
+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.WorkerTeamVO;
|
|
|
+import com.gree.mall.manager.commonmapper.CommonMapper;
|
|
|
+import com.gree.mall.manager.exception.RemoteServiceException;
|
|
|
+import com.gree.mall.manager.logic.common.CommonLogic;
|
|
|
+import com.gree.mall.manager.plus.entity.WorkerTeam;
|
|
|
+import com.gree.mall.manager.plus.service.WorkerTeamService;
|
|
|
+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;
|
|
|
+
|
|
|
+@Service
|
|
|
+@Slf4j
|
|
|
+@RequiredArgsConstructor
|
|
|
+public class WorkerTeamLogic {
|
|
|
+
|
|
|
+ private final CommonLogic commonLogic;
|
|
|
+ private final CommonMapper commonMapper;
|
|
|
+ private final WorkerTeamService workerTeamService;
|
|
|
+
|
|
|
+ public IPage<WorkerTeamVO> list(ZfireParamBean zfireParamBean) {
|
|
|
+ AdminUserCom adminUser = commonLogic.getAdminUser();
|
|
|
+ FieldUtils.supplyParam(zfireParamBean, WorkerTeamVO.class, adminUser);
|
|
|
+ return commonMapper.workerTeamPage(new Page(zfireParamBean.getPageNum(), zfireParamBean.getPageSize()), zfireParamBean);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void add(WorkerTeam workerTeam) {
|
|
|
+ AdminUserCom adminUser = commonLogic.getAdminUser();
|
|
|
+ workerTeam.setCompanyWechatId(adminUser.getCompanyWechatId())
|
|
|
+ .setCompanyWechatName(adminUser.getCompanyName());
|
|
|
+ this.validParams(workerTeam);
|
|
|
+ this.checkUniqueTeam(workerTeam);
|
|
|
+
|
|
|
+ workerTeam.insert();
|
|
|
+ }
|
|
|
+
|
|
|
+ public void update(WorkerTeam workerTeam) {
|
|
|
+ AdminUserCom adminUser = commonLogic.getAdminUser();
|
|
|
+ final WorkerTeam old = workerTeamService.getById(workerTeam.getId());
|
|
|
+ workerTeam.setCompanyWechatId(old.getCompanyWechatId())
|
|
|
+ .setCompanyWechatName(old.getCompanyWechatName());
|
|
|
+ this.validParams(workerTeam);
|
|
|
+
|
|
|
+ workerTeam.updateById();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void validParams(WorkerTeam workerTeam) {
|
|
|
+ if (StringUtils.isBlank(workerTeam.getWebsitId())) {
|
|
|
+ throw new RemoteServiceException("所属网点不能为空");
|
|
|
+ }
|
|
|
+ if (StringUtils.isBlank(workerTeam.getMasterWorkerId())) {
|
|
|
+ throw new RemoteServiceException("大工师傅不能为空");
|
|
|
+ }
|
|
|
+ if (StringUtils.isBlank(workerTeam.getAssistantWorkerId())) {
|
|
|
+ throw new RemoteServiceException("小工师傅不能为空");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void checkUniqueTeam(WorkerTeam workerTeam) {
|
|
|
+ final Integer count = workerTeamService.lambdaQuery()
|
|
|
+ .eq(WorkerTeam::getCompanyWechatId, workerTeam.getCompanyWechatId())
|
|
|
+ .eq(WorkerTeam::getWebsitId, workerTeam.getWebsitId())
|
|
|
+ .eq(WorkerTeam::getMasterWorkerId, workerTeam.getMasterWorkerId())
|
|
|
+ .eq(WorkerTeam::getAssistantWorkerId, workerTeam.getAssistantWorkerId())
|
|
|
+ .ne(StringUtils.isNotBlank(workerTeam.getId()), WorkerTeam::getId, workerTeam.getId())
|
|
|
+ .count();
|
|
|
+ if (count > 0) {
|
|
|
+ throw new RemoteServiceException(workerTeam.getWebsitId() + "已存在一组同样师傅的记录" + workerTeam.getAssistantWorkerId() + "," + workerTeam.getAssistantWorkerId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|