Commit bfa29c18 by guojuxing

添加工单上传接口

parent fca1ce1c
package com.gic.udesk.constant;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public enum UdeskStatusEnum {
OPEN("open", "开启"),
SOLVING("solving", "解决中"),
RESOLVED("resolved", "已解决"),
CLOSED("closed", "已关闭");
private String code;
private String message;
private UdeskStatusEnum(String code, String message) {
this.code = code;
this.message = message;
}
public static List<Map<String, Object>> list() {
List<Map<String, Object>> result = new ArrayList<>();
for (UdeskStatusEnum permissionEnum : values()) {
Map<String, Object> temp = new HashMap<>(4);
temp.put("key", permissionEnum.getCode());
temp.put("value", permissionEnum.getMessage());
result.add(temp);
}
return result;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
}
package com.gic.udesk.dto.gic;
import java.io.Serializable;
import java.util.Map;
/**
* gic提交工单所提交的对象
* @ClassName: GicTicketDTO

* @Description: 

* @author guojuxing

* @date 2019/12/26 4:11 PM

*/
public class GicTicketDTO implements Serializable{
private static final long serialVersionUID = -478265380664580136L;
/**
* 1:gic基础服务 2:应用服务
*/
private Integer businessModuleType;
/**
* 标题 必填
*/
private String subject;
/**
* 内容 必填
*/
private String content;
/**
* 状态中文
*/
private String status;
/**
* 自定义字段
*/
private Map<String, String> ticket_field;
public String getSubject() {
return subject;
}
public void setSubject(String subject) {
this.subject = subject;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public Map<String, String> getTicket_field() {
return ticket_field;
}
public void setTicket_field(Map<String, String> ticket_field) {
this.ticket_field = ticket_field;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public Integer getBusinessModuleType() {
return businessModuleType;
}
public void setBusinessModuleType(Integer businessModuleType) {
this.businessModuleType = businessModuleType;
}
}
package com.gic.udesk.dto.gic;
import java.io.Serializable;
/**
* 工单创建返回信息
* @ClassName: TicketCreateResDTO

* @Description: 

* @author guojuxing

* @date 2019/12/26 4:48 PM

*/
public class TicketCreateResDTO implements Serializable{
private static final long serialVersionUID = 5033595896326990325L;
/**
* 执行结果码,1000代表成功
*/
private Integer code;
/**
* 执行结果说明
*/
private String message;
/**
* 新建工单的id
*/
private Integer ticket_id;
public Integer getCode() {
return code;
}
public void setCode(Integer code) {
this.code = code;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public Integer getTicket_id() {
return ticket_id;
}
public void setTicket_id(Integer ticket_id) {
this.ticket_id = ticket_id;
}
}
package com.gic.udesk.dto.gic;
import java.io.Serializable;
/**
* 附件相关内容
* @ClassName: TicketRepliesAttachmentsDTO

* @Description: 

* @author guojuxing

* @date 2019/12/26 5:55 PM

*/
public class TicketRepliesAttachmentsDTO implements Serializable{
private static final long serialVersionUID = 3349387219138928011L;
/**
* 附件链接
*/
private String url;
private String file_name;
/**
* 附件大小
*/
private Integer file_size;
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public String getFile_name() {
return file_name;
}
public void setFile_name(String file_name) {
this.file_name = file_name;
}
public Integer getFile_size() {
return file_size;
}
public void setFile_size(Integer file_size) {
this.file_size = file_size;
}
}
package com.gic.udesk.dto.gic;
import java.io.Serializable;
/**
* 回复者信息
* @ClassName: TicketRepliesAuthorDTO

* @Description: 

* @author guojuxing

* @date 2019/12/26 5:57 PM

*/
public class TicketRepliesAuthorDTO implements Serializable{
private static final long serialVersionUID = 6306676280816731296L;
private Integer id;
/**
* 回复人员类型
*/
private String user_type;
/**
* 回复人员邮箱
*/
private String email;
/**
* 回复人员头像url
*/
private String avatar;
/**
* 回复人员昵称
*/
private String nick_name;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getUser_type() {
return user_type;
}
public void setUser_type(String user_type) {
this.user_type = user_type;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getAvatar() {
return avatar;
}
public void setAvatar(String avatar) {
this.avatar = avatar;
}
public String getNick_name() {
return nick_name;
}
public void setNick_name(String nick_name) {
this.nick_name = nick_name;
}
}
package com.gic.udesk.dto.gic;
import java.io.Serializable;
import java.util.List;
import java.util.Map;
/**
* 获取工单回复
* @ClassName: TicketRepliesDTO

* @Description: 

* @author guojuxing

* @date 2019/12/26 5:50 PM

*/
public class TicketRepliesDTO implements Serializable{
private static final long serialVersionUID = -243231508063277717L;
/**
* 执行结果码,1000代表成功
*/
private Integer code;
/**
* 分页相关
*/
private Map<String, Object> meta;
private List<TicketRepliesDataDTO> replies;
public Integer getCode() {
return code;
}
public void setCode(Integer code) {
this.code = code;
}
public Map<String, Object> getMeta() {
return meta;
}
public void setMeta(Map<String, Object> meta) {
this.meta = meta;
}
public List<TicketRepliesDataDTO> getReplies() {
return replies;
}
public void setReplies(List<TicketRepliesDataDTO> replies) {
this.replies = replies;
}
}
package com.gic.udesk.dto.gic;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
/**
* 回复列表
* @ClassName: TicketRepliesDataDTO

* @Description: 

* @author guojuxing

* @date 2019/12/26 5:52 PM

*/
public class TicketRepliesDataDTO implements Serializable{
private static final long serialVersionUID = -4610262435451102033L;
private Integer id;
/**
* 回复内容
*/
private String content;
/**
* 内容的类型,"text"/"html"
*/
private String content_format;
private Date created_at;
/**
* 回复类型,"internat"内部备注/"external"外部评论
*/
private String function_type;
/**
* 抄送对象邮箱
*/
private String cc;
/**
* 附件相关内容
*/
private List<TicketRepliesAttachmentsDTO> attachments;
/**
* 回复者信息
*/
private TicketRepliesAuthorDTO author;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public String getContent_format() {
return content_format;
}
public void setContent_format(String content_format) {
this.content_format = content_format;
}
public Date getCreated_at() {
return created_at;
}
public void setCreated_at(Date created_at) {
this.created_at = created_at;
}
public String getFunction_type() {
return function_type;
}
public void setFunction_type(String function_type) {
this.function_type = function_type;
}
public String getCc() {
return cc;
}
public void setCc(String cc) {
this.cc = cc;
}
public List<TicketRepliesAttachmentsDTO> getAttachments() {
return attachments;
}
public void setAttachments(List<TicketRepliesAttachmentsDTO> attachments) {
this.attachments = attachments;
}
public TicketRepliesAuthorDTO getAuthor() {
return author;
}
public void setAuthor(TicketRepliesAuthorDTO author) {
this.author = author;
}
}
package com.gic.udesk.dto.gic;
import java.io.Serializable;
import java.util.Date;
public class UdeskEnterpriseDTO implements Serializable{
private static final long serialVersionUID = -727703112120773752L;
/**
* id
*/
private Integer id;
/**
* 业务模块ID
*/
private String businessModule;
/**
* 业务模块名称
*/
private String businessModuleName;
/**
* 业务模块类型 1:基础模块 2:应用模块
*/
private Integer businessType;
/**
* 工单ID
*/
private Integer ticketId;
/**
* 工单编号
*/
private String ticketNum;
/**
* 工单标题
*/
private String ticketTitle;
/**
* 工单状态
*/
private String ticketStatus;
/**
*
*/
private Date createTime;
/**
*
*/
private Date updateTime;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getBusinessModule() {
return businessModule;
}
public void setBusinessModule(String businessModule) {
this.businessModule = businessModule;
}
public String getBusinessModuleName() {
return businessModuleName;
}
public void setBusinessModuleName(String businessModuleName) {
this.businessModuleName = businessModuleName;
}
public Integer getBusinessType() {
return businessType;
}
public void setBusinessType(Integer businessType) {
this.businessType = businessType;
}
public Integer getTicketId() {
return ticketId;
}
public void setTicketId(Integer ticketId) {
this.ticketId = ticketId;
}
public String getTicketNum() {
return ticketNum;
}
public void setTicketNum(String ticketNum) {
this.ticketNum = ticketNum;
}
public String getTicketTitle() {
return ticketTitle;
}
public void setTicketTitle(String ticketTitle) {
this.ticketTitle = ticketTitle;
}
public String getTicketStatus() {
return ticketStatus;
}
public void setTicketStatus(String ticketStatus) {
this.ticketStatus = ticketStatus;
}
public Date getCreateTime() {
return createTime;
}
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
public Date getUpdateTime() {
return updateTime;
}
public void setUpdateTime(Date updateTime) {
this.updateTime = updateTime;
}
}
package com.gic.udesk.qo;
import com.gic.enterprise.qo.PageQO;
import java.io.Serializable;
/**
* 工单列表查询参数
* @ClassName: TicketListQO

* @Description: 

* @author guojuxing

* @date 2019/12/26 5:23 PM

*/
public class TicketListQO extends PageQO implements Serializable{
private static final long serialVersionUID = -404555085326787735L;
/**
* 支持搜索应用名称/工单编号/问题标题
*/
private String search;
/**
* UdeskStatusEnum枚举
*/
private String ticketStatus;
/**
* 业务模块ID, 英文逗号隔开
*/
private String businessModule;
private String startTime;
/**
* yyyy-MM-dd格式
*/
private String endTime;
public String getSearch() {
return search;
}
public void setSearch(String search) {
this.search = search;
}
public String getTicketStatus() {
return ticketStatus;
}
public void setTicketStatus(String ticketStatus) {
this.ticketStatus = ticketStatus;
}
public String getBusinessModule() {
return businessModule;
}
public void setBusinessModule(String businessModule) {
this.businessModule = businessModule;
}
public String getStartTime() {
return startTime;
}
public void setStartTime(String startTime) {
this.startTime = startTime;
}
public String getEndTime() {
return endTime;
}
public void setEndTime(String endTime) {
this.endTime = endTime;
}
}
package com.gic.udesk.service;
import com.gic.api.base.commons.Page;
import com.gic.api.base.commons.ServiceResponse;
import com.gic.udesk.dto.gic.GicTicketDTO;
import com.gic.udesk.dto.gic.TicketRepliesDTO;
import com.gic.udesk.dto.gic.UdeskEnterpriseDTO;
import com.gic.udesk.qo.TicketListQO;
/**
* gic商户udesk工单接口
* @ClassName: GicTicketApiService

* @Description: 

* @author guojuxing

* @date 2019/12/26 4:27 PM

*/
public interface GicTicketApiService {
/**
* gic商户新建工单
* @Title: saveTicket

* @Description:

 * @author guojuxing
* @param gicTicketDTO

* @return com.gic.api.base.commons.ServiceResponse<java.lang.Integer>


 */
ServiceResponse<Integer> saveTicket(GicTicketDTO gicTicketDTO);
/**
* 分页查询
* @Title: page

* @Description:

 * @author guojuxing
* @param params

* @return com.gic.api.base.commons.ServiceResponse<com.gic.api.base.commons.Page<com.gic.udesk.dto.gic.UdeskEnterpriseDTO>>


 */
ServiceResponse<Page<UdeskEnterpriseDTO>> page(TicketListQO params);
/**
* 查询工单回复信息
* @Title: getTicketReplies

* @Description:

 * @author guojuxing
* @param ticketId 工单ID
* @param currentPage 第几页
* @param pageSize
 每页多少条
* @return com.gic.api.base.commons.ServiceResponse<com.gic.udesk.dto.gic.TicketRepliesDTO>


 */
ServiceResponse<TicketRepliesDTO> getTicketReplies(Integer ticketId, Integer currentPage, Integer pageSize);
}
package com.gic.udesk.dao.mapper;
import com.gic.udesk.entity.TabUdeskEnterprise;
import com.gic.udesk.qo.TicketListQO;
import java.util.List;
public interface TabUdeskEnterpriseMapper {
/**
......@@ -50,4 +53,13 @@ public interface TabUdeskEnterpriseMapper {
* @return 更新条目数
*/
int updateByPrimaryKey(TabUdeskEnterprise record);
/**
* 分页查询
* @Title: page

* @Description:

 * @author guojuxing
* @param params

* @return java.util.List<com.gic.udesk.entity.TabUdeskEnterprise>


 */
List<TabUdeskEnterprise> page(TicketListQO params);
}
\ No newline at end of file
package com.gic.udesk.service;
import com.gic.udesk.entity.TabUdeskEnterprise;
import com.gic.udesk.qo.TicketListQO;
import com.github.pagehelper.Page;
public interface UdeskEnterpriseService {
/**
* 新增gic工单数据
* @Title: save

* @Description:

 * @author guojuxing
* @param record

* @return int


 */
int save(TabUdeskEnterprise record);
/**
* 分页查询
* @param params
* @return
*/
Page<TabUdeskEnterprise> page(TicketListQO params);
}
package com.gic.udesk.service.impl;
import com.gic.udesk.constant.UdeskStatusEnum;
import com.gic.udesk.dao.mapper.TabUdeskEnterpriseMapper;
import com.gic.udesk.entity.TabUdeskEnterprise;
import com.gic.udesk.qo.TicketListQO;
import com.gic.udesk.service.UdeskEnterpriseService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.List;
@Service("udeskEnterpriseService")
public class UdeskEnterpriseServiceImpl implements UdeskEnterpriseService{
@Autowired
private TabUdeskEnterpriseMapper tabUdeskEnterpriseMapper;
@Override
public int save(TabUdeskEnterprise record) {
record.setCreateTime(new Date());
record.setUpdateTime(new Date());
record.setTicketStatus(UdeskStatusEnum.OPEN.getCode());
return tabUdeskEnterpriseMapper.insertSelective(record);
}
@Override
public Page<TabUdeskEnterprise> page(TicketListQO params) {
PageHelper.startPage(params.getCurrentPage(), params.getPageSize());
List<TabUdeskEnterprise> list = tabUdeskEnterpriseMapper.page(params);
return (Page<TabUdeskEnterprise>) list;
}
}
package com.gic.udesk.service.outer.impl;
import com.alibaba.fastjson.JSONObject;
import com.gic.api.base.commons.Page;
import com.gic.commons.util.PageHelperUtils;
import com.gic.enterprise.error.ErrorCode;
import com.gic.udesk.dto.UdeskTicketDetailDTO;
import com.gic.udesk.dto.customfield.UdeskCustomFieldOptionDTO;
import com.gic.udesk.dto.gic.TicketRepliesDTO;
import com.gic.udesk.dto.gic.UdeskEnterpriseDTO;
import com.gic.udesk.entity.TabUdeskEnterprise;
import com.gic.udesk.qo.TicketListQO;
import org.apache.commons.collections.CollectionUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.alibaba.fastjson.JSON;
import com.gic.api.base.commons.ServiceResponse;
import com.gic.udesk.dto.gic.GicTicketDTO;
import com.gic.udesk.dto.gic.TicketCreateResDTO;
import com.gic.udesk.service.GicTicketApiService;
import com.gic.udesk.service.UdeskBaseApiService;
import com.gic.udesk.service.UdeskEnterpriseService;
import com.gic.udesk.utils.UdeskConstant;
import com.gic.udesk.utils.UdeskHttpClientUtil;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service("gicTicketApiService")
public class GicTicketApiServiceImpl implements GicTicketApiService{
private static final Logger LOGGER = LogManager.getLogger(GicTicketApiServiceImpl.class);
@Autowired
private UdeskBaseApiService udeskBaseApiService;
@Autowired
private UdeskEnterpriseService udeskEnterpriseService;
/**
* udesk工单接口 (创建)
*/
private static final String UDESK_CREATE_TICKET = "/tickets/";
/**
* udesk工单详情接口路径
*/
private static final String TICKET_DETAIL = "/tickets/detail";
@Override
public ServiceResponse<Integer> saveTicket(GicTicketDTO gicTicketDTO) {
Integer businessModuleType = gicTicketDTO.getBusinessModuleType();
boolean isNotRightBusinessModuleType = businessModuleType == null || (businessModuleType != 1 && businessModuleType != 2);
if (isNotRightBusinessModuleType) {
return ServiceResponse.failure(ErrorCode.PARAMETER_ERROR.getCode(), "模块类型错误,数值非法");
}
String params = JSON.toJSONString(gicTicketDTO);
LOGGER.info("gic新建udesk工单,内容为:{}", params);
String respStr = UdeskHttpClientUtil
.putUdeskJsonFromJson(UDESK_CREATE_TICKET, params);
LOGGER.info("更新udesk工单,工单返回为:{}", respStr);
TicketCreateResDTO createResDTO = JSON.parseObject(respStr, TicketCreateResDTO.class);
if (createResDTO != null && createResDTO.getCode() == UdeskConstant.UDESK_SUCCESS_CODE) {
Integer ticketId = createResDTO.getTicket_id();
//udesk工单详情接口
String detailStr = this.getUdeskTicketDetail(ticketId.toString());
UdeskTicketDetailDTO detail = JSON.parseObject(detailStr, UdeskTicketDetailDTO.class);
if (detail.getCode() == UdeskConstant.UDESK_SUCCESS_CODE) {
TabUdeskEnterprise record = new TabUdeskEnterprise();
//工单ID
record.setTicketId(ticketId);
//工单编号
record.setTicketNum(detail.getTicket().getField_num());
//工单标题
record.setTicketTitle(gicTicketDTO.getSubject());
//业务模块类型 1:基础模块 2:应用模块
record.setBusinessType(gicTicketDTO.getBusinessModuleType());
//业务模块ID
if (businessModuleType.intValue() == 1) {
String businessModuleValue = gicTicketDTO.getTicket_field().get(UdeskConstant.GIC_BASE_MODULE_SELECT);
record.setBusinessModule(businessModuleValue);
record.setBusinessModuleName(getBusinessModuleName(businessModuleValue));
} else {
record.setBusinessModule(gicTicketDTO.getTicket_field().get(UdeskConstant.APP_MODULE_NAME));
record.setBusinessModuleName(gicTicketDTO.getTicket_field().get(UdeskConstant.APP_MODULE_NAME));
}
udeskEnterpriseService.save(record);
return ServiceResponse.success(ticketId);
} else {
return ServiceResponse.failure(ErrorCode.SYSTEM_ERROR.getCode(), detail.getMessage());
}
} else {
return ServiceResponse.failure(ErrorCode.SYSTEM_ERROR.getCode(), createResDTO.getMessage());
}
}
@Override
public ServiceResponse<Page<UdeskEnterpriseDTO>> page(TicketListQO params) {
com.github.pagehelper.Page<TabUdeskEnterprise> page = udeskEnterpriseService.page(params);
Page<UdeskEnterpriseDTO> resultPage = PageHelperUtils.changePageHelperToCurrentPage(page, UdeskEnterpriseDTO.class);
return ServiceResponse.success(resultPage);
}
@Override
public ServiceResponse<TicketRepliesDTO> getTicketReplies(Integer ticketId, Integer currentPage, Integer pageSize) {
LOGGER.info(" 查询工单回复信息,工单Id:{}", ticketId);
JSONObject params = new JSONObject();
params.put("page", currentPage);
params.put("per_page", pageSize);
String respStr = UdeskHttpClientUtil
.putUdeskJsonFromJson("/tickets/" + ticketId + "/replies", params.toJSONString());
LOGGER.info("查询工单回复信息,工单返回为:{}", respStr);
TicketRepliesDTO updateDetail = JSON.parseObject(respStr, TicketRepliesDTO.class);
if (updateDetail.getCode() == UdeskConstant.UDESK_SUCCESS_CODE) {
return ServiceResponse.success(updateDetail);
}
return ServiceResponse.failure(ErrorCode.SYSTEM_ERROR.getCode(), "无数据");
}
/**
* udesk工单详情接口
* @param id
* @return
*/
private String getUdeskTicketDetail(String id) {
Map<String, Object> param = new HashMap<>(8);
param.put("id", id);
LOGGER.info("请求udesk工单详情入参id为{}", id);
String detailStr = UdeskHttpClientUtil.getUdeskJsonFromParam(TICKET_DETAIL, param);
LOGGER.info("请求udesk工单详情返回为{}", detailStr);
return detailStr;
}
/**
* gic基础模块 级联名称获取
* @param businessModule
* @return
*/
private String getBusinessModuleName(String businessModule) {
String[] arr = businessModule.split(",");
//第一层级
String name1 = "";
//第二层级
String name2 = "";
ServiceResponse<List<UdeskCustomFieldOptionDTO>> result = udeskBaseApiService.getGicServiceSelect();
if (result.isSuccess()) {
List<UdeskCustomFieldOptionDTO> list = result.getResult();
if (CollectionUtils.isNotEmpty(list)) {
for (UdeskCustomFieldOptionDTO optionDTO : list) {
if (optionDTO.getValue().equals(arr[0])) {
name1 = optionDTO.getTitle();
if (CollectionUtils.isNotEmpty(optionDTO.getSubs())) {
for (UdeskCustomFieldOptionDTO subDTO : optionDTO.getSubs()) {
if (subDTO.getValue().equals(arr[1])) {
name2 = subDTO.getTitle();
break;
}
}
}
break;
}
}
return name1 + "/" + name2;
}
}
return null;
}
}
......@@ -131,6 +131,16 @@ public class UdeskConstant {
public static final String UDESK_FIELD_TRANSACTOR = "SelectField_23591";
/**
* GIC后台对应的基础模块 级联字段
*/
public static final String GIC_BASE_MODULE_SELECT = "SelectField_56661";
/**
* GIC应用模块工单 应用模块名称
*/
public static final String APP_MODULE_NAME = "TextField_101931";
/**
* udesk来源的类型异常
*/
public static final String UDESK_EXP_TYPE = "udesk";
......
......@@ -302,6 +302,7 @@ public class UdeskHttpClientUtil {
multipartEntityBuilder.addTextBody("file_name", fileName);
HttpEntity httpEntity = multipartEntityBuilder.build();
httpPost.setEntity(httpEntity);
// httpPost.setHeader("Content-Type", "application/octet-stream");
response = httpClient.execute(httpPost);
return response;
}
......
......@@ -18,5 +18,6 @@
<dubbo:service interface="com.gic.udesk.service.TapdConfigApiService" ref="tapdConfigApiService" retries="0"/>
<dubbo:service interface="com.gic.udesk.service.TapdMessageApiService" ref="tapdMessageApiService" retries="0"/>
<dubbo:service interface="com.gic.udesk.service.UdeskBaseApiService" ref="udeskBaseApiService" retries="0"/>
<dubbo:service interface="com.gic.udesk.service.GicTicketApiService" ref="gicTicketApiService" retries="0"/>
</beans>
......@@ -18,7 +18,7 @@
ticket_title, ticket_status, create_time, update_time
</sql>
<select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
select
select
<include refid="Base_Column_List" />
from tab_udesk_enterprise
where id = #{id,jdbcType=INTEGER}
......@@ -150,4 +150,30 @@
update_time = #{updateTime,jdbcType=TIMESTAMP}
where id = #{id,jdbcType=INTEGER}
</update>
<select id="page" parameterType="com.gic.udesk.qo.TicketListQO" resultMap="BaseResultMap">
SELECT <include refid="Base_Column_List"></include>
from tab_udesk_enterprise
where 1=1
<if test="search != null and search != '' ">
and (business_module_name like concat('%', #{search}, '%')
or ticket_num like concat('%', #{search}, '%')
or ticket_title like concat('%', #{search}, '%')
)
</if>
<if test="ticketStatus != null and ticketStatus != '' ">
and ticket_status = #{ticketStatus}
</if>
<if test="businessModule != null and businessModule != '' ">
and business_module = #{businessModule}
</if>
<if test="startTime != null and startTime != '' ">
and create_time >= #{startTime}
</if>
<if test="endTime != null and endTime != '' ">
and create_time &lt;&gt; #{endTime}
</if>
order by create_time desc
</select>
</mapper>
\ No newline at end of file
......@@ -11,7 +11,7 @@ import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import com.gic.api.base.commons.ServiceResponse;
import com.alibaba.fastjson.JSON;
import com.gic.commons.webapi.reponse.RestResponse;
import com.gic.enterprise.ano.IgnoreLogin;
import com.gic.enterprise.error.ErrorCode;
......@@ -20,7 +20,10 @@ import com.gic.udesk.constant.AgentPermissionEnum;
import com.gic.udesk.constant.CalculateResultTypeEnum;
import com.gic.udesk.constant.CustomFieldContentTypeEnum;
import com.gic.udesk.constant.CustomerPermissionEnum;
import com.gic.udesk.dto.uploadfile.UploadFileDTO;
import com.gic.udesk.service.GicTicketApiService;
import com.gic.udesk.service.UdeskBaseApiService;
import com.gic.udesk.web.utils.UdeskHttpClientUtil;
@RestController
public class GicTicketController {
......@@ -28,6 +31,8 @@ public class GicTicketController {
@Autowired
private UdeskBaseApiService udeskBaseApiService;
@Autowired
private GicTicketApiService gicTicketApiService;
@RequestMapping("/get-gic-service-select")
@IgnoreLogin
......@@ -46,6 +51,19 @@ public class GicTicketController {
return ResultControllerUtils.commonResult(udeskBaseApiService.getCustomFieldFromUdeskTemplates(type));
}
/**
* 工单回复信息
* @param ticketId
* @param currentPage
* @param pageSize
* @return
*/
@RequestMapping("/get-ticket-replies")
@IgnoreLogin
public RestResponse getTicketReplies(Integer ticketId, Integer currentPage, Integer pageSize) {
return ResultControllerUtils.commonResult(gicTicketApiService.getTicketReplies(ticketId, currentPage, pageSize));
}
@RequestMapping("/ticket-upload-file")
@IgnoreLogin
public RestResponse getCustomFieldFromUdeskTemplates(HttpServletRequest request) throws Exception {
......@@ -59,9 +77,14 @@ public class GicTicketController {
if (file.isEmpty()) {
return RestResponse.failure(ErrorCode.PARAMETER_ERROR.getCode(), "文件为空");
}
ServiceResponse<String> result = udeskBaseApiService.ticketUploadFile(file.getBytes(), file.getOriginalFilename(),
Integer.parseInt(ticketId));
return ResultControllerUtils.commonResult(result);
LOGGER.info("udesk工单上传附件");
String replyRespStr = UdeskHttpClientUtil.postUdeskJsonFromJsonForFile("/tickets/upload_file", Integer.parseInt(ticketId), file);
LOGGER.info("desk工单上传附件返回为{}", replyRespStr);
UploadFileDTO result = JSON.parseObject(replyRespStr, UploadFileDTO.class);
if (result.getCode() == 1000) {
return RestResponse.success();
}
return RestResponse.failure(ErrorCode.SYSTEM_ERROR.getCode(), result.getMessage());
}
/**
......
package com.gic.udesk.web.utils;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.net.URISyntaxException;
import java.security.NoSuchAlgorithmException;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import javax.net.ssl.SSLContext;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpEntity;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.*;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.config.Registry;
import org.apache.http.config.RegistryBuilder;
import org.apache.http.conn.socket.ConnectionSocketFactory;
import org.apache.http.conn.socket.LayeredConnectionSocketFactory;
import org.apache.http.conn.socket.PlainConnectionSocketFactory;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.apache.http.entity.mime.HttpMultipartMode;
import org.apache.http.entity.mime.MultipartEntityBuilder;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
import org.apache.http.util.EntityUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.web.multipart.MultipartFile;
public class UdeskHttpClientUtil {
private static final Logger logger = LogManager.getLogger(UdeskHttpClientUtil.class);
private static PoolingHttpClientConnectionManager connectionManager = null;
private static CloseableHttpClient httpClient = null;
static {
LayeredConnectionSocketFactory sslsf = null;
try {
sslsf = new SSLConnectionSocketFactory(SSLContext.getDefault());
Registry<ConnectionSocketFactory> socketFactoryRegistry = RegistryBuilder.<ConnectionSocketFactory>create()
.register("https", sslsf).register("http", new PlainConnectionSocketFactory()).build();
connectionManager = new PoolingHttpClientConnectionManager(socketFactoryRegistry);
connectionManager.setMaxTotal(500);
connectionManager.setDefaultMaxPerRoute(100);
httpClient = HttpClients.custom().setConnectionManager(connectionManager).build();
} catch (NoSuchAlgorithmException e) {
logger.info("加载UdeskHttpClientUtil失败", e);
}
}
/**
* udesk的post请求,Request Body 上传文件参数天聪
*/
public static String postUdeskJsonFromJsonForFile(String url, Integer ticketId, MultipartFile file) {
long timeStamp = System.currentTimeMillis() / 1000;
url = "http://demogic.udesk.cn/open_api_v1" + url + "?email=jingjiawei@demogic.com" + "&timestamp=" + timeStamp + "&sign=" + UdeskUtils.getSign(timeStamp);
logger.info(url);
CloseableHttpResponse response = null;
try {
HttpPost httpPost = new HttpPost(url);
response = getResponseForFile(file, ticketId, httpPost);
return EntityUtils.toString(response.getEntity(), "utf-8");
} catch (Exception e) {
logger.info("POST请求{}失败,参数ticketId:{}", url, ticketId, e);
} finally {
closeResponse(response);
}
return null;
}
/**
* 铁臂-使用httpclient自带的URIBuilder建立URI
* @param uri
* @param requestParams
* @return String
* @throws URISyntaxException
*/
private static String getURIBuilder(String uri, Map<String, Object> requestParams) throws URISyntaxException {
URIBuilder uriBuilder = new URIBuilder( uri);
if (requestParams != null && requestParams.size() > 0) {
for (Map.Entry<String, Object> entry : requestParams.entrySet()) {
String key = entry.getKey();
if (StringUtils.isNotBlank(key)) {
uriBuilder.setParameter(key, String.valueOf(entry.getValue()));
}
}
}
return uriBuilder.build().toString();
}
/**
* 拼接URL
*/
private static String getURL(String url, Map<String, Object> param) {
if (param != null && param.size() > 0) {
StringBuilder urlSB = new StringBuilder(url);
Set<Map.Entry<String, Object>> paramSet = param.entrySet();
boolean isFirst = true;
for (Map.Entry<String, Object> entry : paramSet) {
if (isFirst) {
urlSB.append("?");
isFirst = false;
} else {
urlSB.append("&");
}
urlSB.append(entry.getKey()).append("=").append(entry.getValue());
}
return urlSB.toString();
}
return url;
}
/**
* 关闭Response
*/
private static void closeResponse(CloseableHttpResponse response) {
if (response != null) {
try {
response.close();
} catch (Exception e) {
logger.info("关闭response失败", e);
}
}
}
/**
* 获取Response
*/
private static CloseableHttpResponse getResponse(String json, HttpPost httpPost)
throws IOException, ClientProtocolException {
CloseableHttpResponse response;
if (json != null && (!"".equals(json.trim()))) {
StringEntity entity = new StringEntity(json, ContentType.APPLICATION_JSON);
httpPost.setEntity(entity);
}
response = httpClient.execute(httpPost);
return response;
}
/**
* 上传文件填充
* @param file
* @param ticketId
* @param httpPost
* @return
* @throws IOException
* @throws ClientProtocolException
*/
private static CloseableHttpResponse getResponseForFile(MultipartFile file, Integer ticketId, HttpPost httpPost)
throws IOException, ClientProtocolException {
CloseableHttpResponse response;
//解决乱码,设置mode
MultipartEntityBuilder multipartEntityBuilder = MultipartEntityBuilder.create().setMode(HttpMultipartMode.RFC6532);
multipartEntityBuilder.addBinaryBody("file", file.getInputStream(), ContentType.APPLICATION_OCTET_STREAM, file.getOriginalFilename());
multipartEntityBuilder.addTextBody("ticket_id", ticketId.toString());
multipartEntityBuilder.addTextBody("file_name", file.getOriginalFilename());
HttpEntity httpEntity = multipartEntityBuilder.build();
httpPost.setEntity(httpEntity);
response = httpClient.execute(httpPost);
return response;
}
}
package com.gic.udesk.web.utils;
import org.apache.commons.codec.digest.DigestUtils;
public class UdeskUtils {
public static String getSign(long timeStamp){
return DigestUtils.sha1Hex("jingjiawei@demogic.com&2a83c020-2309-4064-b4eb-af1367425c99&" +timeStamp);
}
}
......@@ -18,5 +18,6 @@
<dubbo:reference interface="com.gic.udesk.service.TapdMessageApiService" id="tapdMessageApiService" timeout="6000"/>
<dubbo:reference interface="com.gic.udesk.service.TapdConfigApiService" id="tapdConfigApiService" timeout="6000"/>
<dubbo:reference interface="com.gic.udesk.service.UdeskBaseApiService" id="udeskBaseApiService" timeout="6000"/>
<dubbo:reference interface="com.gic.udesk.service.GicTicketApiService" id="gicTicketApiService" timeout="6000"/>
</beans>
\ No newline at end of file
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