Commit f3bce9aa by jianan

Fna接口15

parent 8e9f2f76
......@@ -58,53 +58,10 @@ public class ApiCustomerController {
@PostMapping("/add")
@Transactional(rollbackFor = Exception.class)
public Result<String> addCustomer(@RequestBody CustomerAddRequest customerAddRequest, HttpServletRequest request) {
if (customerAddRequest == null) {
return Result.fail(ErrorCode.PARAMS_ERROR.getCode(), ErrorCode.PARAMS_ERROR.getMessage());
}
// 校验 请求 对象中,参数是否全部为空
if (ValidateUtil.isAllFieldsNull(customerAddRequest)) {
throw new BusinessException(ErrorCode.PARAMS_ERROR.getCode(), ErrorCode.PARAMS_ERROR.getMessage());
}
// 客户主表信息
Customer customer = new Customer();
BeanUtils.copyProperties(customerAddRequest, customer);
// 客户扩展表信息
CustomerExpand customerExpand = customerService.getCustomerExpand(customerAddRequest);
// 客户主表业务唯一id
customer.setCustomerBizId(RandomStringGenerator.generateBizId16("customer"));
boolean result = customerService.save(customer);
if (!result) {
return Result.fail(ErrorCode.OPERATION_ERROR.getCode(), ErrorCode.OPERATION_ERROR.getMessage());
}
// 客户扩展表信息,非空时,写入数据库
if (!ValidateUtil.isAllFieldsNull(customerAddRequest)) {
// 主表业务唯一id
customerExpand.setCustomerBizId(customer.getCustomerBizId());
// 客户扩展表业务唯一id
customerExpand.setCustomerExpandBizId(RandomStringGenerator.generateBizId16("customer_expand"));
// 写入数据库
boolean resultExpand = customerExpandService.save(customerExpand);
if (!resultExpand) {
return Result.fail(ErrorCode.OPERATION_ERROR.getCode(), ErrorCode.OPERATION_ERROR.getMessage());
}
// 更新客户主表
Customer updateCustomer = new Customer();
updateCustomer.setId(customer.getId());
updateCustomer.setCustomerExpandBizId(customerExpand.getCustomerBizId());
customerService.updateById(updateCustomer);
}
// Result<GetLoginInfoResponse> loginUser = apiSysUserFeignClient.getLoginInfo();
// customer.setUserBizId(loginUser.getData().getApiLoginUserInfoResponse().getUserBizId());
// 返回新写入的数据 id
String newFnaId = customer.getCustomerBizId();
return Result.success(newFnaId);
return Result.success(customerService.addCustomer(customerAddRequest));
}
/**
......
package com.yd.csf.api.controller;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yd.common.exception.BusinessException;
import com.yd.common.result.Result;
import com.yd.common.utils.RandomStringGenerator;
import com.yd.csf.api.service.ApiAppointmentService;
import com.yd.csf.feign.dto.appointment.ApiAppointmentInfoDto;
import com.yd.csf.feign.response.appointment.ApiAppointmentDetailResponse;
import com.yd.csf.service.common.ErrorCode;
import com.yd.csf.service.dto.DeleteFnaRequest;
import com.yd.csf.service.dto.FnaAddRequest;
import com.yd.csf.service.dto.FnaQueryRequest;
import com.yd.csf.service.dto.FnaUpdateRequest;
import com.yd.csf.service.model.Appointment;
import com.yd.csf.service.model.Customer;
import com.yd.csf.service.model.Fna;
import com.yd.csf.service.service.CustomerService;
......@@ -25,7 +21,6 @@ import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
......@@ -80,26 +75,7 @@ public class ApiFnaController {
if (deleteRequest == null || deleteRequest.getId() == null) {
throw new BusinessException(ErrorCode.PARAMS_ERROR.getCode(), ErrorCode.PARAMS_ERROR.getMessage());
}
Long id = deleteRequest.getId();
// 判断是否存在
Fna oldFna = fnaService.getById(id);
if (oldFna == null) {
throw new BusinessException(ErrorCode.NOT_FOUND_ERROR.getCode(), ErrorCode.NOT_FOUND_ERROR.getMessage());
}
// 仅本人或管理员可删除
// if (!oldFna.getUserId().equals(user.getId()) && !userService.isAdmin(request)) {
// throw new BusinessException(ErrorCode.NO_AUTH_ERROR);
// }
// 操作数据库
Fna updateFna = new Fna();
updateFna.setId(id);
updateFna.setIsDeleted(1);
boolean result = fnaService.updateById(updateFna);
if (!result) {
return Result.fail(ErrorCode.OPERATION_ERROR.getCode(), ErrorCode.OPERATION_ERROR.getMessage());
}
return Result.success(true);
return Result.success(fnaService.deleteFna(deleteRequest));
}
/**
......
......@@ -7,6 +7,7 @@ import lombok.Data;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
/**
* 创建customer请求
......@@ -59,13 +60,13 @@ public class CustomerAddRequest implements Serializable {
/**
* 称谓
*/
@Schema(description = "称谓")
@Schema(description = "称谓 字典值: csf_customer_title")
private String title;
/**
* 性别
*/
@Schema(description = "性别")
@Schema(description = "性别 字典值: sys_gender")
private Object gender;
/**
......@@ -113,7 +114,7 @@ public class CustomerAddRequest implements Serializable {
/**
* 是否吸烟
*/
@Schema(description = "是否吸烟")
@Schema(description = "是否吸烟 字典值: sys_no_yes")
private String smoke;
/**
......@@ -137,7 +138,7 @@ public class CustomerAddRequest implements Serializable {
/**
* 证件类型
*/
@Schema(description = "证件类型")
@Schema(description = "证件类型 字典值: csf_id_type")
private String idType;
/**
......@@ -161,7 +162,7 @@ public class CustomerAddRequest implements Serializable {
/**
* 婚姻状况
*/
@Schema(description = "婚姻状况")
@Schema(description = "婚姻状况 字典值: csf_marriage")
private Object marriage;
/**
......@@ -173,7 +174,7 @@ public class CustomerAddRequest implements Serializable {
/**
* 教育程度
*/
@Schema(description = "教育程度")
@Schema(description = "教育程度 字典值: csf_education")
private Object education;
/**
......@@ -205,28 +206,30 @@ public class CustomerAddRequest implements Serializable {
/**
* 是否长期出国
*/
@Schema(description = "是否长期出国")
@Schema(description = "是否长期出国 字典值: sys_no_yes")
private String longtimeAbroad;
/**
* 居住地址
*/
private AddressVO residenceAddress;
/**
* 住宅地址
*/
private AddressVO residentialAddress;
private List<AddressVO> addressList;
/**
* 邮寄地址
*/
private AddressVO mailingAddress;
/**
* 公司地址
* 居住地址
*/
private AddressVO companyAddress;
// private AddressVO residenceAddress;
//
// /**
// * 住宅地址
// */
// private AddressVO residentialAddress;
//
// /**
// * 邮寄地址
// */
// private AddressVO mailingAddress;
//
// /**
// * 公司地址
// */
// private AddressVO companyAddress;
/**
* 公司名称
......
package com.yd.csf.service.dto;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.yd.common.dto.PageDto;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
......@@ -21,12 +22,14 @@ public class FnaQueryRequest extends PageDto implements Serializable {
* 创建时间开始
*/
@Schema(description = "创建时间开始")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private LocalDateTime startTime;
/**
* 创建时间结束
*/
@Schema(description = "创建时间结束")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private LocalDateTime endTime;
/**
......@@ -38,7 +41,7 @@ public class FnaQueryRequest extends PageDto implements Serializable {
/**
* 状态
*/
@Schema(description = "状态 UNCOMPLETED-未完成 COMPLETED-已完成")
@Schema(description = "状态 字典值: csf_fna_status")
private String status;
/**
......
......@@ -27,6 +27,11 @@ public class Customer implements Serializable {
private String customerBizId;
/**
* 用户业务ID
*/
private String userBizId;
/**
* 自定义代码
*/
private String customCode;
......
......@@ -28,4 +28,6 @@ public interface CustomerService extends IService<Customer> {
Page<CustomerVO> getCustomerVOPage(Page<Customer> customerPage);
Customer getByCustomerBizId(String customerBizId);
String addCustomer(CustomerAddRequest customerAddRequest);
}
......@@ -2,6 +2,7 @@ package com.yd.csf.service.service;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yd.csf.service.dto.DeleteFnaRequest;
import com.yd.csf.service.dto.FnaAddRequest;
import com.yd.csf.service.dto.FnaQueryRequest;
import com.baomidou.mybatisplus.extension.service.IService;
......@@ -44,4 +45,6 @@ public interface FnaService extends IService<Fna> {
Fna getByBizId(String fnaBizId);
boolean updateByBizId(Fna fna);
Boolean deleteFna(DeleteFnaRequest deleteRequest);
}
......@@ -6,6 +6,10 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.gson.Gson;
import com.yd.common.exception.BusinessException;
import com.yd.common.result.Result;
import com.yd.common.utils.RandomStringGenerator;
import com.yd.csf.service.common.ErrorCode;
import com.yd.csf.service.dao.CustomerMapper;
import com.yd.csf.service.dto.CustomerAddRequest;
import com.yd.csf.service.dto.CustomerQueryRequest;
......@@ -14,12 +18,14 @@ import com.yd.csf.service.model.Customer;
import com.yd.csf.service.model.CustomerExpand;
import com.yd.csf.service.service.CustomerExpandService;
import com.yd.csf.service.service.CustomerService;
import com.yd.csf.service.utils.ValidateUtil;
import com.yd.csf.service.vo.AddressVO;
import com.yd.csf.service.vo.CustomerExpandVO;
import com.yd.csf.service.vo.CustomerVO;
import com.yd.csf.service.vo.FnaVO;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.List;
......@@ -41,6 +47,11 @@ public class CustomerServiceImpl extends ServiceImpl<CustomerMapper, Customer>
@Resource
private CustomerExpandService customerExpandService;
@Resource
private CustomerService customerService;
@Override
public CustomerVO getCustomerVO(Customer customer) {
return CustomerVO.objToVo(customer);
......@@ -109,6 +120,51 @@ public class CustomerServiceImpl extends ServiceImpl<CustomerMapper, Customer>
return baseMapper.selectOne(new LambdaQueryWrapper<Customer>().eq(Customer::getCustomerBizId, customerBizId));
}
@Override
@Transactional(rollbackFor = Exception.class)
public String addCustomer(CustomerAddRequest customerAddRequest) {
// 校验 请求 对象中,参数是否全部为空
if (ValidateUtil.isAllFieldsNull(customerAddRequest)) {
throw new BusinessException(ErrorCode.PARAMS_ERROR.getCode(), ErrorCode.PARAMS_ERROR.getMessage());
}
// 客户主表信息
Customer customer = new Customer();
BeanUtils.copyProperties(customerAddRequest, customer);
// 客户扩展表信息
CustomerExpand customerExpand = customerService.getCustomerExpand(customerAddRequest);
// 获取 userBizId
// SecurityUtil.getLoginUser();
// customer.setUserBizId("");
// 客户主表业务唯一id
customer.setCustomerBizId(RandomStringGenerator.generateBizId16("customer"));
boolean result = customerService.save(customer);
if (!result) {
throw new BusinessException(ErrorCode.OPERATION_ERROR.getCode(), ErrorCode.OPERATION_ERROR.getMessage());
}
// 客户扩展表信息,非空时,写入数据库
if (!ValidateUtil.isAllFieldsNull(customerAddRequest)) {
// 主表业务唯一id
customerExpand.setCustomerBizId(customer.getCustomerBizId());
// 客户扩展表业务唯一id
customerExpand.setCustomerExpandBizId(RandomStringGenerator.generateBizId16("customer_expand"));
// 写入数据库
boolean resultExpand = customerExpandService.save(customerExpand);
if (!resultExpand) {
throw new BusinessException(ErrorCode.OPERATION_ERROR.getCode(), ErrorCode.OPERATION_ERROR.getMessage());
}
// 更新客户主表
Customer updateCustomer = new Customer();
updateCustomer.setId(customer.getId());
updateCustomer.setCustomerExpandBizId(customerExpand.getCustomerBizId());
customerService.updateById(updateCustomer);
}
return customer.getCustomerBizId();
}
}
......
......@@ -6,10 +6,12 @@ import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yd.common.exception.BusinessException;
import com.yd.common.result.Result;
import com.yd.common.utils.RandomStringGenerator;
import com.yd.csf.service.common.ErrorCode;
import com.yd.csf.service.dao.FnaMapper;
import com.yd.csf.service.dto.DeleteFnaRequest;
import com.yd.csf.service.dto.FnaAddRequest;
import com.yd.csf.service.dto.FnaQueryRequest;
import com.yd.csf.service.model.Fna;
......@@ -207,4 +209,21 @@ public class FnaServiceImpl extends ServiceImpl<FnaMapper, Fna> implements FnaSe
return baseMapper.update(fna, updateWrapper) > 0;
}
@Override
@Transactional(rollbackFor = Exception.class)
public Boolean deleteFna(DeleteFnaRequest deleteRequest) {
Long id = deleteRequest.getId();
// 判断是否存在
Fna oldFna = this.getById(id);
if (oldFna == null) {
throw new BusinessException(ErrorCode.NOT_FOUND_ERROR.getCode(), ErrorCode.NOT_FOUND_ERROR.getMessage());
}
// 操作数据库
boolean result = this.removeById(id);
if (!result) {
throw new BusinessException(ErrorCode.OPERATION_ERROR.getCode(), ErrorCode.OPERATION_ERROR.getMessage());
}
return result;
}
}
......@@ -8,9 +8,15 @@ import java.io.Serializable;
@Data
@ToString
@Schema(description = "地址 residenceAddress-居住地址、residentialAddress-住宅地址、mailingAddress-邮寄地址、companyAddress-公司地址")
@Schema(description = "地址")
public class AddressVO implements Serializable {
/**
* 地址类型
*/
@Schema(description = "地址类型 residenceAddress-居住地址、residentialAddress-住宅地址、mailingAddress-邮寄地址、companyAddress-公司地址")
private String type;
@Schema(description = "区域")
private String region;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment