Commit 4f3200b4 by jianan

Fna接口47

parent 0fcfed7b
package com.yd.csf.api.controller;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yd.common.enums.ResultCode;
import com.yd.common.exception.BusinessException;
import com.yd.common.result.Result;
import com.yd.csf.api.service.ApiAppointmentService;
import com.yd.csf.feign.dto.appointment.ApiAppointmentInfoDto;
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.dto.*;
import com.yd.csf.service.model.Customer;
import com.yd.csf.service.model.Fna;
import com.yd.csf.service.service.CustomerService;
......@@ -54,7 +51,7 @@ public class ApiFnaController {
@Operation(summary = "新建流程")
public Result<Map<String, Object>> addFna(@RequestBody FnaAddRequest fnaAddRequest, HttpServletRequest request) {
if (fnaAddRequest == null) {
return Result.fail(ErrorCode.PARAMS_ERROR.getCode(), ErrorCode.PARAMS_ERROR.getMessage());
return Result.fail(ResultCode.PARAMS_ERROR.getCode(), ResultCode.PARAMS_ERROR.getMessage());
}
return Result.success(fnaService.addFna(fnaAddRequest));
}
......@@ -70,7 +67,7 @@ public class ApiFnaController {
@Operation(summary = "删除流程")
public Result<Boolean> deleteFna(@RequestBody DeleteFnaRequest deleteRequest, HttpServletRequest request) {
if (deleteRequest == null || StringUtils.isBlank(deleteRequest.getFnaBizId())) {
throw new BusinessException(ErrorCode.PARAMS_ERROR.getCode(), ErrorCode.PARAMS_ERROR.getMessage());
return Result.fail(ResultCode.PARAMS_ERROR.getCode(), ResultCode.PARAMS_ERROR.getMessage());
}
return Result.success(fnaService.deleteFna(deleteRequest));
}
......@@ -85,7 +82,7 @@ public class ApiFnaController {
@Operation(summary = "更新流程")
public Result<Boolean> updateFna(@RequestBody FnaUpdateRequest fnaUpdateRequest) {
if (fnaUpdateRequest == null || StringUtils.isBlank(fnaUpdateRequest.getFnaBizId())) {
throw new BusinessException(ErrorCode.PARAMS_ERROR.getCode(), ErrorCode.PARAMS_ERROR.getMessage());
throw new BusinessException(ResultCode.PARAMS_ERROR.getCode(), ResultCode.PARAMS_ERROR.getMessage());
}
String appointmentNo = null;
if (StringUtils.isNotBlank(fnaUpdateRequest.getAppointmentBizId())) {
......@@ -109,12 +106,12 @@ public class ApiFnaController {
@Operation(summary = "流程详情")
public Result<FnaVO> getFnaVOByBizId(String fnaBizId, HttpServletRequest request) {
if (StringUtils.isBlank(fnaBizId)) {
return Result.fail(ErrorCode.PARAMS_ERROR.getCode(), ErrorCode.PARAMS_ERROR.getMessage());
return Result.fail(ResultCode.PARAMS_ERROR.getCode(), ResultCode.PARAMS_ERROR.getMessage());
}
// 查询数据库
Fna fna = fnaService.getByBizId(fnaBizId);
if (fna == null) {
return Result.fail(ErrorCode.NOT_FOUND_ERROR.getCode(), ErrorCode.NOT_FOUND_ERROR.getMessage());
return Result.fail(ResultCode.NULL_ERROR.getCode(), ResultCode.NULL_ERROR.getMessage());
}
// 获取封装类
......@@ -139,26 +136,18 @@ public class ApiFnaController {
}
/**
* 分页获取fna列表(封装类)
* 生成副本
*
* @param fnaQueryRequest
* @param fnaCopyRequest
* @param request
* @return
*/
// @PostMapping("/list/page/vo")
// public Result<Page<Fna>> listFnaVOByPage(@RequestBody FnaQueryRequest fnaQueryRequest,
// HttpServletRequest request) {
// long current = fnaQueryRequest.getPageNo();
// long size = fnaQueryRequest.getPageSize();
//
// // 查询数据库
// Page<Fna> fnaPage = fnaService.page(new Page<>(current, size),
// fnaService.getQueryWrapper(fnaQueryRequest));
// // 获取封装类
//// return Result.success(fnaService.getFnaVOPage(fnaPage, request));
//
// return Result.success(fnaPage);
// }
@PostMapping("/copy")
@Operation(summary = "生成副本")
public Result<Map<String, Object>> copyFna(@RequestBody FnaCopyRequest fnaCopyRequest, HttpServletRequest request) {
if (fnaCopyRequest == null || StringUtils.isBlank(fnaCopyRequest.getFnaBizId())) {
return Result.fail(ResultCode.PARAMS_ERROR.getCode(), ResultCode.PARAMS_ERROR.getMessage());
}
return Result.success(fnaService.copyFna(fnaCopyRequest));
}
}
......@@ -11,6 +11,7 @@ import com.yd.csf.service.model.Fna;
*/
public interface FnaMapper extends BaseMapper<Fna> {
boolean updateFnaNoById(String fnaNo, Long id);
}
......
package com.yd.csf.service.dto;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
@Data
public class FnaCopyRequest {
/**
* 原流程业务ID
*/
@Schema(description = "原流程业务ID")
private String fnaBizId;
}
package com.yd.csf.service.enums;
/**
* fna状态枚举 'DRAFT'-草稿, 'UNCOMPLETED'-未完成, 'COMPLETED'-已完成
*/
public enum FnaStatusEnum {
DRAFT("草稿", "DRAFT"),
UNCOMPLETED("未完成", "UNCOMPLETED"),
COMPLETED("已完成", "COMPLETED"),
;
//字典项标签(名称)
private String itemLabel;
//字典项值
private String itemValue;
//构造函数
FnaStatusEnum(String itemLabel, String itemValue) {
this.itemLabel = itemLabel;
this.itemValue = itemValue;
}
public String getItemLabel() {
return itemLabel;
}
public String getItemValue() {
return itemValue;
}
}
......@@ -32,6 +32,11 @@ public class Fna implements Serializable {
private String fnaNo;
/**
* 租户编码
*/
private String tenantCode;
/**
* 系统用户唯一业务ID
*/
private String userBizId;
......
......@@ -56,4 +56,6 @@ public interface FnaFormService extends IService<FnaForm> {
FnaForm getFnaForm(FnaFormUpdateRequest fnaFormUpdateRequest);
FnaForm getByFnaFormBizId(String fnaFormBizId);
PersonalData getPersonalDataObj(Object personalData);
}
......@@ -2,11 +2,8 @@ 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.yd.csf.service.dto.*;
import com.baomidou.mybatisplus.extension.service.IService;
import com.yd.csf.service.dto.FnaUpdateRequest;
import com.yd.csf.service.model.Fna;
import com.yd.csf.service.vo.FnaVO;
......@@ -54,4 +51,6 @@ public interface FnaService extends IService<Fna> {
Fna queryOne(String fnaBizId);
Boolean updateFna(FnaUpdateRequest fnaUpdateRequest, String appointmentNo);
Map<String, Object> copyFna(FnaCopyRequest fnaCopyRequest);
}
......@@ -247,4 +247,12 @@ public class FnaFormServiceImpl extends ServiceImpl<FnaFormMapper, FnaForm> impl
return baseMapper.selectOne(queryWrapper);
}
@Override
public PersonalData getPersonalDataObj(Object personalData) {
if (personalData == null) {
return new PersonalData();
}
return GSON.fromJson(personalData.toString(), PersonalData.class);
}
}
......@@ -7,20 +7,18 @@ 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.google.gson.Gson;
import com.yd.auth.core.dto.AuthUserDto;
import com.yd.auth.core.utils.SecurityUtil;
import com.yd.common.constant.CommonConstant;
import com.yd.common.enums.CommonEnum;
import com.yd.common.enums.ResultCode;
import com.yd.common.exception.BusinessException;
import com.yd.common.result.Result;
import com.yd.common.utils.RandomStringGenerator;
import com.yd.csf.feign.dto.appointment.ApiAppointmentInfoDto;
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.dto.FnaUpdateRequest;
import com.yd.csf.service.dto.*;
import com.yd.csf.service.enums.FnaStatusEnum;
import com.yd.csf.service.model.Customer;
import com.yd.csf.service.model.Fna;
import com.yd.csf.service.model.FnaForm;
......@@ -39,10 +37,7 @@ import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.stream.Collectors;
/**
......@@ -53,17 +48,13 @@ import java.util.stream.Collectors;
@Slf4j
public class FnaServiceImpl extends ServiceImpl<FnaMapper, Fna> implements FnaService {
// @Resource
// private UserService userService;
@Autowired
private FnaFormService fnaFormService;
@Resource
private CustomerService customerService;
@Resource
private AppointmentServiceImpl appointmentService;
private final static Gson GSON = new Gson();
@Override
@Transactional(rollbackFor = Exception.class)
......@@ -76,11 +67,7 @@ public class FnaServiceImpl extends ServiceImpl<FnaMapper, Fna> implements FnaSe
String userBizId = authUserDto.getUserBizId();
fna.setUserBizId(userBizId);
String fnaBizId = RandomStringGenerator.generateBizId16(CommonEnum.UID_TYPE_FNA.getCode());
fna.setFnaBizId(fnaBizId);
fna.setFnaNo(generateFnaNo(fnaAddRequest.getTenantCode(), fnaBizId));
fna.setFnaBizId(RandomStringGenerator.generateBizId16(CommonEnum.UID_TYPE_FNA.getCode()));
fna.setCreatorId(userBizId);
fna.setUpdaterId(userBizId);
fna.setStatus("DRAFT");
......@@ -91,28 +78,38 @@ public class FnaServiceImpl extends ServiceImpl<FnaMapper, Fna> implements FnaSe
// 写入数据库
boolean result = this.save(fna);
if (!result) {
throw new BusinessException(ErrorCode.OPERATION_ERROR.getCode(), ErrorCode.OPERATION_ERROR.getMessage());
throw new BusinessException(ResultCode.FAIL.getCode(), ResultCode.FAIL.getMessage());
}
// 生成fna编号
String fnaNo = generateFnaNo(fnaAddRequest.getTenantCode(), fna.getId());
// 更新fna
baseMapper.updateFnaNoById(fnaNo, fna.getId());
// 组装返回
Map<String, Object> map = new HashMap<>();
map.put("fnaBizId", fnaBizId);
map.put("fnaBizId", fna.getFnaBizId());
return map;
}
/**
* 生成f流程编号
* 流程编号格式:租户编号-流程类型-创建时间(YY-MM-DD)-bizld
* 流程编号格式:租户编号-流程类型-创建时间(YY-MM-DD)-id
*
* @param tenantCode
* @param fnaBizId
* @param fnaId
* @return
*/
private String generateFnaNo(String tenantCode, String fnaBizId) {
private String generateFnaNo(String tenantCode, Long fnaId) {
String defaultTenantCode = "CSF";
if (StringUtils.isBlank(tenantCode)) {
tenantCode = defaultTenantCode;
}
return tenantCode + "-B-" + LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMdd")) + "-" + fnaBizId;
// 如果 fnaId 不足 4位,则补足 4位,超过则不变
String fnaIdstr = String.valueOf(fnaId);
if (fnaId < 1000L) {
fnaIdstr = String.format("%04d", fnaId);
}
return tenantCode + "-B-" + LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMdd")) + "-" + fnaIdstr;
}
/**
......@@ -256,12 +253,12 @@ public class FnaServiceImpl extends ServiceImpl<FnaMapper, Fna> implements FnaSe
// 判断是否存在
Fna oldFna = this.getByBizId(fnaBizId);
if (oldFna == null) {
throw new BusinessException(ErrorCode.NOT_FOUND_ERROR.getCode(), ErrorCode.NOT_FOUND_ERROR.getMessage());
throw new BusinessException(ResultCode.NULL_ERROR.getCode(), ResultCode.NULL_ERROR.getMessage());
}
// 操作数据库
boolean result = this.removeById(oldFna.getId());
if (!result) {
throw new BusinessException(ErrorCode.OPERATION_ERROR.getCode(), ErrorCode.OPERATION_ERROR.getMessage());
throw new BusinessException(ResultCode.FAIL.getCode(), ResultCode.FAIL.getMessage());
}
return result;
}
......@@ -282,7 +279,7 @@ public class FnaServiceImpl extends ServiceImpl<FnaMapper, Fna> implements FnaSe
String fnaBizId = fnaUpdateRequest.getFnaBizId();
Fna fna = this.getByBizId(fnaBizId);
if (fna == null) {
throw new BusinessException(ErrorCode.NOT_FOUND_ERROR.getCode(), ErrorCode.NOT_FOUND_ERROR.getMessage());
throw new BusinessException(ResultCode.NULL_ERROR.getCode(), ResultCode.NULL_ERROR.getMessage());
}
BeanUtils.copyProperties(fnaUpdateRequest, fna,"fnaBizId");
......@@ -308,4 +305,79 @@ public class FnaServiceImpl extends ServiceImpl<FnaMapper, Fna> implements FnaSe
return this.updateById(fna);
}
@Override
@Transactional(rollbackFor = Exception.class)
public Map<String, Object> copyFna(FnaCopyRequest fnaCopyRequest) {
String fnaBizId = fnaCopyRequest.getFnaBizId();
Fna oldFna = this.getByBizId(fnaBizId);
if (oldFna == null) {
throw new BusinessException(ResultCode.NULL_ERROR.getCode(), ResultCode.NULL_ERROR.getMessage());
}
// 获取Security上下文当前用户的登录信息
AuthUserDto authUserDto = SecurityUtil.getCurrentLoginUser();
String userBizId = authUserDto.getUserBizId();
// 新建流程
Fna newFna = new Fna();
// 租户编码
newFna.setTenantCode(oldFna.getTenantCode());
// 复制 客户信息
newFna.setCustomerName(oldFna.getCustomerName());
newFna.setFnaFormBizId(oldFna.getFnaFormBizId());
newFna.setUserBizId(userBizId);
newFna.setFnaBizId(RandomStringGenerator.generateBizId16(CommonEnum.UID_TYPE_FNA.getCode()));
newFna.setCreatorId(userBizId);
newFna.setUpdaterId(userBizId);
newFna.setStatus(FnaStatusEnum.UNCOMPLETED.getItemValue());
Date date = new Date();
newFna.setCreateTime(date);
newFna.setUpdateTime(date);
// 保存 fna
boolean result = this.save(newFna);
if (!result) {
throw new BusinessException(ResultCode.FAIL.getCode(), ResultCode.FAIL.getMessage());
}
// 生成fna编号
String fnaNo = generateFnaNo(oldFna.getTenantCode(), newFna.getId());
// 复制 FnaForm
String newFnaFormBizId = copyFnaForm(oldFna.getFnaFormBizId(), userBizId);
// 更新 fna
Fna updateFna = new Fna();
updateFna.setId(newFna.getId());
updateFna.setFnaNo(fnaNo);
updateFna.setFnaFormBizId(newFnaFormBizId);
this.updateById(updateFna);
return Collections.singletonMap("fnaBizId", newFna.getFnaBizId());
}
private String copyFnaForm(String oldFnaFormBizId, String userBizId) {
FnaForm fnaForm = fnaFormService.getByFnaFormBizId(oldFnaFormBizId);
if (fnaForm == null) {
throw new BusinessException(ResultCode.NULL_ERROR.getCode(), ResultCode.NULL_ERROR.getMessage());
}
// 处理个人资料
PersonalData personalData = fnaFormService.getPersonalDataObj(fnaForm.getPersonalData());
personalData.setAccountName(null);
personalData.setRegistrationNumber(null);
personalData.setNumber(null);
FnaForm newFnaForm = new FnaForm();
BeanUtils.copyProperties(fnaForm, newFnaForm, "id", "fnaFormBizId", "userBizId", "personalData");
newFnaForm.setFnaFormBizId(RandomStringGenerator.generateBizId16(CommonEnum.UID_TYPE_FNA_FORM.getCode()));
newFnaForm.setUserBizId(userBizId);
newFnaForm.setCreatorId(userBizId);
newFnaForm.setUpdaterId(userBizId);
newFnaForm.setPersonalData(GSON.toJson(personalData));
Date date = new Date();
newFnaForm.setCreateTime(date);
newFnaForm.setUpdateTime(date);
fnaFormService.save(newFnaForm);
return newFnaForm.getFnaFormBizId();
}
}
......@@ -8,6 +8,7 @@
<id property="id" column="id" />
<result property="fnaBizId" column="fna_biz_id" />
<result property="fnaNo" column="fna_no" />
<result property="tenantCode" column="tenant_code" />
<result property="userBizId" column="user_biz_id" />
<result property="customerBizId" column="customer_biz_id" />
<result property="appointmentNo" column="appointment_no" />
......@@ -30,10 +31,14 @@
</resultMap>
<sql id="Base_Column_List">
id,fna_biz_id,fna_no,user_biz_id,customer_biz_id,appointment_no,
id,fna_biz_id,fna_no,tenant_code,user_biz_id,customer_biz_id,appointment_no,
appointment_biz_id,booking_status_tip,underwriting_no,policy_biz_id,policy_no,
status,product_code,product_name,url,edit,
remark,is_deleted,creator_id,updater_id,create_time,
update_time
</sql>
<update id="updateFnaNoById">
update fna set fna_no = #{fnaNo} where id = #{id}
</update>
</mapper>
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