绑定车辆
This commit is contained in:
parent
7eaeb811eb
commit
38422ce5c2
@ -7,4 +7,8 @@ package cn.iocoder.yudao.common;
|
||||
public class BaseConstants {
|
||||
/**政企客户经办人*/
|
||||
public static final String CUS_TYPE_CORP_ATTN = "04";
|
||||
/**客户标识*/
|
||||
public static final String CUS_SIGN_CUSTOMER = "customer";
|
||||
/**车辆标识*/
|
||||
public static final String CUS_SIGN_CAR = "car";
|
||||
}
|
||||
|
@ -123,10 +123,11 @@ public class CustomerMainController {
|
||||
|
||||
/**
|
||||
* 根据经办人所属企业查询经办人信息
|
||||
* @author PQZ
|
||||
* @date 16:15 2024/8/2
|
||||
*
|
||||
* @param deptCode 经办人所属企业code
|
||||
* @return cn.iocoder.yudao.framework.common.pojo.CommonResult<java.lang.Boolean>
|
||||
* @author PQZ
|
||||
* @date 16:15 2024/8/2
|
||||
**/
|
||||
@GetMapping("/getAttn")
|
||||
@Operation(summary = "根据deptCode获取经办人信息")
|
||||
@ -134,4 +135,20 @@ public class CustomerMainController {
|
||||
return success(customerMainService.getCustomerByDeptCode(deptCode));
|
||||
}
|
||||
|
||||
/**
|
||||
* 绑定车辆
|
||||
*
|
||||
* @param saveReqVO CustomerMainSaveReqVO
|
||||
* @return cn.iocoder.yudao.framework.common.pojo.CommonResult<java.lang.Boolean>
|
||||
* @author PQZ
|
||||
* @date 19:21 2024/8/3
|
||||
**/
|
||||
@PostMapping("/bindCustomerCar")
|
||||
@Operation(summary = "创建客户管理")
|
||||
@PreAuthorize("@ss.hasPermission('base:customer-main:car')")
|
||||
public CommonResult<Boolean> bindCustomerCar(@Valid @RequestBody CustomerMainSaveReqVO saveReqVO) {
|
||||
customerMainService.bindCustomAndCar(saveReqVO);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
}
|
@ -36,7 +36,7 @@ public interface CarMainMapper extends BaseMapper<CarMain> {
|
||||
* @param cusId 客户id
|
||||
* @return java.util.List<cn.iocoder.yudao.module.custom.entity.CarMain>
|
||||
**/
|
||||
List<CarMain> selectListByCusId( @Param("cusId") String cusId);
|
||||
List<CarMainRespVO> selectListByCusId( @Param("cusId") String cusId);
|
||||
List<CarMain> isDataKeyValueRepeat(@Param("dto") CarMain carMain);
|
||||
|
||||
}
|
@ -3,6 +3,8 @@ package cn.iocoder.yudao.module.custom.service;
|
||||
import cn.iocoder.yudao.module.custom.entity.CustomerCar;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 客户车辆管理关联Service 接口
|
||||
*
|
||||
@ -10,5 +12,15 @@ import com.baomidou.mybatisplus.extension.service.IService;
|
||||
*/
|
||||
public interface CustomerCarService extends IService<CustomerCar> {
|
||||
|
||||
|
||||
/**
|
||||
* 保存客户与车辆的关联关系
|
||||
*
|
||||
* @param mainId 主表id
|
||||
* @param mainTable 主表标识(cust:客户,car:车辆)
|
||||
* @param customerCars List<CustomerCar>
|
||||
* @return void
|
||||
* @author PQZ
|
||||
* @date 18:45 2024/8/3
|
||||
**/
|
||||
void bindCustomerCar(String mainId, String mainTable, List<CustomerCar> customerCars);
|
||||
}
|
@ -41,20 +41,32 @@ public interface CustomerMainService extends IService<CustomerMain> {
|
||||
|
||||
/**
|
||||
* 根据客户id查询客户信息
|
||||
* @author PQZ
|
||||
* @date 15:12 2024/8/2
|
||||
*
|
||||
* @param id 客户id
|
||||
* @return cn.iocoder.yudao.module.custom.vo.CustomerMainRespVO
|
||||
* @author PQZ
|
||||
* @date 15:12 2024/8/2
|
||||
**/
|
||||
CustomerMainRespVO getCustomerById(String id);
|
||||
|
||||
/**
|
||||
* 根据经办人所属企业查询经办人信息
|
||||
* @author PQZ
|
||||
* @date 16:15 2024/8/2
|
||||
*
|
||||
* @param deptCode 经办人所属企业code
|
||||
* @return java.util.List<cn.iocoder.yudao.module.custom.vo.CustomerMainRespVO>
|
||||
* @author PQZ
|
||||
* @date 16:15 2024/8/2
|
||||
**/
|
||||
List<CustomerMain> getCustomerByDeptCode(String deptCode);
|
||||
|
||||
/**
|
||||
* 绑定车辆信息
|
||||
*
|
||||
* @param saveReqVO CustomerMainSaveReqVO实体
|
||||
* @return void
|
||||
* @author PQZ
|
||||
* @date 18:42 2024/8/3
|
||||
**/
|
||||
void bindCustomAndCar(CustomerMainSaveReqVO saveReqVO);
|
||||
|
||||
}
|
@ -1,12 +1,18 @@
|
||||
package cn.iocoder.yudao.module.custom.service.impl;
|
||||
|
||||
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
|
||||
import cn.iocoder.yudao.module.custom.entity.CustomerCar;
|
||||
import cn.iocoder.yudao.module.custom.mapper.CustomerCarMapper;
|
||||
import cn.iocoder.yudao.module.custom.service.CustomerCarService;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static cn.iocoder.yudao.common.BaseConstants.CUS_SIGN_CUSTOMER;
|
||||
|
||||
/**
|
||||
* 客户车辆管理关联
|
||||
*
|
||||
@ -17,4 +23,37 @@ import org.springframework.validation.annotation.Validated;
|
||||
public class CustomerCarServiceImpl extends ServiceImpl<CustomerCarMapper, CustomerCar> implements CustomerCarService {
|
||||
|
||||
|
||||
/**
|
||||
* 保存客户与车辆的关联关系
|
||||
*
|
||||
* @param mainId 主表id
|
||||
* @param mainTable 主表标识(cust:客户,car:车辆)
|
||||
* @param customerCars List<CustomerCar>
|
||||
* @return void
|
||||
* @author PQZ
|
||||
* @date 18:45 2024/8/3
|
||||
**/
|
||||
@Override
|
||||
public void bindCustomerCar(String mainId, String mainTable, List<CustomerCar> customerCars) {
|
||||
/*1、删除已有关联关系*/
|
||||
LambdaQueryWrapper<CustomerCar> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
lambdaQueryWrapper.eq(BaseDO::getDeleted, 0);
|
||||
if (CUS_SIGN_CUSTOMER.equals(mainTable)) {
|
||||
//如果主表是客户表
|
||||
lambdaQueryWrapper.eq(CustomerCar::getCusId, mainId);
|
||||
} else {
|
||||
//如果主表是车辆表
|
||||
lambdaQueryWrapper.eq(CustomerCar::getCarId, mainId);
|
||||
}
|
||||
this.remove(lambdaQueryWrapper);
|
||||
/*2、保存新关联关系*/
|
||||
if (null != customerCars && !customerCars.isEmpty()) {
|
||||
customerCars.forEach(item -> {
|
||||
//防止主键重复
|
||||
item.setId(null);
|
||||
});
|
||||
this.saveBatch(customerCars);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -5,6 +5,7 @@ import cn.iocoder.yudao.framework.common.exception.ServiceException;
|
||||
import cn.iocoder.yudao.framework.common.exception.enums.GlobalErrorCodeConstants;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
|
||||
import cn.iocoder.yudao.module.custom.entity.CarMain;
|
||||
import cn.iocoder.yudao.module.custom.entity.CustomerCar;
|
||||
import cn.iocoder.yudao.module.custom.entity.CustomerItem;
|
||||
import cn.iocoder.yudao.module.custom.entity.CustomerMain;
|
||||
import cn.iocoder.yudao.module.custom.mapper.CarMainMapper;
|
||||
@ -13,6 +14,7 @@ import cn.iocoder.yudao.module.custom.service.CarMainService;
|
||||
import cn.iocoder.yudao.module.custom.service.CustomerCarService;
|
||||
import cn.iocoder.yudao.module.custom.service.CustomerItemService;
|
||||
import cn.iocoder.yudao.module.custom.service.CustomerMainService;
|
||||
import cn.iocoder.yudao.module.custom.vo.CarMainRespVO;
|
||||
import cn.iocoder.yudao.module.custom.vo.CustomerMainPageReqVO;
|
||||
import cn.iocoder.yudao.module.custom.vo.CustomerMainRespVO;
|
||||
import cn.iocoder.yudao.module.custom.vo.CustomerMainSaveReqVO;
|
||||
@ -25,9 +27,11 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import static cn.iocoder.yudao.common.BaseConstants.CUS_SIGN_CUSTOMER;
|
||||
import static cn.iocoder.yudao.common.BaseConstants.CUS_TYPE_CORP_ATTN;
|
||||
|
||||
/**
|
||||
@ -111,7 +115,7 @@ public class CustomerMainServiceImpl extends ServiceImpl<CustomerMainMapper, Cus
|
||||
lambdaQueryWrapper.eq(BaseDO::getDeleted, 0).eq(CustomerItem::getCusId, id);
|
||||
List<CustomerItem> itemList = customerItemService.list(lambdaQueryWrapper);
|
||||
/*3、车辆信息*/
|
||||
List<CarMain> carList = carMainMapper.selectListByCusId(id);
|
||||
List<CarMainRespVO> carList = carMainMapper.selectListByCusId(id);
|
||||
CustomerMainRespVO result = JSONUtil.toBean(JSONUtil.parseObj(main).toJSONString(0), CustomerMainRespVO.class);
|
||||
result.setItemList(itemList);
|
||||
result.setCarList(carList);
|
||||
@ -132,4 +136,30 @@ public class CustomerMainServiceImpl extends ServiceImpl<CustomerMainMapper, Cus
|
||||
lambdaQueryWrapper.eq(BaseDO::getDeleted, 0).eq(CustomerMain::getDeptCode, deptCode).eq(CustomerMain::getTypeCode, CUS_TYPE_CORP_ATTN);
|
||||
return list(lambdaQueryWrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 绑定车辆信息
|
||||
*
|
||||
* @param saveReqVO CustomerMainSaveReqVO实体
|
||||
* @return void
|
||||
* @author PQZ
|
||||
* @date 18:42 2024/8/3
|
||||
**/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void bindCustomAndCar(CustomerMainSaveReqVO saveReqVO) {
|
||||
List<CustomerCar> customerCars = new ArrayList<>();
|
||||
List<CarMainRespVO> carList = saveReqVO.getCarList();
|
||||
if (null != carList){
|
||||
//组装数据
|
||||
carList.forEach(item -> {
|
||||
CustomerCar customerCar = new CustomerCar();
|
||||
customerCar.setCarId(item.getId());
|
||||
customerCar.setCusId(saveReqVO.getId());
|
||||
customerCar.setIsOwner(item.getIsOwner());
|
||||
customerCars.add(customerCar);
|
||||
});
|
||||
}
|
||||
customerCarService.bindCustomerCar(saveReqVO.getId(),CUS_SIGN_CUSTOMER,customerCars);
|
||||
}
|
||||
}
|
@ -87,4 +87,7 @@ public class CarMainRespVO extends CarMain {
|
||||
@ExcelProperty("创建时间")
|
||||
private LocalDateTime createTime;
|
||||
|
||||
/**是否车主(0否1是)*/
|
||||
private String isOwner;
|
||||
|
||||
}
|
@ -22,6 +22,6 @@ public class CustomerMainRespVO extends CustomerMain {
|
||||
/**扩展信息*/
|
||||
List<CustomerItem> itemList;
|
||||
/**客户绑定车辆信息*/
|
||||
List<CarMain> carList;
|
||||
List<CarMainRespVO> carList;
|
||||
|
||||
}
|
@ -13,5 +13,7 @@ public class CustomerMainSaveReqVO extends CustomerMain {
|
||||
|
||||
/**客户扩展信息表内容*/
|
||||
private List<CustomerItem> itemList;
|
||||
/**客户绑定车辆信息*/
|
||||
private List<CarMainRespVO> carList;
|
||||
|
||||
}
|
@ -90,13 +90,15 @@
|
||||
</if>
|
||||
|
||||
</select>
|
||||
<select id="selectListByCusId" resultType="cn.iocoder.yudao.module.custom.entity.CarMain">
|
||||
<select id="selectListByCusId" resultType="cn.iocoder.yudao.module.custom.vo.CarMainRespVO">
|
||||
SELECT
|
||||
<include refid="baseCarMainColumn"></include>
|
||||
<include refid="baseCarMainColumn"></include>,main.is_owner AS isOwner
|
||||
FROM
|
||||
`base_car_main` tbcm
|
||||
base_customer_car main
|
||||
LEFT JOIN base_car_main tbcm ON main.car_id = tbcm.id AND tbcm.deleted = 0
|
||||
WHERE
|
||||
tbcm.id IN ( SELECT car_id FROM base_customer_car WHERE cus_id = #{cusId} AND deleted = 0 )
|
||||
AND tbcm.deleted = 0
|
||||
main.deleted = 0
|
||||
AND main.cus_id = #{cusId}
|
||||
ORDER BY main.create_time DESC
|
||||
</select>
|
||||
</mapper>
|
Loading…
Reference in New Issue
Block a user