|
@@ -0,0 +1,149 @@
|
|
|
+package com.gree.mall.manager.logic.workorder;
|
|
|
+
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
+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.workorder.PgAppraiseCategoryVO;
|
|
|
+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.PgAppraiseCategory;
|
|
|
+import com.gree.mall.manager.plus.entity.PgAppraiseConfig;
|
|
|
+import com.gree.mall.manager.plus.service.PgAppraiseApplyService;
|
|
|
+import com.gree.mall.manager.plus.service.PgAppraiseCategoryService;
|
|
|
+import com.gree.mall.manager.plus.service.PgAppraiseConfigService;
|
|
|
+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.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+@Slf4j
|
|
|
+@Service
|
|
|
+@RequiredArgsConstructor
|
|
|
+public class AppraiseRelaLogic {
|
|
|
+ private final CommonLogic commonLogic;
|
|
|
+ private final CommonMapper commonMapper;
|
|
|
+ private final PgAppraiseConfigService pgAppraiseConfigService;
|
|
|
+ private final PgAppraiseCategoryService pgAppraiseCategoryService;
|
|
|
+ private final PgAppraiseApplyService pgAppraiseApplyService;
|
|
|
+
|
|
|
+ public List<PgAppraiseConfig> configList() {
|
|
|
+ AdminUserCom adminUser = commonLogic.getAdminUser();
|
|
|
+ return pgAppraiseConfigService.lambdaQuery()
|
|
|
+ .eq(PgAppraiseConfig::getCompanyWechatId, adminUser.getCompanyWechatId())
|
|
|
+ .list();
|
|
|
+ }
|
|
|
+
|
|
|
+ public IPage<PgAppraiseCategoryVO> categoryList(ZfireParamBean zfireParamBean) {
|
|
|
+ AdminUserCom adminUser = commonLogic.getAdminUser();
|
|
|
+ FieldUtils.supplyParam(zfireParamBean, PgAppraiseCategoryVO.class, adminUser);
|
|
|
+ return commonMapper.appraiseCategoryList(new Page(zfireParamBean.getPageNum(), zfireParamBean.getPageSize()), zfireParamBean);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional
|
|
|
+ public void categorySave(PgAppraiseCategory category) {
|
|
|
+ AdminUserCom adminUser = commonLogic.getAdminUser();
|
|
|
+ boolean isAdd = StringUtils.isBlank(category.getId());
|
|
|
+
|
|
|
+ category.setCompanyWechatId(adminUser.getCompanyWechatId())
|
|
|
+ .setCompanyWechatName(adminUser.getCompanyName());
|
|
|
+
|
|
|
+ if (!isAdd) {
|
|
|
+ final PgAppraiseCategory old = pgAppraiseCategoryService.getById(category.getId());
|
|
|
+ category.setCompanyWechatId(old.getCompanyWechatId())
|
|
|
+ .setCompanyWechatName(old.getCompanyWechatName());
|
|
|
+ }
|
|
|
+
|
|
|
+ String preStr = "大类";
|
|
|
+ if (StringUtils.isNotBlank(category.getParentId()) && !category.getParentId().equals("0")) {
|
|
|
+ preStr = "小类";
|
|
|
+ }
|
|
|
+
|
|
|
+ if (StringUtils.isBlank(category.getName())) {
|
|
|
+ throw new RemoteServiceException(preStr + "名称不能为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ final Integer count = pgAppraiseCategoryService.lambdaQuery()
|
|
|
+ .eq(PgAppraiseCategory::getCompanyWechatId, category.getCompanyWechatId())
|
|
|
+ .eq(PgAppraiseCategory::getName, category.getName())
|
|
|
+ .ne(!isAdd, PgAppraiseCategory::getId, category.getId())
|
|
|
+ .count();
|
|
|
+ if (count > 0) {
|
|
|
+ throw new RemoteServiceException("名称重复存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (isAdd) {
|
|
|
+ category.insert();
|
|
|
+ } else {
|
|
|
+ category.updateById();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional
|
|
|
+ public void categoryImportData(MultipartFile file) throws Exception {
|
|
|
+ AdminUserCom adminUser = commonLogic.getAdminUser();
|
|
|
+ if (adminUser.getType() == 2) {
|
|
|
+ throw new RemoteServiceException("平台账号禁止操作");
|
|
|
+ }
|
|
|
+
|
|
|
+ String companyWechatId = adminUser.getAdminCompanyWechat().getCompanyWechatId();
|
|
|
+ String companyName = adminUser.getAdminCompanyWechat().getCompanyName();
|
|
|
+
|
|
|
+ List<Object> objects = ExcelUtils.importExcel(file);
|
|
|
+ Map<String, Set<String>> importMap = new HashMap<>();
|
|
|
+
|
|
|
+ for (int i = 0; i < objects.size(); i++) {
|
|
|
+ List<Object> row = (List<Object>) objects.get(i);
|
|
|
+ row = CommonUtils.initList2(row, 2);
|
|
|
+
|
|
|
+ if (Objects.isNull(row.get(0))) {
|
|
|
+ throw new RemoteServiceException("第" + (i + 1) + "行, 大类名称不能为空");
|
|
|
+ }
|
|
|
+ if (Objects.isNull(row.get(1))) {
|
|
|
+ throw new RemoteServiceException("第" + (i + 1) + "行, 小类名称不能为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ String parentName = (String) row.get(0);
|
|
|
+ String subName = (String) row.get(1);
|
|
|
+
|
|
|
+ if (importMap.containsKey(StrUtil.trim(parentName))) {
|
|
|
+ importMap.get(StrUtil.trim(parentName)).add(StrUtil.trim(subName));
|
|
|
+ } else {
|
|
|
+ importMap.put(StrUtil.trim(parentName), new HashSet<String>() {{ this.add(StrUtil.trim(subName)); }});
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ final List<PgAppraiseCategory> categoryList = pgAppraiseCategoryService.lambdaQuery()
|
|
|
+ .eq(PgAppraiseCategory::getCompanyWechatId, companyWechatId)
|
|
|
+ .eq(PgAppraiseCategory::getParentId, "0")
|
|
|
+ .list();
|
|
|
+
|
|
|
+ final Map<String, String> parentMap = categoryList.stream()
|
|
|
+ .collect(Collectors.toMap(PgAppraiseCategory::getName, PgAppraiseCategory::getId));
|
|
|
+
|
|
|
+ for (Map.Entry<String, Set<String>> entry : importMap.entrySet()) {
|
|
|
+ if (!parentMap.containsKey(entry.getKey())) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ final String parentId = parentMap.get(entry.getKey());
|
|
|
+ for (String name : entry.getValue()) {
|
|
|
+ PgAppraiseCategory category = new PgAppraiseCategory();
|
|
|
+ category.setCompanyWechatId(companyWechatId)
|
|
|
+ .setCompanyWechatName(companyName)
|
|
|
+ .setParentId(parentId)
|
|
|
+ .setName(name);
|
|
|
+ this.categorySave(category);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|