|
|
|
@ -1,16 +1,37 @@ |
|
|
|
package com.elink.esua.epdc.modules.events.service.impl; |
|
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.codec.Base64Encoder; |
|
|
|
import cn.hutool.crypto.SecureUtil; |
|
|
|
import cn.hutool.crypto.symmetric.AES; |
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
|
|
|
import com.elink.esua.epdc.commons.mybatis.service.impl.BaseServiceImpl; |
|
|
|
import com.elink.esua.epdc.commons.tools.constant.NumConstant; |
|
|
|
import com.elink.esua.epdc.commons.tools.constant.StrConstant; |
|
|
|
import com.elink.esua.epdc.commons.tools.exception.RenException; |
|
|
|
import com.elink.esua.epdc.commons.tools.utils.ConvertUtils; |
|
|
|
import com.elink.esua.epdc.constant.XxxdConstant; |
|
|
|
import com.elink.esua.epdc.dto.events.XxxdEventDTO; |
|
|
|
import com.elink.esua.epdc.dto.events.form.XxxdFeedBackQuestionFormDTO; |
|
|
|
import com.elink.esua.epdc.dto.events.result.XxxdFeedBackResultDTO; |
|
|
|
import com.elink.esua.epdc.modules.events.dao.XxxdEventDao; |
|
|
|
import com.elink.esua.epdc.modules.events.entity.XxxdEventEntity; |
|
|
|
import com.elink.esua.epdc.modules.events.service.XxxdEventService; |
|
|
|
import com.google.zxing.oned.UPCAReader; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
import org.springframework.http.*; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
import org.springframework.web.client.HttpClientErrorException; |
|
|
|
import org.springframework.web.client.RestTemplate; |
|
|
|
|
|
|
|
import java.time.LocalDateTime; |
|
|
|
import java.time.format.DateTimeFormatter; |
|
|
|
import java.util.Date; |
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
/** |
|
|
|
@ -19,6 +40,7 @@ import java.util.List; |
|
|
|
* @author generator generator@elink-cn.com |
|
|
|
* @since v1.0.0 2023-05-22 |
|
|
|
*/ |
|
|
|
@Slf4j |
|
|
|
@Service |
|
|
|
public class XxxdEventServiceImpl extends BaseServiceImpl<XxxdEventDao, XxxdEventEntity> implements XxxdEventService { |
|
|
|
|
|
|
|
@ -29,7 +51,7 @@ public class XxxdEventServiceImpl extends BaseServiceImpl<XxxdEventDao, XxxdEven |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public void save(XxxdEventDTO dto) { |
|
|
|
public String save(XxxdEventDTO dto) { |
|
|
|
XxxdEventEntity entity = ConvertUtils.sourceToTarget(dto, XxxdEventEntity.class); |
|
|
|
// 将图片与声音的数组转换为字符串,中间用分号分隔
|
|
|
|
String[] pics = dto.getPics(); |
|
|
|
@ -40,25 +62,57 @@ public class XxxdEventServiceImpl extends BaseServiceImpl<XxxdEventDao, XxxdEven |
|
|
|
if (audios != null && audios.length > 0) { |
|
|
|
entity.setAudios(String.join(StrConstant.SEMICOLON, audios)); |
|
|
|
} |
|
|
|
insert(entity); |
|
|
|
|
|
|
|
LambdaQueryWrapper<XxxdEventEntity> queryWrapper=new LambdaQueryWrapper<>(); |
|
|
|
queryWrapper.eq(XxxdEventEntity::getQuestionId,dto.getQuestionId()) |
|
|
|
.eq(XxxdEventEntity::getDelFlag, NumConstant.ZERO_STR); |
|
|
|
XxxdEventEntity origin=baseDao.selectOne(queryWrapper); |
|
|
|
if (null == origin) { |
|
|
|
insert(entity); |
|
|
|
} else { |
|
|
|
entity.setId(origin.getId()); |
|
|
|
updateById(entity); |
|
|
|
} |
|
|
|
return entity.getId(); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* 更新 |
|
|
|
* |
|
|
|
* @param dto |
|
|
|
* @param formDTO |
|
|
|
*/ |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
@Override |
|
|
|
public void update(XxxdEventDTO dto) { |
|
|
|
|
|
|
|
public XxxdFeedBackResultDTO feedBack(XxxdFeedBackQuestionFormDTO formDTO) { |
|
|
|
// 向新新向党反馈数据结果
|
|
|
|
XxxdFeedBackResultDTO resultDTO=submitFeedback(formDTO.getQuestionId(), formDTO.getStatus(), formDTO.getProcessResult(),formDTO.getProcessTime()); |
|
|
|
if(!resultDTO.getSuccess()){ |
|
|
|
throw new RenException("调用新新向党随手拍处理反馈接口失败:"+resultDTO.getMessage()); |
|
|
|
} |
|
|
|
LambdaUpdateWrapper<XxxdEventEntity> updateWrapper=new LambdaUpdateWrapper<>(); |
|
|
|
updateWrapper.eq(XxxdEventEntity::getQuestionId,formDTO.getQuestionId()) |
|
|
|
.set(XxxdEventEntity::getStatus,formDTO.getStatus()) |
|
|
|
.set(XxxdEventEntity::getProcessResult,formDTO.getProcessResult()) |
|
|
|
.set(XxxdEventEntity::getProcessTime,formDTO.getProcessTime()) |
|
|
|
.set(XxxdEventEntity::getUpdatedTime,new Date()); |
|
|
|
baseDao.update(null,updateWrapper); |
|
|
|
return resultDTO; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public XxxdEventDTO get(String id) { |
|
|
|
XxxdEventEntity entity = baseDao.selectById(id); |
|
|
|
return ConvertUtils.sourceToTarget(entity, XxxdEventDTO.class); |
|
|
|
XxxdEventDTO xxxdEventDTO=ConvertUtils.sourceToTarget(entity, XxxdEventDTO.class); |
|
|
|
if(StringUtils.isNotBlank(entity.getPics())){ |
|
|
|
String[] arr1 = entity.getPics().split(StrConstant.SEMICOLON); |
|
|
|
xxxdEventDTO.setPics(arr1); |
|
|
|
} |
|
|
|
if(StringUtils.isNotBlank(entity.getAudios())){ |
|
|
|
String[] arr2 = entity.getAudios().split(StrConstant.SEMICOLON); |
|
|
|
xxxdEventDTO.setAudios(arr2); |
|
|
|
} |
|
|
|
return xxxdEventDTO; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -68,4 +122,65 @@ public class XxxdEventServiceImpl extends BaseServiceImpl<XxxdEventDao, XxxdEven |
|
|
|
// 逻辑删除(@TableLogic 注解)
|
|
|
|
baseDao.deleteBatchIds(ids); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private XxxdFeedBackResultDTO submitFeedback(String questionId, String status, String processResult, String processTime) { |
|
|
|
HttpHeaders headers = new HttpHeaders(); |
|
|
|
headers.setContentType(MediaType.APPLICATION_JSON); |
|
|
|
headers.set("Authorization", genAuthorization()); |
|
|
|
|
|
|
|
/* LocalDateTime currentTime = LocalDateTime.now(); |
|
|
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); |
|
|
|
String processTime = currentTime.format(formatter);*/ |
|
|
|
|
|
|
|
// 构建请求体数据,这里以示例数据为准
|
|
|
|
// String requestBody = "{\"questionId\":\"" + questionId + "\", \"status\":\"" + status + "\", \"processResult\":\"" + processResult + "\", \"processTime\":\"" + processTime + "\"}";
|
|
|
|
XxxdFeedBackQuestionFormDTO formDTO=new XxxdFeedBackQuestionFormDTO(); |
|
|
|
formDTO.setQuestionId(questionId); |
|
|
|
formDTO.setStatus(status); |
|
|
|
formDTO.setProcessResult(processResult); |
|
|
|
formDTO.setProcessTime(processTime); |
|
|
|
HttpEntity<XxxdFeedBackQuestionFormDTO> requestEntity = new HttpEntity<>(formDTO, headers); |
|
|
|
RestTemplate restTemplate = new RestTemplate(); |
|
|
|
|
|
|
|
try { |
|
|
|
ResponseEntity<String> response = restTemplate.exchange(XxxdConstant.XXXD_QUESTION_FEED_BACK_URL, HttpMethod.POST, requestEntity, String.class); |
|
|
|
log.warn("新新向党_随手拍处理反馈原始返参:" + JSON.toJSONString(response.getBody())); |
|
|
|
|
|
|
|
JSONObject shopNameArr = JSONObject.parseObject(response.getBody()); |
|
|
|
XxxdFeedBackResultDTO resultDTO = JSON.parseObject(shopNameArr.toJSONString(), XxxdFeedBackResultDTO.class); |
|
|
|
log.warn("新新向党_随手拍处理反馈返参XxxdFeedBackResultDTO:" + JSON.toJSONString(resultDTO)); |
|
|
|
return resultDTO; |
|
|
|
} catch (HttpClientErrorException e) { |
|
|
|
// 处理异常情况
|
|
|
|
HttpStatus statusCode = e.getStatusCode(); |
|
|
|
// 进一步处理异常...
|
|
|
|
} |
|
|
|
return new XxxdFeedBackResultDTO().error(); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 生成认证信息 |
|
|
|
* |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
public String genAuthorization() { |
|
|
|
String key = XxxdConstant.APP_KEY; |
|
|
|
String secret = XxxdConstant.APP_SECRET; |
|
|
|
|
|
|
|
LocalDateTime currentTime = LocalDateTime.now(); |
|
|
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMddHHmmss"); |
|
|
|
String time = currentTime.format(formatter); |
|
|
|
|
|
|
|
String version = "1.0"; |
|
|
|
String beforeSignStr = key + time + version;// 拼接要加密的字符串
|
|
|
|
|
|
|
|
AES aes = SecureUtil.aes(secret.getBytes()); |
|
|
|
String signStr = aes.encryptBase64(beforeSignStr);// 执行aes加密并转base64编码
|
|
|
|
String authStr = String.format("{\"ak_key\":\"%s\",\"ak_time\":\"%s\",\"ac_version\":\"%s\",\"ac_signature\":\"%s\"}", key, time, version, signStr);// 组装认证信息
|
|
|
|
|
|
|
|
return Base64Encoder.encode(authStr);// 认证信息执行base64
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |