PickUpCustomerService.java
4.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
package cn.fw.valhalla.service.bus.cust;
import cn.fw.common.web.auth.LoginAuthBean;
import cn.fw.valhalla.common.constant.RoleCode;
import cn.fw.valhalla.domain.db.customer.Customer;
import cn.fw.valhalla.domain.dto.CustomerDetailDto;
import cn.fw.valhalla.domain.vo.customer.PickUpCustomerDetailVO;
import cn.fw.valhalla.rpc.angel.dto.InsuranceDTO;
import cn.fw.valhalla.rpc.erp.dto.UserInfoDTO;
import cn.fw.valhalla.rpc.oop.dto.ShopDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Objects;
import java.util.Optional;
import static cn.fw.common.businessvalidator.Validator.BV;
/**
* @author : kurisu
* @className : PickUpCustomerService
* @description : 接车档案管理
* @date: 2020-08-13 09:58
*/
@Service
@Slf4j
public class PickUpCustomerService extends AbstractCustomerService {
/**
* 接车时查询档案信息
*
* @param currentUser
* @param plateNo
* @return
*/
public PickUpCustomerDetailVO getDetailByPlateNo(LoginAuthBean currentUser, String plateNo) {
Customer customer = customerService.queryByPlateNo(plateNo, currentUser.getGroupId());
if (customer == null) {
return null;
}
return with(customer, currentUser.getUserId());
}
/**
* 修改车牌号
*
* @param frameNo
* @param plateNo
* @param currentUser
* @return
*/
@Transactional(rollbackFor = Exception.class)
public Long fixPlateNo(String frameNo, String plateNo, LoginAuthBean currentUser) {
Customer customer = customerService.queryByFrameNo(frameNo, currentUser.getGroupId());
BV.notNull(customer, () -> "车架号有误");
customer.setPlateNo(plateNo);
boolean bool = customerService.updateById(customer);
BV.isTrue(bool, () -> "修改车牌号失败");
return customer.getId();
}
/**
* 修改车牌号
*
* @param frameNo
* @param plateNo
* @param groupId
* @return
*/
@Transactional(rollbackFor = Exception.class)
public Boolean fixPlateNo(String frameNo, String plateNo, Long groupId) {
Customer customer = customerService.queryByFrameNo(frameNo, groupId);
BV.notNull(customer, () -> "车架号有误");
Customer motoCust = customerService.queryByPlateNo(plateNo, groupId);
customer.setPlateNo(plateNo);
boolean update = customerService.updateById(customer);
if (Objects.nonNull(motoCust) && !motoCust.getFrameNo().equals(frameNo)) {
customerService.forbidden(motoCust.getId());
}
return update;
}
/**
* 根据vin查询档案
*
* @param currentUser
* @param frameNo
* @return
*/
public PickUpCustomerDetailVO getDetailByFrameNo(LoginAuthBean currentUser, String frameNo) {
Customer customer = customerService.queryByFrameNo(frameNo, currentUser.getGroupId());
if (customer == null) {
return null;
}
return with(customer, currentUser.getUserId());
}
private PickUpCustomerDetailVO with(Customer customer, Long userId) {
PickUpCustomerDetailVO detailVO = new PickUpCustomerDetailVO();
CustomerDetailDto detailDto = renderDto(customer);
BeanUtils.copyProperties(detailDto, detailVO);
detailVO.setOrgCode(detailDto.getIdCode());
detailVO.setIdNum(detailDto.getIdCode());
Optional<InsuranceDTO> dtoOptional = queryInsuInfo(customer.getId());
dtoOptional.ifPresent(t -> {
detailVO.setInsurCompanyId(t.getInsurerId());
detailVO.setInsurCompanyName(t.getInsurerName());
detailVO.setInsurExpireDate(t.getExpiryDate());
});
boolean canReception = true;
ShopDTO shop = Optional.ofNullable(queryDealId(userId, RoleCode.FWGW)).orElse(new ShopDTO());
if (Objects.nonNull(customer.getShopId()) && customer.getShopId().equals(shop.getId()) && Objects.nonNull(customer.getAdviserId())) {
UserInfoDTO user = ehrRpcService.user(customer.getAdviserId());
String userName = Optional.ofNullable(user).map(UserInfoDTO::getUserName).orElse("");
detailVO.setAdviserName(userName);
}
detailVO.setCanReception(canReception);
return detailVO;
}
}