|
|
@@ -1,11 +1,30 @@
|
|
|
package org.jeecg.modules.hlgcompany.service.impl;
|
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import io.netty.util.internal.StringUtil;
|
|
|
+import org.apache.shiro.SecurityUtils;
|
|
|
+import org.jeecg.common.constant.CommonConstant;
|
|
|
+import org.jeecg.common.system.vo.LoginUser;
|
|
|
+import org.jeecg.common.util.YouBianCodeUtil;
|
|
|
import org.jeecg.modules.hlgcompany.entity.HlgCompany;
|
|
|
import org.jeecg.modules.hlgcompany.mapper.HlgCompanyMapper;
|
|
|
import org.jeecg.modules.hlgcompany.service.IHlgCompanyService;
|
|
|
+import org.jeecg.modules.hlgplatform.entity.HlgPlatform;
|
|
|
+import org.jeecg.modules.hlgplatform.service.IHlgPlatformService;
|
|
|
+import org.jeecg.modules.system.entity.SysDepart;
|
|
|
+import org.jeecg.modules.system.service.ISysDepartService;
|
|
|
+import org.jeecg.modules.system.service.impl.SysDepartServiceImpl;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+import java.util.UUID;
|
|
|
|
|
|
/**
|
|
|
* @Description: hlg_company
|
|
|
@@ -15,5 +34,117 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
*/
|
|
|
@Service
|
|
|
public class HlgCompanyServiceImpl extends ServiceImpl<HlgCompanyMapper, HlgCompany> implements IHlgCompanyService {
|
|
|
+ @Autowired
|
|
|
+ private ISysDepartService sysDepartService;
|
|
|
+ @Resource
|
|
|
+ private SysDepartServiceImpl sysDepartServiceImpl;
|
|
|
+ @Resource
|
|
|
+ private IHlgPlatformService hlgPlatformService;
|
|
|
+ /**
|
|
|
+ * 新增企业信息
|
|
|
+ *
|
|
|
+ * @param
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public void saveCompany(HlgCompany hlgCompany) {
|
|
|
+ LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
|
|
|
+ //自动生成一个二级机构
|
|
|
+ SysDepart sysDepart = new SysDepart();
|
|
|
+ sysDepart.setDepartName(hlgCompany.getCompanyName());
|
|
|
+ sysDepart.setDepartOrder(0);
|
|
|
+ sysDepart.setOrgType("2");
|
|
|
+ String s = UUID.randomUUID().toString().replace("-", "");
|
|
|
+ sysDepart.setId(s);
|
|
|
+ // 先判断该对象有无父级ID,有则意味着不是最高级,否则意味着是最高级
|
|
|
+ // 获取父级ID
|
|
|
+ SysDepart sysDepartParent = sysDepartService.getByCode(sysUser.getOrgCode());
|
|
|
+ sysDepart.setParentId(sysDepartParent.getId());
|
|
|
+ String parentId = sysDepart.getParentId();
|
|
|
+ String[] codeArray = generateOrgCode(parentId);
|
|
|
+ sysDepart.setOrgCode(codeArray[0]);
|
|
|
+ sysDepart.setCreateTime(new Date());
|
|
|
+ sysDepart.setDelFlag(CommonConstant.DEL_FLAG_0.toString());
|
|
|
+ sysDepartService.save(sysDepart);
|
|
|
+ //保存企业
|
|
|
+ //默认:认证状态0
|
|
|
+ hlgCompany.setIsLock(0);
|
|
|
+ //获取当前平台id
|
|
|
+ HlgPlatform hlgPlatform = hlgPlatformService.getByCode(sysUser.getOrgCode());
|
|
|
+ hlgCompany.setPlatformId(hlgPlatform.getId());
|
|
|
+ hlgCompany.setCreateBy(sysUser.getUsername());
|
|
|
+ hlgCompany.setUpdateTime(new Date());
|
|
|
+ hlgCompany.setUpdateBy(sysUser.getUsername());
|
|
|
+ hlgCompany.setSysOrgCode(sysDepart.getOrgCode());
|
|
|
+ this.save(hlgCompany);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * saveDepartData 的调用方法,生成部门编码和部门类型
|
|
|
+ *
|
|
|
+ * @param parentId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private String[] generateOrgCode(String parentId) {
|
|
|
+ //update-begin--Author:Steve Date:20190201 for:组织机构添加数据代码调整
|
|
|
+ LambdaQueryWrapper<SysDepart> query = new LambdaQueryWrapper<SysDepart>();
|
|
|
+ LambdaQueryWrapper<SysDepart> query1 = new LambdaQueryWrapper<SysDepart>();
|
|
|
+ String[] strArray = new String[2];
|
|
|
+ // 创建一个List集合,存储查询返回的所有SysDepart对象
|
|
|
+ List<SysDepart> departList = new ArrayList<>();
|
|
|
+ // 定义新编码字符串
|
|
|
+ String newOrgCode = "";
|
|
|
+ // 定义旧编码字符串
|
|
|
+ String oldOrgCode = "";
|
|
|
+ // 定义部门类型
|
|
|
+ String orgType = "";
|
|
|
+ // 如果是最高级,则查询出同级的org_code, 调用工具类生成编码并返回
|
|
|
+ if (StringUtil.isNullOrEmpty(parentId)) {
|
|
|
+ // 线判断数据库中的表是否为空,空则直接返回初始编码
|
|
|
+ query1.eq(SysDepart::getParentId, "");
|
|
|
+ query1.orderByDesc(SysDepart::getOrgCode);
|
|
|
+ departList = sysDepartServiceImpl.list(query1);
|
|
|
+ if (departList == null || departList.size() == 0) {
|
|
|
+ strArray[0] = YouBianCodeUtil.getNextYouBianCode(null);
|
|
|
+ strArray[1] = "1";
|
|
|
+ return strArray;
|
|
|
+ } else {
|
|
|
+ SysDepart depart = departList.get(0);
|
|
|
+ oldOrgCode = depart.getOrgCode();
|
|
|
+ orgType = depart.getOrgType();
|
|
|
+ newOrgCode = YouBianCodeUtil.getNextYouBianCode(oldOrgCode);
|
|
|
+ }
|
|
|
+ } else { // 反之则查询出所有同级的部门,获取结果后有两种情况,有同级和没有同级
|
|
|
+ // 封装查询同级的条件
|
|
|
+ query.eq(SysDepart::getParentId, parentId);
|
|
|
+ // 降序排序
|
|
|
+ query.orderByDesc(SysDepart::getOrgCode);
|
|
|
+ // 查询出同级部门的集合
|
|
|
+ List<SysDepart> parentList = sysDepartServiceImpl.list(query);
|
|
|
+ // 查询出父级部门
|
|
|
+ SysDepart depart = sysDepartServiceImpl.getById(parentId);
|
|
|
+ // 获取父级部门的Code
|
|
|
+ String parentCode = depart.getOrgCode();
|
|
|
+ // 根据父级部门类型算出当前部门的类型
|
|
|
+ orgType = String.valueOf(Integer.valueOf(depart.getOrgType()) + 1);
|
|
|
+ // 处理同级部门为null的情况
|
|
|
+ if (parentList == null || parentList.size() == 0) {
|
|
|
+ // 直接生成当前的部门编码并返回
|
|
|
+ newOrgCode = YouBianCodeUtil.getSubYouBianCode(parentCode, null);
|
|
|
+ } else { //处理有同级部门的情况
|
|
|
+ // 获取同级部门的编码,利用工具类
|
|
|
+ String subCode = parentList.get(0).getOrgCode();
|
|
|
+ // 返回生成的当前部门编码
|
|
|
+ newOrgCode = YouBianCodeUtil.getSubYouBianCode(parentCode, subCode);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 返回最终封装了部门编码和部门类型的数组
|
|
|
+ strArray[0] = newOrgCode;
|
|
|
+ strArray[1] = orgType;
|
|
|
+ return strArray;
|
|
|
+ //update-end--Author:Steve Date:20190201 for:组织机构添加数据代码调整
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
}
|