新增客户和司机时针对用户和部门是否存在的情况进行判断

master
luojian 2024-12-19 09:40:24 +08:00
parent 8087c7ed48
commit 1c01993989
4 changed files with 56 additions and 7 deletions

View File

@ -8,7 +8,11 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cpxt.biz.domain.BizCarModel;
import com.cpxt.common.core.domain.entity.SysDept;
import com.cpxt.common.core.domain.entity.SysUser;
import com.cpxt.common.utils.DateUtils;
import com.cpxt.system.mapper.SysDeptMapper;
import com.cpxt.system.mapper.SysUserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.parameters.P;
import org.springframework.stereotype.Service;
@ -28,6 +32,12 @@ public class BizCustomerServiceImpl implements IBizCustomerService
@Autowired
private BizCustomerMapper bizCustomerMapper;
@Autowired
private SysDeptMapper sysDeptMapper;
@Autowired
private SysUserMapper sysUserMapper;
/**
*
*
@ -91,9 +101,37 @@ public class BizCustomerServiceImpl implements IBizCustomerService
@Override
public int insertBizCustomer(BizCustomer bizCustomer)
{
Long parentId = sysDeptMapper.selectDeptIdByDeptName("外部单位");
Long aLong = sysDeptMapper.selectDeptIdByDeptName(bizCustomer.getName());
SysDept sysDept = new SysDept();
if (ObjectUtil.isEmpty(aLong)){
// 同步创建一个部门,名称为客户名称
sysDept.setParentId(parentId);
sysDept.setAncestors("0," + parentId);
sysDept.setDeptName(bizCustomer.getName());
sysDeptMapper.insertDept(sysDept);
}else {
sysDept.setDeptId(aLong);
}
// 同步新增一个用户
SysUser user = sysUserMapper.selectUserByUserName(bizCustomer.getLinkphone());
if (ObjectUtil.isEmpty(user)){
SysUser sysUser = new SysUser();
setSysUser(bizCustomer,sysUser,sysDept);
sysUserMapper.insertUser(sysUser);
}
return bizCustomerMapper.insert(bizCustomer);
}
private void setSysUser(BizCustomer bizCustomer, SysUser sysUser, SysDept sysDept) {
sysUser.setDeptId(sysDept.getDeptId());
sysUser.setUserName(bizCustomer.getLinkphone());
sysUser.setNickName(bizCustomer.getName());
sysUser.setUserType("2"); // 客户
sysUser.setPhonenumber(bizCustomer.getLinkphone());
sysUser.setPassword(bizCustomer.getLinkphone().substring(7,11)); // 18756576807
}
/**
*
*

View File

@ -94,12 +94,16 @@ public class BizDriverServiceImpl implements IBizDriverService
@Override
public int insertBizDriver(BizDriver bizDriver)
{
SysUser sysUser = new SysUser();
setSysUser(bizDriver,sysUser);
sysUserMapper.insertUser(sysUser);
bizDriver.setDeptName(sysDeptMapper.selectDeptById(bizDriver.getDeptId()).getDeptName());
bizDriver.setUserId(sysUser.getUserId());
SysUser user = sysUserMapper.selectUserByUserName(bizDriver.getPhone());
if (ObjectUtil.isEmpty(user)){
SysUser sysUser = new SysUser();
setSysUser(bizDriver,sysUser);
sysUserMapper.insertUser(sysUser);
bizDriver.setUserId(sysUser.getUserId());
}else {
bizDriver.setUserId(user.getUserId());
}
return bizDriverMapper.insert(bizDriver);
}
@ -111,7 +115,7 @@ public class BizDriverServiceImpl implements IBizDriverService
sysUser.setPhonenumber(bizDriver.getPhone());
sysUser.setSex(bizDriver.getGender());
sysUser.setAvatar(bizDriver.getPhoto());
sysUser.setPassword(bizDriver.getIdcard().substring(12,18)); // 340123199906222873
sysUser.setPassword(bizDriver.getPhone().substring(7,11)); // 18756576807
}
/**

View File

@ -115,4 +115,7 @@ public interface SysDeptMapper
* @return
*/
public int deleteDeptById(Long deptId);
Long selectDeptIdByDeptName(String deptName);
}

View File

@ -87,6 +87,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
where dept_name=#{deptName} and parent_id = #{parentId} and del_flag = '0' limit 1
</select>
<select id="selectDeptIdByDeptName" resultType="java.lang.Long">
select dept_id from sys_dept where dept_name = #{deptName}
</select>
<insert id="insertDept" parameterType="SysDept">
insert into sys_dept(
<if test="deptId != null and deptId != 0">dept_id,</if>