package com.deloitte.system.service;
|
|
import cn.hutool.core.collection.CollUtil;
|
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.redis.util.RedisUtil;
|
import com.deloitte.system.model.CacheList;
|
import com.deloitte.system.model.Swo;
|
import com.deloitte.system.request.SwoDto;
|
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 SwoService {
|
|
private String tableName="swo";
|
|
@Autowired
|
private CryptoService cryptoService;
|
|
@Autowired
|
private IdUtils idWorker;
|
|
@Autowired
|
private RedisUtil redisUtil;
|
|
public SwoDto queryForOne(String dataId) {
|
Swo swo =Swo.dao.findById(dataId);
|
if (!ObjectUtil.isEmpty(swo)){
|
SwoDto dto = BeanHelper.copyAs(swo, SwoDto.class);
|
return dto;
|
}
|
return null;
|
}
|
|
public List<SwoDto> insertList(List<SwoDto> swoDtoList, String txId) {
|
List<SwoDto> respList = new ArrayList<>();
|
CacheList<SwoDto> dtoCacheList = new CacheList<>();
|
dtoCacheList.setTableName(tableName);
|
List<SwoDto> dtoItemList = new ArrayList<>();
|
swoDtoList.forEach(e -> {
|
String dataId = idWorker.nextId();
|
SwoDto cacheItem = BeanHelper.copyAs(e, SwoDto.class);
|
cacheItem.setDataId(dataId);
|
dtoItemList.add(cacheItem);
|
SwoDto target = BeanHelper.copyAs(e, SwoDto.class);
|
target.setDataId(dataId);
|
SwoDto dto = cryptoService.encryptModelColumns(e);
|
dto.setDataId(dataId);
|
target.setAuthorEncrypt(dto.getAuthor());
|
target.setBccEncrypt(dto.getBcc());
|
target.setBccNameEncrypt(dto.getBccName());
|
target.setCcEncrypt(dto.getCc());
|
target.setCcNameEncrypt(dto.getCcName());
|
target.setContactEncrypt(dto.getContact());
|
target.setContactNameHiddenEncrypt(dto.getContactNameHidden());
|
target.setEmailEncrypt(dto.getEmail());
|
target.setMessageEncrypt(dto.getMessage());
|
target.setPrimaryRecipientEncrypt(dto.getPrimaryRecipient());
|
target.setRecipientEncrypt(dto.getRecipient());
|
target.setSendEncrypt(dto.getSend());
|
target.setToNameEncrypt(dto.getToName());
|
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<SwoDto> updateList(List<SwoDto> swoDtoList, String txId) {
|
List<SwoDto> respList = new ArrayList<>();
|
CacheList<SwoDto> dtoCacheList = new CacheList<>();
|
dtoCacheList.setTableName(tableName);
|
List<SwoDto> dtoItemList = new ArrayList<>();
|
swoDtoList.forEach(e -> {
|
Swo swo = Swo.dao.findById(e.getDataId());
|
SwoDto cacheItem = BeanHelper.copyAs(e, SwoDto.class);
|
dtoItemList.add(cacheItem);
|
SwoDto dto = BeanHelper.copyAs(BeanHelper.copy(cacheItem,swo),SwoDto.class);
|
SwoDto target = BeanHelper.copyAs(dto, SwoDto.class);
|
dto = cryptoService.encryptModelColumns(dto);
|
target.setAuthorEncrypt(dto.getAuthor());
|
target.setBccEncrypt(dto.getBcc());
|
target.setBccNameEncrypt(dto.getBccName());
|
target.setCcEncrypt(dto.getCc());
|
target.setCcNameEncrypt(dto.getCcName());
|
target.setContactEncrypt(dto.getContact());
|
target.setContactNameHiddenEncrypt(dto.getContactNameHidden());
|
target.setEmailEncrypt(dto.getEmail());
|
target.setMessageEncrypt(dto.getMessage());
|
target.setPrimaryRecipientEncrypt(dto.getPrimaryRecipient());
|
target.setRecipientEncrypt(dto.getRecipient());
|
target.setSendEncrypt(dto.getSend());
|
target.setToNameEncrypt(dto.getToName());
|
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) {
|
Swo swo = Swo.dao.findById(dataId);
|
swo.setIsDelete(1);
|
return swo.saveOrUpdate();
|
}
|
|
public Boolean undeleteOne(String dataId) {
|
Swo swo = Swo.dao.findById(dataId);
|
swo.setIsDelete(1);
|
return swo.saveOrUpdate();
|
}
|
|
public List<SwoDto> search(List<String> idList){
|
if (CollUtil.isEmpty(idList)) {
|
return null;
|
}
|
StringBuilder queryParam = new StringBuilder();
|
queryParam.append("and id in ").append(idList.stream().collect(Collectors.joining(", ", "(", ")")));
|
List<Swo> quotesList = Swo.dao.findList(queryParam.toString());
|
return quotesList.stream()
|
.map(quotes -> BeanHelper.copyAs(quotes, SwoDto.class)).collect(Collectors.toList());
|
|
}
|
}
|