From 38422ce5c2c3ff29971e2f5f14ec147949a8c1ab Mon Sep 17 00:00:00 2001 From: PQZ Date: Sat, 3 Aug 2024 21:51:22 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=91=E5=AE=9A=E8=BD=A6=E8=BE=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../iocoder/yudao/common/BaseConstants.java | 4 ++ .../admin/CustomerMainController.java | 21 +++++++++- .../module/custom/mapper/CarMainMapper.java | 2 +- .../custom/service/CustomerCarService.java | 14 ++++++- .../custom/service/CustomerMainService.java | 24 +++++++++--- .../service/impl/CustomerCarServiceImpl.java | 39 +++++++++++++++++++ .../service/impl/CustomerMainServiceImpl.java | 32 ++++++++++++++- .../yudao/module/custom/vo/CarMainRespVO.java | 3 ++ .../module/custom/vo/CustomerMainRespVO.java | 2 +- .../custom/vo/CustomerMainSaveReqVO.java | 2 + .../resources/mapper/custom/CarMainMapper.xml | 12 +++--- 11 files changed, 138 insertions(+), 17 deletions(-) diff --git a/dl-module-base/src/main/java/cn/iocoder/yudao/common/BaseConstants.java b/dl-module-base/src/main/java/cn/iocoder/yudao/common/BaseConstants.java index 8d59cc5c..422197ef 100644 --- a/dl-module-base/src/main/java/cn/iocoder/yudao/common/BaseConstants.java +++ b/dl-module-base/src/main/java/cn/iocoder/yudao/common/BaseConstants.java @@ -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"; } diff --git a/dl-module-base/src/main/java/cn/iocoder/yudao/module/custom/controller/admin/CustomerMainController.java b/dl-module-base/src/main/java/cn/iocoder/yudao/module/custom/controller/admin/CustomerMainController.java index 246b00f4..d8cca422 100644 --- a/dl-module-base/src/main/java/cn/iocoder/yudao/module/custom/controller/admin/CustomerMainController.java +++ b/dl-module-base/src/main/java/cn/iocoder/yudao/module/custom/controller/admin/CustomerMainController.java @@ -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 + * @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 + * @author PQZ + * @date 19:21 2024/8/3 + **/ + @PostMapping("/bindCustomerCar") + @Operation(summary = "创建客户管理") + @PreAuthorize("@ss.hasPermission('base:customer-main:car')") + public CommonResult bindCustomerCar(@Valid @RequestBody CustomerMainSaveReqVO saveReqVO) { + customerMainService.bindCustomAndCar(saveReqVO); + return success(true); + } + } \ No newline at end of file diff --git a/dl-module-base/src/main/java/cn/iocoder/yudao/module/custom/mapper/CarMainMapper.java b/dl-module-base/src/main/java/cn/iocoder/yudao/module/custom/mapper/CarMainMapper.java index 16de1d72..f3cec350 100644 --- a/dl-module-base/src/main/java/cn/iocoder/yudao/module/custom/mapper/CarMainMapper.java +++ b/dl-module-base/src/main/java/cn/iocoder/yudao/module/custom/mapper/CarMainMapper.java @@ -36,7 +36,7 @@ public interface CarMainMapper extends BaseMapper { * @param cusId 客户id * @return java.util.List **/ - List selectListByCusId( @Param("cusId") String cusId); + List selectListByCusId( @Param("cusId") String cusId); List isDataKeyValueRepeat(@Param("dto") CarMain carMain); } \ No newline at end of file diff --git a/dl-module-base/src/main/java/cn/iocoder/yudao/module/custom/service/CustomerCarService.java b/dl-module-base/src/main/java/cn/iocoder/yudao/module/custom/service/CustomerCarService.java index eba9bd9e..218231f8 100644 --- a/dl-module-base/src/main/java/cn/iocoder/yudao/module/custom/service/CustomerCarService.java +++ b/dl-module-base/src/main/java/cn/iocoder/yudao/module/custom/service/CustomerCarService.java @@ -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 { - + /** + * 保存客户与车辆的关联关系 + * + * @param mainId 主表id + * @param mainTable 主表标识(cust:客户,car:车辆) + * @param customerCars List + * @return void + * @author PQZ + * @date 18:45 2024/8/3 + **/ + void bindCustomerCar(String mainId, String mainTable, List customerCars); } \ No newline at end of file diff --git a/dl-module-base/src/main/java/cn/iocoder/yudao/module/custom/service/CustomerMainService.java b/dl-module-base/src/main/java/cn/iocoder/yudao/module/custom/service/CustomerMainService.java index 876d9680..c31bd407 100644 --- a/dl-module-base/src/main/java/cn/iocoder/yudao/module/custom/service/CustomerMainService.java +++ b/dl-module-base/src/main/java/cn/iocoder/yudao/module/custom/service/CustomerMainService.java @@ -41,20 +41,32 @@ public interface CustomerMainService extends IService { /** * 根据客户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 - **/ + * @author PQZ + * @date 16:15 2024/8/2 + **/ List getCustomerByDeptCode(String deptCode); + /** + * 绑定车辆信息 + * + * @param saveReqVO CustomerMainSaveReqVO实体 + * @return void + * @author PQZ + * @date 18:42 2024/8/3 + **/ + void bindCustomAndCar(CustomerMainSaveReqVO saveReqVO); + } \ No newline at end of file diff --git a/dl-module-base/src/main/java/cn/iocoder/yudao/module/custom/service/impl/CustomerCarServiceImpl.java b/dl-module-base/src/main/java/cn/iocoder/yudao/module/custom/service/impl/CustomerCarServiceImpl.java index 8b5c2247..aa3cda8d 100644 --- a/dl-module-base/src/main/java/cn/iocoder/yudao/module/custom/service/impl/CustomerCarServiceImpl.java +++ b/dl-module-base/src/main/java/cn/iocoder/yudao/module/custom/service/impl/CustomerCarServiceImpl.java @@ -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 implements CustomerCarService { + /** + * 保存客户与车辆的关联关系 + * + * @param mainId 主表id + * @param mainTable 主表标识(cust:客户,car:车辆) + * @param customerCars List + * @return void + * @author PQZ + * @date 18:45 2024/8/3 + **/ + @Override + public void bindCustomerCar(String mainId, String mainTable, List customerCars) { + /*1、删除已有关联关系*/ + LambdaQueryWrapper 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); + } + + } } \ No newline at end of file diff --git a/dl-module-base/src/main/java/cn/iocoder/yudao/module/custom/service/impl/CustomerMainServiceImpl.java b/dl-module-base/src/main/java/cn/iocoder/yudao/module/custom/service/impl/CustomerMainServiceImpl.java index 6a78ab5e..1053528a 100644 --- a/dl-module-base/src/main/java/cn/iocoder/yudao/module/custom/service/impl/CustomerMainServiceImpl.java +++ b/dl-module-base/src/main/java/cn/iocoder/yudao/module/custom/service/impl/CustomerMainServiceImpl.java @@ -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 itemList = customerItemService.list(lambdaQueryWrapper); /*3、车辆信息*/ - List carList = carMainMapper.selectListByCusId(id); + List 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 customerCars = new ArrayList<>(); + List 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); + } } \ No newline at end of file diff --git a/dl-module-base/src/main/java/cn/iocoder/yudao/module/custom/vo/CarMainRespVO.java b/dl-module-base/src/main/java/cn/iocoder/yudao/module/custom/vo/CarMainRespVO.java index ff0c9d2d..a3f8fd0e 100644 --- a/dl-module-base/src/main/java/cn/iocoder/yudao/module/custom/vo/CarMainRespVO.java +++ b/dl-module-base/src/main/java/cn/iocoder/yudao/module/custom/vo/CarMainRespVO.java @@ -87,4 +87,7 @@ public class CarMainRespVO extends CarMain { @ExcelProperty("创建时间") private LocalDateTime createTime; + /**是否车主(0否1是)*/ + private String isOwner; + } \ No newline at end of file diff --git a/dl-module-base/src/main/java/cn/iocoder/yudao/module/custom/vo/CustomerMainRespVO.java b/dl-module-base/src/main/java/cn/iocoder/yudao/module/custom/vo/CustomerMainRespVO.java index 89595c93..11e23415 100644 --- a/dl-module-base/src/main/java/cn/iocoder/yudao/module/custom/vo/CustomerMainRespVO.java +++ b/dl-module-base/src/main/java/cn/iocoder/yudao/module/custom/vo/CustomerMainRespVO.java @@ -22,6 +22,6 @@ public class CustomerMainRespVO extends CustomerMain { /**扩展信息*/ List itemList; /**客户绑定车辆信息*/ - List carList; + List carList; } \ No newline at end of file diff --git a/dl-module-base/src/main/java/cn/iocoder/yudao/module/custom/vo/CustomerMainSaveReqVO.java b/dl-module-base/src/main/java/cn/iocoder/yudao/module/custom/vo/CustomerMainSaveReqVO.java index b1103645..0cb5b069 100644 --- a/dl-module-base/src/main/java/cn/iocoder/yudao/module/custom/vo/CustomerMainSaveReqVO.java +++ b/dl-module-base/src/main/java/cn/iocoder/yudao/module/custom/vo/CustomerMainSaveReqVO.java @@ -13,5 +13,7 @@ public class CustomerMainSaveReqVO extends CustomerMain { /**客户扩展信息表内容*/ private List itemList; + /**客户绑定车辆信息*/ + private List carList; } \ No newline at end of file diff --git a/dl-module-base/src/main/resources/mapper/custom/CarMainMapper.xml b/dl-module-base/src/main/resources/mapper/custom/CarMainMapper.xml index 2f42e396..7690bf41 100644 --- a/dl-module-base/src/main/resources/mapper/custom/CarMainMapper.xml +++ b/dl-module-base/src/main/resources/mapper/custom/CarMainMapper.xml @@ -90,13 +90,15 @@ - SELECT - + ,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 \ No newline at end of file