package com.deloitte.system.service;
|
|
|
|
import cn.hutool.core.collection.CollectionUtil;
|
import cn.hutool.core.util.ObjectUtil;
|
import com.alibaba.fastjson.JSONArray;
|
import com.common.core.constant.GlobalConst;
|
import com.common.core.exception.BizException;
|
import com.common.core.service.CryptoService;
|
import com.common.core.utils.BeanHelper;
|
import com.common.core.utils.DesensitiveUtils;
|
import com.common.core.utils.IdUtils;
|
import com.common.core.utils.StringUtils;
|
import com.common.redis.util.RedisUtil;
|
import com.deloitte.system.model.CacheList;
|
import com.deloitte.system.model.LoanerApplication;
|
import com.deloitte.system.model.Repair;
|
import com.deloitte.system.request.ContactSearchDto;
|
import com.deloitte.system.request.LoanerApplicationDto;
|
import com.deloitte.system.request.SearchDto;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
|
import java.util.ArrayList;
|
import java.util.List;
|
import java.util.stream.Collectors;
|
|
import static com.common.core.constant.GlobalConst.PIPL_UNCONFIRM_INSERT;
|
import static com.common.core.constant.GlobalConst.PIPL_UNCONFIRM_UPDATE;
|
|
@Service
|
public class LoanerApplicationService {
|
private String tableName = "loaner_application";
|
|
@Autowired
|
private CryptoService cryptoService;
|
|
@Autowired
|
private IdUtils idWorker;
|
|
@Autowired
|
private RedisUtil redisUtil;
|
|
public LoanerApplicationDto queryForOne(String dataId) {
|
LoanerApplication loanerApplication = LoanerApplication.dao.findById(dataId);
|
if (!ObjectUtil.isEmpty(loanerApplication)) {
|
LoanerApplicationDto dto = BeanHelper.copyAs(loanerApplication,LoanerApplicationDto.class);
|
return dto;
|
}
|
return null;
|
}
|
|
public List<LoanerApplicationDto> insertList(List<LoanerApplicationDto> loanerApplicationList, String txId) {
|
List<LoanerApplicationDto> respList = new ArrayList<>();
|
CacheList<LoanerApplicationDto> dtoCacheList = new CacheList<>();
|
dtoCacheList.setTableName(tableName);
|
List<LoanerApplicationDto> dtoItemList = new ArrayList<>();
|
loanerApplicationList.forEach(e -> {
|
String dataId = idWorker.nextId();
|
LoanerApplicationDto cacheItem = BeanHelper.copyAs(e, LoanerApplicationDto.class);
|
cacheItem.setDataId(dataId);
|
dtoItemList.add(cacheItem);
|
|
LoanerApplicationDto target = BeanHelper.copyAs(e, LoanerApplicationDto.class);
|
target.setDataId(dataId);
|
LoanerApplicationDto dto = cryptoService.encryptModelColumns(e);
|
dto.setDataId(dataId);
|
cryptoService.convertor(dto,target);
|
DesensitiveUtils.format(target);
|
respList.add(target);
|
});
|
dtoCacheList.setData(dtoItemList);
|
String insertJsonString = JSONArray.toJSONString(dtoCacheList);
|
String insertKey = PIPL_UNCONFIRM_INSERT + txId;
|
boolean redisFlag = redisUtil.set(insertKey, insertJsonString,GlobalConst.DATA_EXPIRE);
|
if (!redisFlag) {
|
throw new BizException("缓存写入失败");
|
}
|
return respList;
|
}
|
|
public List<LoanerApplicationDto> updateList(List<LoanerApplicationDto> loanerApplicationList, String txId) {
|
List<LoanerApplicationDto> respList = new ArrayList<>();
|
CacheList<LoanerApplicationDto> dtoCacheList = new CacheList<>();
|
dtoCacheList.setTableName(tableName);
|
List<LoanerApplicationDto> dtoItemList = new ArrayList<>();
|
loanerApplicationList.forEach(e -> {
|
LoanerApplication loanerApplication = LoanerApplication.dao.findById(e.getDataId());
|
LoanerApplicationDto cacheItem = BeanHelper.copyAs(e, LoanerApplicationDto.class);
|
dtoItemList.add(cacheItem);
|
LoanerApplicationDto dto = BeanHelper.copyAs(BeanHelper.copy(cacheItem,loanerApplication),LoanerApplicationDto.class);
|
LoanerApplicationDto target = BeanHelper.copyAs(dto, LoanerApplicationDto.class);
|
dto = cryptoService.encryptModelColumns(dto);
|
target.setApplyPersonEncrypt(dto.getApplyPerson());
|
target.setApplyPersonPhoneEncrypt(dto.getApplyPersonPhone());
|
target.setApplicantMailboxEncrypt(dto.getApplicantMailbox());
|
target.setLoanerReceiveStaffEncrypt(dto.getLoanerReceiveStaff());
|
target.setDirectShippmentAddressEncrypt(dto.getDirectShippmentAddress());
|
target.setLoanerReceiveStaffPhoneEncrypt(dto.getLoanerReceiveStaffPhone());
|
target.setReturnTrakeStaffEncrypt(dto.getReturnTrakeStaff());
|
target.setReturnNumberEncrypt(dto.getReturnNumber());
|
target.setPostCodeEncrypt(dto.getPostCode());
|
target.setLoanerSerEncrypt(dto.getLoanerSer());
|
DesensitiveUtils.format(target);
|
respList.add(target);
|
});
|
dtoCacheList.setData(dtoItemList);
|
String updateJsonString = JSONArray.toJSONString(dtoCacheList);
|
String updateKey = PIPL_UNCONFIRM_UPDATE + txId;
|
boolean redisFlag = redisUtil.set(updateKey, updateJsonString,GlobalConst.DATA_EXPIRE);
|
if (!redisFlag) {
|
throw new BizException("缓存写入失败");
|
}
|
return respList;
|
}
|
|
public Boolean deleteOne(String dataId) {
|
LoanerApplication loanerApplication = LoanerApplication.dao.findById(dataId);
|
loanerApplication.setIsDelete(1);
|
return loanerApplication.saveOrUpdate();
|
}
|
|
public Boolean undeleteOne(String dataId) {
|
LoanerApplication loanerApplication = LoanerApplication.dao.findById(dataId);
|
loanerApplication.setIsDelete(0);
|
return loanerApplication.saveOrUpdate();
|
}
|
|
public List<LoanerApplicationDto> searchList(SearchDto searchDto) {
|
List<String> dataIds = searchDto.getDataIds();
|
String contactName = searchDto.getName();
|
StringBuilder queryParam = new StringBuilder();
|
if (CollectionUtil.isEmpty(dataIds) && StringUtils.isEmpty(contactName)) {
|
//参数都为空,直接返回Null
|
return null;
|
} else {
|
if(CollectionUtil.isNotEmpty(dataIds)){
|
queryParam.append("and id in").append(dataIds.stream().collect(Collectors.joining(", ", "(", ")")));
|
}
|
if(StringUtils.isNotEmpty(contactName)) {
|
queryParam.append("and apply_person like ").append("\'%").append(contactName).append("%\'");
|
}
|
List<LoanerApplication> contactList = LoanerApplication.dao.findList(queryParam.toString());
|
return contactList.stream()
|
.map(contact -> BeanHelper.copyAs(contact,LoanerApplicationDto.class)).collect(Collectors.toList());
|
}
|
}
|
}
|