From c61e6f0b4c128247b81d48f1ccbd999d439d2544 Mon Sep 17 00:00:00 2001
From: nidapeng <jp@doumee.com>
Date: 星期一, 22 四月 2024 11:30:52 +0800
Subject: [PATCH] 最新版本
---
server/dmvisit_service/src/main/java/com/doumee/service/business/impl/CompanyServiceImpl.java | 126 ++++++++++++++++++++++++++++++++++++------
1 files changed, 108 insertions(+), 18 deletions(-)
diff --git a/server/dmvisit_service/src/main/java/com/doumee/service/business/impl/CompanyServiceImpl.java b/server/dmvisit_service/src/main/java/com/doumee/service/business/impl/CompanyServiceImpl.java
index 62c0042..19b9e48 100644
--- a/server/dmvisit_service/src/main/java/com/doumee/service/business/impl/CompanyServiceImpl.java
+++ b/server/dmvisit_service/src/main/java/com/doumee/service/business/impl/CompanyServiceImpl.java
@@ -2,6 +2,7 @@
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.doumee.biz.system.SystemDictDataBiz;
+import com.doumee.config.DataSyncConfig;
import com.doumee.core.annotation.excel.ExcelColumn;
import com.doumee.core.constants.ResponseStatus;
import com.doumee.core.exception.BusinessException;
@@ -19,24 +20,25 @@
import com.doumee.core.model.PageWrap;
import com.doumee.core.utils.Constants;
import com.doumee.core.utils.Utils;
+import com.doumee.dao.admin.request.UpdateCompanySortDTO;
import com.doumee.dao.admin.response.CompanyDTO;
import com.doumee.dao.business.CompanyMapper;
import com.doumee.dao.business.join.CompanyJoinMapper;
-import com.doumee.dao.business.model.Category;
-import com.doumee.dao.business.model.Company;
-import com.doumee.dao.business.model.Member;
+import com.doumee.dao.business.model.*;
+import com.doumee.dao.system.dto.UpdateSystemMenuSortDTO;
+import com.doumee.dao.system.model.SystemMenu;
import com.doumee.dao.system.model.SystemUser;
import com.doumee.service.business.CompanyService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.doumee.service.common.tree.CompanyTree;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import io.swagger.annotations.ApiModelProperty;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.SecurityUtils;
-import org.checkerframework.checker.units.qual.C;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -55,6 +57,8 @@
@Autowired
private CompanyMapper companyMapper;
+ @Autowired
+ private DataSyncConfig dataSyncConfig;
@Autowired
private SystemDictDataBiz systemDictDataBiz;
@@ -82,11 +86,10 @@
if(parent == null || Constants.equalsInteger(parent.getIsdeleted(),Constants.ONE)){
throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(), "瀵逛笉璧凤紝鐖剁骇缁勭粐淇℃伅涓嶅瓨鍦▇");
}
- if(StringUtils.isBlank(parent.getHkParentId())){
+ if(StringUtils.isBlank(parent.getHkId())){
throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(), "瀵逛笉璧凤紝鐖剁骇缁勭粐淇℃伅灏氭湭鍚屾涓嬪彂鎴愬姛~");
-
}
- company.setHkParentId(parent.getHkParentId());
+ company.setHkParentId(parent.getHkId());
}
company.setCreateDate(new Date());
company.setCreator(user.getId());
@@ -135,17 +138,18 @@
BaseResponse<List<OrgUpdateFailureResponse>> result = HKService.delBatchOrg(request);
if(result !=null && StringUtils.equals(result.getCode(),HKConstants.RESPONSE_SUCCEE)){
//澶勭悊鏂板鎴愬姛鐨勬暟鎹紝淇敼娴峰悍鍚屾鐘舵��
- if(result.getData()!=null && result.getData().size()>0){
+ if(result.getData()!=null && result.getData().size()==0){
return true;
}
}
+
return false;
}
private OrgAddRequest getOrgAddModel(Company c ) {
OrgAddRequest model = new OrgAddRequest();
- model.setOrgIndexCode(HKConstants.RES_ORG_INDEX+ UUID.randomUUID().toString().replace("-",""));
+ model.setOrgIndexCode(c.getHkId());
model.setOrgName(c.getName());
// model.setOrgCode(c.getCode());
model.setParentIndexCode(c.getHkParentId());
@@ -198,6 +202,7 @@
if(StringUtils.isBlank(model.getHkId())){
throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(), "瀵逛笉璧凤紝缁勭粐淇℃伅灏氭湭鍚屾涓嬪彂鎴愬姛,鏆備笉鏀寔淇敼锛岃灏濊瘯鍒犻櫎鍚庨噸鏂版坊鍔爚");
}
+
Company company = new Company();
company.setId(id);
company.setEditDate(new Date());
@@ -207,7 +212,7 @@
company.setHkDate(company.getHkDate());
companyMapper.updateById(company);
//涓嬪彂娴峰悍瀹夐槻骞冲彴
- if(!delHkOrg(company)){
+ if(!delHkOrg(model)){
throw new BusinessException(ResponseStatus.SERVER_ERROR.getCode(),"瀵逛笉璧凤紝缁勭粐鍒犻櫎涓嬪彂澶辫触锛岃纭璇ョ粍缁囨棤涓嬬骇缁勭粐鎴栫粍缁囦汉鍛樹俊鎭瘇");
}
}
@@ -439,24 +444,29 @@
@Override
public List<CompanyDTO> findCompanyTreePage(Integer type) {
//閰嶇疆缁勫憳浜哄憳绫诲瀷鏉ユ簮鏂瑰紡 0鑷缓 1ERP
- String origin = systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.ORG_USER_ORIGIN).getCode();
LambdaQueryWrapper<Company> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(Company::getIsdeleted,Constants.ZERO)
.eq(Constants.equalsInteger(type,Constants.ONE),Company::getType,type);
List<Company> companies = companyMapper.selectList(wrapper);
- return getCompanyTree( companies, null,origin);
+ return getCompanyTree( companies, null);
}
- private List<CompanyDTO> getCompanyTree(List<Company> companies, String parentId,String origin){
+ private List<CompanyDTO> getCompanyTree(List<Company> companies, String parentId){
if (CollectionUtils.isEmpty(companies)){
return null;
}
- List<Company> collect = companies.stream()
- .filter(s -> (StringUtils.equals(origin, Constants.ONE+"")?StringUtils.equals(s.getErpParentId(), parentId):StringUtils.equals(s.getParentId()+"", parentId)))
- .collect(Collectors.toList());
- if (CollectionUtils.isEmpty(companies)){
+ int origin =Constants.formatIntegerNum(dataSyncConfig.getOrgUserDataOrigin());
+ List<Company> collect = null;
+ if(origin == DataSyncConfig.origin.erp){
+ collect= companies.stream().filter(s -> ( StringUtils.defaultString(s.getErpParentId(),"").equals(StringUtils.defaultString(parentId)))).collect(Collectors.toList());
+ }else if(origin == DataSyncConfig.origin.hk){
+ collect= companies.stream().filter(s -> ( StringUtils.defaultString(s.getHkParentId(),"").equals(StringUtils.defaultString(parentId)))).collect(Collectors.toList());
+ }else{
+ collect= companies.stream().filter(s -> (StringUtils.defaultString(s.getParentId()+"","").equals(StringUtils.defaultString(parentId)))).collect(Collectors.toList());
+ }
+ if (CollectionUtils.isEmpty(collect)){
return null;
}
List<CompanyDTO> companyDTOList = new ArrayList<>();
@@ -464,7 +474,13 @@
Company company = collect.get(i);
CompanyDTO companyDTO = new CompanyDTO();
BeanUtils.copyProperties(company,companyDTO);
- companyDTO.setCompanyDTOList(getCompanyTree(companies,StringUtils.equals(origin, Constants.ONE+"")?company.getErpId(): company.getId()+"",origin));
+ String pId = company.getId()+"";
+ if(origin == 1){
+ pId = company.getErpId();
+ }else if(origin == 2){
+ pId = company.getHkParentId();
+ }
+ companyDTO.setCompanyDTOList(getCompanyTree(companies,pId));
companyDTOList.add(companyDTO);
}
return companyDTOList;
@@ -494,4 +510,78 @@
throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(),"鍏徃鍚嶇О宸插瓨鍦�");
}
}
+
+
+
+ @Override
+ public List<Company> companyTree(Integer type) {
+ MPJLambdaWrapper<Company> queryWrapper = new MPJLambdaWrapper<>();
+ queryWrapper.selectAll(Company.class);
+ queryWrapper.selectAs(Member::getName,Company::getHeadName);
+ queryWrapper.selectAs(Member::getPhone,Company::getHeadPhone);
+ queryWrapper.leftJoin(Member.class,Member::getId,Company::getHeadId);
+ queryWrapper.eq(Company::getIsdeleted,Constants.ZERO);
+ queryWrapper.eq(Company::getType,type);
+ List<Company> companyList = companyJoinMapper.selectJoinList(Company.class,queryWrapper);
+ //閰嶇疆缁勫憳浜哄憳绫诲瀷鏉ユ簮鏂瑰紡 0鑷缓 1ERP
+ CompanyTree treeBuild = new CompanyTree(companyList, dataSyncConfig.getOrgUserDataOrigin());
+ companyList = treeBuild.buildTree();
+ return companyList;
+ }
+
+
+ @Override
+ public void updateSort(UpdateCompanySortDTO dto) {
+ Company company = companyMapper.selectById(dto.getId());
+ if(Objects.isNull(company)){
+ throw new BusinessException(ResponseStatus.DATA_EMPTY);
+ }
+
+ List<Company> companyPool;
+ if (company.getParentId() == null) {
+ companyPool = companyMapper.selectList(new QueryWrapper<Company>().lambda()
+ .eq(Company::getIsdeleted,Constants.ZERO)
+ .isNull(Company::getParentId)
+ .orderByAsc(Company::getSortnum)
+ );
+ } else {
+ companyPool = companyMapper.selectList(new QueryWrapper<Company>().lambda()
+ .eq(Company::getIsdeleted,Constants.ZERO)
+ .eq(Company::getParentId,company.getParentId())
+ .orderByAsc(Company::getSortnum)
+ );
+ }
+ int currentMenuIndex = 0;
+ for (int i = 0; i < companyPool.size(); i++) {
+ if (companyPool.get(i).getId().equals(dto.getId())) {
+ currentMenuIndex = i;
+ break;
+ }
+ }
+ // 涓婄Щ
+ if ("top".equals(dto.getDirection())) {
+ if (currentMenuIndex - 1 < 0) {
+ return;
+ }
+ Company preMenu = companyPool.remove(currentMenuIndex - 1);
+ companyPool.add(currentMenuIndex, preMenu);
+ }
+ // 涓嬬Щ
+ else {
+ if (currentMenuIndex + 1 > companyPool.size() - 1) {
+ return;
+ }
+ Company nextMenu = companyPool.remove(currentMenuIndex + 1);
+ companyPool.add(currentMenuIndex, nextMenu);
+ }
+ for (int i = 0; i < companyPool.size(); i++) {
+ companyPool.get(i).setSortnum(i);
+ }
+
+ for (Company updCompany:companyPool) {
+ companyMapper.updateById(updCompany);
+ }
+
+ }
+
}
--
Gitblit v1.9.3