新增客户和司机时针对用户和部门是否存在的情况进行判断
parent
8087c7ed48
commit
1c01993989
|
|
@ -8,7 +8,11 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.cpxt.biz.domain.BizCarModel;
|
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.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.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.security.core.parameters.P;
|
import org.springframework.security.core.parameters.P;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
@ -28,6 +32,12 @@ public class BizCustomerServiceImpl implements IBizCustomerService
|
||||||
@Autowired
|
@Autowired
|
||||||
private BizCustomerMapper bizCustomerMapper;
|
private BizCustomerMapper bizCustomerMapper;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private SysDeptMapper sysDeptMapper;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private SysUserMapper sysUserMapper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询客户
|
* 查询客户
|
||||||
*
|
*
|
||||||
|
|
@ -91,9 +101,37 @@ public class BizCustomerServiceImpl implements IBizCustomerService
|
||||||
@Override
|
@Override
|
||||||
public int insertBizCustomer(BizCustomer bizCustomer)
|
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);
|
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
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 修改客户
|
* 修改客户
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -94,12 +94,16 @@ public class BizDriverServiceImpl implements IBizDriverService
|
||||||
@Override
|
@Override
|
||||||
public int insertBizDriver(BizDriver bizDriver)
|
public int insertBizDriver(BizDriver bizDriver)
|
||||||
{
|
{
|
||||||
SysUser sysUser = new SysUser();
|
|
||||||
setSysUser(bizDriver,sysUser);
|
|
||||||
sysUserMapper.insertUser(sysUser);
|
|
||||||
|
|
||||||
bizDriver.setDeptName(sysDeptMapper.selectDeptById(bizDriver.getDeptId()).getDeptName());
|
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);
|
return bizDriverMapper.insert(bizDriver);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -111,7 +115,7 @@ public class BizDriverServiceImpl implements IBizDriverService
|
||||||
sysUser.setPhonenumber(bizDriver.getPhone());
|
sysUser.setPhonenumber(bizDriver.getPhone());
|
||||||
sysUser.setSex(bizDriver.getGender());
|
sysUser.setSex(bizDriver.getGender());
|
||||||
sysUser.setAvatar(bizDriver.getPhoto());
|
sysUser.setAvatar(bizDriver.getPhoto());
|
||||||
sysUser.setPassword(bizDriver.getIdcard().substring(12,18)); // 340123199906222873
|
sysUser.setPassword(bizDriver.getPhone().substring(7,11)); // 18756576807
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -115,4 +115,7 @@ public interface SysDeptMapper
|
||||||
* @return 结果
|
* @return 结果
|
||||||
*/
|
*/
|
||||||
public int deleteDeptById(Long deptId);
|
public int deleteDeptById(Long deptId);
|
||||||
|
|
||||||
|
Long selectDeptIdByDeptName(String deptName);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -86,7 +86,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
<include refid="selectDeptVo"/>
|
<include refid="selectDeptVo"/>
|
||||||
where dept_name=#{deptName} and parent_id = #{parentId} and del_flag = '0' limit 1
|
where dept_name=#{deptName} and parent_id = #{parentId} and del_flag = '0' limit 1
|
||||||
</select>
|
</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 id="insertDept" parameterType="SysDept">
|
||||||
insert into sys_dept(
|
insert into sys_dept(
|
||||||
<if test="deptId != null and deptId != 0">dept_id,</if>
|
<if test="deptId != null and deptId != 0">dept_id,</if>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue