From 8f35f4d9f2f1702cfdaf6b36599d4a2ed6c290b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=B0=8F=E6=9E=97?= <320730042@qq.com> Date: Wed, 5 Jun 2024 17:59:50 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=AE=A2=E6=88=B7=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bellmann/common/result/ResultCode.java | 5 +- .../controller/CustomerController.java | 27 ++++++-- .../bellmann/converter/CustomerConverter.java | 3 + .../converter/DeviceStaticConverter.java | 8 +-- .../com/bellmann/mapper/CustomerMapper.java | 2 +- .../bellmann/mapper/DeviceStaticMapper.java | 4 +- .../bellmann/model/entity/DeviceStatic.java | 2 +- .../com/bellmann/model/form/CustomForm.java | 44 ++++++++++++ .../com/bellmann/model/query/SelectQuery.java | 2 +- .../com/bellmann/service/CustomerService.java | 10 +++ .../service/impl/CustomerServiceImpl.java | 67 +++++++++++++++++++ .../service/impl/DeviceStaticServiceImpl.java | 14 ++-- .../resources/mapper/DeviceStaticMapper.xml | 17 +++-- 13 files changed, 178 insertions(+), 27 deletions(-) create mode 100644 src/main/java/com/bellmann/model/form/CustomForm.java diff --git a/src/main/java/com/bellmann/common/result/ResultCode.java b/src/main/java/com/bellmann/common/result/ResultCode.java index 16b6ddf..5915272 100644 --- a/src/main/java/com/bellmann/common/result/ResultCode.java +++ b/src/main/java/com/bellmann/common/result/ResultCode.java @@ -99,7 +99,10 @@ public enum ResultCode implements IResultCode, Serializable { TR069_BINDING_SERVICE("F0009","TR069数据模型已经和业务绑定"), CUSTOM_NOT_FIND("F0010", "客户不存在"), - DEV_DOMAIN_MAP_NOT_FOUNT("F0011", "传入的设备软件版本和系统管理域映射不存在"); + DEV_DOMAIN_MAP_NOT_FOUNT("F0011", "传入的设备软件版本和系统管理域映射不存在"), + EXIST_USER_DEV("F0012","存在该用户的设备"), + DEV_ALREADY_CUSTOM("F0013","设备已经绑定客户"), + ; @Override public String getCode() { return code; diff --git a/src/main/java/com/bellmann/controller/CustomerController.java b/src/main/java/com/bellmann/controller/CustomerController.java index 7e7ae29..aacbbe2 100644 --- a/src/main/java/com/bellmann/controller/CustomerController.java +++ b/src/main/java/com/bellmann/controller/CustomerController.java @@ -2,16 +2,17 @@ package com.bellmann.controller; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.bellmann.common.result.PageResult; +import com.bellmann.common.result.Result; +import com.bellmann.model.form.CustomForm; import com.bellmann.model.query.SelectQuery; import com.bellmann.model.vo.CustomerVO; import com.bellmann.service.CustomerService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import lombok.RequiredArgsConstructor; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; + +import java.util.List; @Tag(name = "17.客户管理") @@ -22,9 +23,25 @@ public class CustomerController { private final CustomerService customerService; @PostMapping("customer-page") - @Operation(summary = "资源管理-设备管理表格接口") + @Operation(summary = "客户管理-page") public PageResult resourcePage(@RequestBody SelectQuery query){ Page page = customerService.resourcePage(query); return PageResult.success(page); } + @PutMapping("update-status/{customId}/{status}") + @Operation(summary = "修改客户状态") + public Result updateStatus(@PathVariable Long customId, @PathVariable String status){ + return customerService.updateStatus(customId,status); + } + @PostMapping("delete-custom") + @Operation(summary = "修改客户状态") + public Result deleteCustom(@RequestBody List ids){ + return customerService.deleteCustom(ids); + } + + @PostMapping("add-custom") + @Operation(summary = "新增客户") + public Result addCustom(@RequestBody CustomForm form){ + return customerService.addCustom(form); + } } diff --git a/src/main/java/com/bellmann/converter/CustomerConverter.java b/src/main/java/com/bellmann/converter/CustomerConverter.java index b31d528..091a18d 100644 --- a/src/main/java/com/bellmann/converter/CustomerConverter.java +++ b/src/main/java/com/bellmann/converter/CustomerConverter.java @@ -1,6 +1,7 @@ package com.bellmann.converter; import com.bellmann.model.entity.Customer; +import com.bellmann.model.form.CustomForm; import com.bellmann.model.vo.EquipmentCustomerVO; import org.mapstruct.Mapper; @@ -9,4 +10,6 @@ import org.mapstruct.Mapper; public interface CustomerConverter { EquipmentCustomerVO entityE2EquipmentVO(Customer customer); + + Customer form2Entity(CustomForm form); } diff --git a/src/main/java/com/bellmann/converter/DeviceStaticConverter.java b/src/main/java/com/bellmann/converter/DeviceStaticConverter.java index 6a81e9b..0f52c44 100644 --- a/src/main/java/com/bellmann/converter/DeviceStaticConverter.java +++ b/src/main/java/com/bellmann/converter/DeviceStaticConverter.java @@ -1,5 +1,6 @@ package com.bellmann.converter; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.bellmann.model.bo.EquipmentBO; import com.bellmann.model.entity.DeviceStatic; import com.bellmann.model.form.EquipmentAddForm; @@ -8,8 +9,6 @@ import org.mapstruct.Mapper; import org.mapstruct.Mapping; import org.mapstruct.Mappings; -import java.util.List; - @Mapper(componentModel = "spring") public interface DeviceStaticConverter { @@ -20,9 +19,8 @@ public interface DeviceStaticConverter { @Mapping(target = "devOnline", expression = "java(com.bellmann.common.base.IBaseEnum.getLabelByValue(bo.getDevOnline(), com.bellmann.common.enums.DevOnlineEnum.class))") }) - EquipmentVO resourceBOList2VOList(EquipmentBO bo); - List resourceBOList2VOList(List list); - + EquipmentVO resourceBOPage2VOPage(EquipmentBO bo); DeviceStatic resourceForm2VOEntity(EquipmentAddForm form); + Page resourceBOPage2VOPage(Page boPage); } diff --git a/src/main/java/com/bellmann/mapper/CustomerMapper.java b/src/main/java/com/bellmann/mapper/CustomerMapper.java index 9514740..a77ebb0 100644 --- a/src/main/java/com/bellmann/mapper/CustomerMapper.java +++ b/src/main/java/com/bellmann/mapper/CustomerMapper.java @@ -11,5 +11,5 @@ import java.util.List; @Mapper public interface CustomerMapper extends BaseMapper { - List resourcePage(Page page, @Param("column") String column, @Param("value") String value); + List resourcePage(Page page, @Param("column") String column, @Param("value") Object value); } diff --git a/src/main/java/com/bellmann/mapper/DeviceStaticMapper.java b/src/main/java/com/bellmann/mapper/DeviceStaticMapper.java index 8a6624f..52d1cf6 100644 --- a/src/main/java/com/bellmann/mapper/DeviceStaticMapper.java +++ b/src/main/java/com/bellmann/mapper/DeviceStaticMapper.java @@ -8,11 +8,9 @@ import com.bellmann.model.vo.EquipmentDetailVO; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; -import java.util.List; - @Mapper public interface DeviceStaticMapper extends BaseMapper { - List resourcePage(Page page, @Param("column") String column, @Param("value") String value); + Page resourcePage(Page page, @Param("column") String column, @Param("value") Object value); EquipmentDetailVO detailInfo(@Param("devId") Long devId); diff --git a/src/main/java/com/bellmann/model/entity/DeviceStatic.java b/src/main/java/com/bellmann/model/entity/DeviceStatic.java index 984f992..e37d2cf 100644 --- a/src/main/java/com/bellmann/model/entity/DeviceStatic.java +++ b/src/main/java/com/bellmann/model/entity/DeviceStatic.java @@ -20,7 +20,7 @@ public class DeviceStatic implements Serializable { private Long typeAndVerId; @TableField("cust_id") - private String customId; + private Long customId; private Long regionAreaId; diff --git a/src/main/java/com/bellmann/model/form/CustomForm.java b/src/main/java/com/bellmann/model/form/CustomForm.java new file mode 100644 index 0000000..45370ad --- /dev/null +++ b/src/main/java/com/bellmann/model/form/CustomForm.java @@ -0,0 +1,44 @@ +package com.bellmann.model.form; + +import com.baomidou.mybatisplus.annotation.TableField; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +@Data +@Schema(description = "客户表单") +public class CustomForm { + + @Schema(description = "客户ID") + private Long custId; + + @Schema(description = "系统管理域") + private Long regionAreaId; + + @Schema(description = "客户账号") + private String customAccount; + + @Schema(description = "客户名称" ) + private String customName; + + @Schema(description = "客户地址") + private String customAddr; + + @Schema(description = "联系人方式") + private String contactType; + + @Schema(description = "客户类型") + private String customType; + + @Schema(description = "客户状态") + private String customStatus; + + @Schema(description = "客户端口号") + private String customRemark1; + + @Schema(description = "接入电话号码") + private String customRemark2; + + @TableField(value = "客户身份证号码") + private String customRemark3; + +} diff --git a/src/main/java/com/bellmann/model/query/SelectQuery.java b/src/main/java/com/bellmann/model/query/SelectQuery.java index f3c7337..f306058 100644 --- a/src/main/java/com/bellmann/model/query/SelectQuery.java +++ b/src/main/java/com/bellmann/model/query/SelectQuery.java @@ -10,5 +10,5 @@ public class SelectQuery extends BasePageQuery { private String selectName; - private String selectValue; + private Object selectValue; } diff --git a/src/main/java/com/bellmann/service/CustomerService.java b/src/main/java/com/bellmann/service/CustomerService.java index 000021d..1e7e891 100644 --- a/src/main/java/com/bellmann/service/CustomerService.java +++ b/src/main/java/com/bellmann/service/CustomerService.java @@ -1,9 +1,19 @@ package com.bellmann.service; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.bellmann.common.result.Result; +import com.bellmann.model.form.CustomForm; import com.bellmann.model.query.SelectQuery; import com.bellmann.model.vo.CustomerVO; +import java.util.List; + public interface CustomerService { Page resourcePage(SelectQuery query); + + Result updateStatus(Long customId, String status); + + Result deleteCustom(List ids); + + Result addCustom(CustomForm form); } diff --git a/src/main/java/com/bellmann/service/impl/CustomerServiceImpl.java b/src/main/java/com/bellmann/service/impl/CustomerServiceImpl.java index c791cc6..472e8f8 100644 --- a/src/main/java/com/bellmann/service/impl/CustomerServiceImpl.java +++ b/src/main/java/com/bellmann/service/impl/CustomerServiceImpl.java @@ -1,25 +1,42 @@ package com.bellmann.service.impl; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.bellmann.common.base.IBaseEnum; import com.bellmann.common.constant.SecurityConstants; import com.bellmann.common.enums.CustomStatusEnum; import com.bellmann.common.enums.CustomTypeEnum; +import com.bellmann.common.exception.BusinessException; +import com.bellmann.common.result.Result; +import com.bellmann.common.result.ResultCode; +import com.bellmann.converter.CustomerConverter; import com.bellmann.mapper.CustomerMapper; +import com.bellmann.mapper.DeviceStaticMapper; +import com.bellmann.model.entity.Customer; +import com.bellmann.model.entity.DeviceStatic; +import com.bellmann.model.form.CustomForm; import com.bellmann.model.query.SelectQuery; import com.bellmann.model.vo.CustomerVO; import com.bellmann.service.CustomerService; import lombok.RequiredArgsConstructor; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import java.time.LocalDateTime; import java.util.List; @Service @RequiredArgsConstructor public class CustomerServiceImpl implements CustomerService { private final CustomerMapper customerMapper; + private final RedisTemplate redisTemplate; + + private final DeviceStaticMapper deviceStaticMapper; + + private final CustomerConverter customerConverter; @Override public Page resourcePage(SelectQuery query) { int pageNum = query.getPageNum(); @@ -35,4 +52,54 @@ public class CustomerServiceImpl implements CustomerService { }); return page.setRecords(list); } + + @Override + public Result updateStatus(Long customId, String status) { + if(customId==null||status==null){ + return Result.failed(ResultCode.PARAM_ERROR); + } + if (CustomStatusEnum.SIGN_OUT.getValue().equals(status)) { + Long count = deviceStaticMapper.selectCount(new LambdaQueryWrapper() + .eq(DeviceStatic::getCustomId, customId) + ); + if (count > 0L) { + return Result.failed(ResultCode.EXIST_USER_DEV); + } + } + customerMapper.update(null,new LambdaUpdateWrapper() + .eq(Customer::getCustId,customId) + .set(Customer::getCustomStatus,status) + ); + return Result.success(); + } + + @Override + @Transactional + public Result deleteCustom(List ids) { + if (ids.isEmpty()){ + return Result.failed(ResultCode.IDS_IS_NULL); + } + for (Long customId:ids){ + Long count = deviceStaticMapper.selectCount(new LambdaQueryWrapper() + .eq(DeviceStatic::getCustomId, customId) + ); + if (count > 0L) { + throw new BusinessException(ResultCode.EXIST_USER_DEV); + } + customerMapper.update(null,new LambdaUpdateWrapper() + .eq(Customer::getCustId,customId) + .set(Customer::getCustomStatus,CustomStatusEnum.SIGN_OUT.getValue()) + ); + } + return Result.success(); + } + + @Override + public Result addCustom(CustomForm form) { + Customer customer = customerConverter.form2Entity(form); + customer.setCustomCreateTime(LocalDateTime.now()); + customer.setCustomModifyTime(LocalDateTime.now()); + customerMapper.insert(customer); + return Result.success(customer.getCustId()); + } } diff --git a/src/main/java/com/bellmann/service/impl/DeviceStaticServiceImpl.java b/src/main/java/com/bellmann/service/impl/DeviceStaticServiceImpl.java index c94b9e1..3df16af 100644 --- a/src/main/java/com/bellmann/service/impl/DeviceStaticServiceImpl.java +++ b/src/main/java/com/bellmann/service/impl/DeviceStaticServiceImpl.java @@ -71,12 +71,8 @@ public class DeviceStaticServiceImpl implements DeviceStaticService { int pageNum = query.getPageNum(); int pageSize = query.getPageSize(); Page page = new Page<>(pageNum,pageSize); - List list = deviceStaticMapper.resourcePage(page,query.getSelectName(),query.getSelectValue()); - List voList = deviceStaticConverter.resourceBOList2VOList(list); - Page vp = new Page<>(pageNum,pageSize); - vp.setTotal(page.getTotal()); - vp.setRecords(voList); - return vp; + Page boPage = deviceStaticMapper.resourcePage(page,query.getSelectName(),query.getSelectValue()); + return deviceStaticConverter.resourceBOPage2VOPage(boPage); } @Override @@ -190,6 +186,12 @@ public class DeviceStaticServiceImpl implements DeviceStaticService { @Override public Result bindingCustom(Long customId, Long devId) { + DeviceStatic deviceStatic = deviceStaticMapper.selectOne(new LambdaQueryWrapper() + .eq(DeviceStatic::getDevId, devId) + ); + if(deviceStatic.getCustomId()!=null){ + return Result.failed(ResultCode.DEV_ALREADY_CUSTOM); + } Customer customer = customerManager.findByCustomId(customId); if (customer==null){ return Result.failed(ResultCode.CUSTOM_NOT_FIND); diff --git a/src/main/resources/mapper/DeviceStaticMapper.xml b/src/main/resources/mapper/DeviceStaticMapper.xml index 9c11ab8..41e28cb 100644 --- a/src/main/resources/mapper/DeviceStaticMapper.xml +++ b/src/main/resources/mapper/DeviceStaticMapper.xml @@ -22,14 +22,23 @@ dy.dev_online_time FROM itms_device_static s - LEFT JOIN ITMS_DEVICE_DYNAMIC dy ON s.DEV_ID = dy.DEV_ID - LEFT JOIN itms_device_type_ver v ON s.type_and_ver_id = v.type_and_ver_id - LEFT JOIN itms_device_type T ON v.dev_type_id = T.dev_type_id - LEFT JOIN itms_device_type_ver_detail d ON v.type_and_ver_id = d.type_and_ver_id + + INNER JOIN itms_customer ON itms_customer.cust_id = s.cust_id + + INNER JOIN ITMS_DEVICE_DYNAMIC dy ON s.DEV_ID = dy.DEV_ID + INNER JOIN itms_device_type_ver v ON s.type_and_ver_id = v.type_and_ver_id + INNER JOIN itms_device_type T ON v.dev_type_id = T.dev_type_id + INNER JOIN itms_device_type_ver_detail d ON v.type_and_ver_id = d.type_and_ver_id and s.dev_ad_no = #{value} + + and itms_customer.cust_name = #{value} + + + and s.cust_id = #{value} +