| @@ -0,0 +1,108 @@ | |||||
| package com.iformall.controller.basic; | |||||
| import com.github.pagehelper.PageInfo; | |||||
| import com.iformall.annotation.SystemControllerLog; | |||||
| import com.iformall.annotation.TenantIgnore; | |||||
| import com.iformall.common.ErrorCode; | |||||
| import com.iformall.common.Result; | |||||
| import com.iformall.common.ResultData; | |||||
| import com.iformall.controller.base.BaseController; | |||||
| import com.iformall.controller.base.DouyinBaseController; | |||||
| import com.iformall.controller.mem.AsyncTask; | |||||
| import com.iformall.domain.po.MallUserInfo; | |||||
| import com.iformall.domain.po.TtMallIm; | |||||
| import com.iformall.domain.po.TtMerchantPoi; | |||||
| import com.iformall.domain.po.base.BaseEntity; | |||||
| import com.iformall.enums.EnumSupplierMathStatus; | |||||
| import com.iformall.exception.MallinkException; | |||||
| import com.iformall.service.TtMallImService; | |||||
| import com.iformall.service.TtMerchantPoiService; | |||||
| import com.iformall.utils.Constant; | |||||
| import io.swagger.annotations.ApiImplicitParam; | |||||
| import io.swagger.annotations.ApiImplicitParams; | |||||
| import io.swagger.annotations.ApiOperation; | |||||
| import org.apache.commons.lang3.StringUtils; | |||||
| import org.slf4j.Logger; | |||||
| import org.slf4j.LoggerFactory; | |||||
| import org.springframework.beans.factory.annotation.Autowired; | |||||
| import org.springframework.data.redis.core.StringRedisTemplate; | |||||
| import org.springframework.web.bind.annotation.*; | |||||
| import org.springframework.web.multipart.MultipartFile; | |||||
| import javax.servlet.http.HttpServletRequest; | |||||
| import javax.servlet.http.HttpServletResponse; | |||||
| import java.io.BufferedInputStream; | |||||
| import java.io.File; | |||||
| import java.io.FileOutputStream; | |||||
| import java.io.IOException; | |||||
| import java.util.List; | |||||
| import java.util.Map; | |||||
| import java.util.concurrent.TimeUnit; | |||||
| /** | |||||
| * @author gongbiao | |||||
| */ | |||||
| @RestController | |||||
| @RequestMapping("mallIm") | |||||
| public class TtMallImController extends BaseController { | |||||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | |||||
| @Autowired | |||||
| private TtMallImService ttMallImService; | |||||
| @ApiOperation("分页列表接口") | |||||
| @GetMapping("list") | |||||
| @ApiImplicitParams({ | |||||
| @ApiImplicitParam(name = "pageNum", value = "页数", dataType = "int", paramType = "query", required = true), | |||||
| @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", paramType = "query", required = true)}) | |||||
| @SystemControllerLog(description = "列表") | |||||
| public ResultData list(@ModelAttribute TtMallIm record, Integer pageNum, Integer pageSize) { | |||||
| logger.debug("[" + getIpAddr() + "] TtMallImController::list"); | |||||
| if (null == record) record = new TtMallIm(); | |||||
| record.updateTenantInfo(getTenantInfo()); | |||||
| record.setSortColumns(BaseEntity.SortField.UpdateDate_DESC); | |||||
| final PageInfo<TtMallIm> page = ttMallImService.listAsPage(record, pageNum, pageSize); | |||||
| return new ResultData(page); | |||||
| } | |||||
| @ApiOperation("保存") | |||||
| @PostMapping("save") | |||||
| @SystemControllerLog(description = "保存") | |||||
| public ResultData save(@RequestBody TtMallIm record) { | |||||
| logger.debug("[" + getIpAddr() + "] TtMallImController::save"); | |||||
| record.setId(null); | |||||
| record.updateTenantInfo(getTenantInfo()); | |||||
| if (StringUtils.isBlank(record.getImId())) { | |||||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "imId为空"); | |||||
| } | |||||
| ttMallImService.saveOrUpdate(record); | |||||
| return new ResultData(); | |||||
| } | |||||
| @ApiOperation("更新接口") | |||||
| @PostMapping("updateById") | |||||
| @SystemControllerLog(description = "更新") | |||||
| public ResultData updateById(@RequestBody TtMallIm record) { | |||||
| logger.debug("[" + getIpAddr() + "] TtMallImController::updateById"); | |||||
| if (record.getId() == null) { | |||||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL); | |||||
| } | |||||
| ttMallImService.saveOrUpdate(record); | |||||
| return new ResultData(record); | |||||
| } | |||||
| @ApiOperation("根据id删除接口") | |||||
| @GetMapping("/del") | |||||
| @ApiImplicitParam(name = "id", value = "id", dataType = "Long", paramType = "query", required = true) | |||||
| @SystemControllerLog(description = "商户-删除") | |||||
| public ResultData delete(Long id) { | |||||
| logger.debug("[" + getIpAddr() + "] TtMallImController::delete"); | |||||
| if (id == null) { | |||||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL); | |||||
| } | |||||
| ttMallImService.deleteById(id); | |||||
| return new ResultData(Result.SUCCESS, "删除成功", null); | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,44 @@ | |||||
| package com.iformall.controller; | |||||
| import com.iformall.common.ResultData; | |||||
| import com.iformall.domain.po.TtMallIm; | |||||
| import com.iformall.enums.EnumImStatus; | |||||
| import com.iformall.service.TtMallImService; | |||||
| import io.swagger.annotations.ApiOperation; | |||||
| import org.slf4j.Logger; | |||||
| import org.slf4j.LoggerFactory; | |||||
| import org.springframework.beans.factory.annotation.Autowired; | |||||
| import org.springframework.web.bind.annotation.*; | |||||
| import java.util.List; | |||||
| import java.util.Random; | |||||
| /** | |||||
| * @author | |||||
| */ | |||||
| @RestController | |||||
| @RequestMapping("api/mallIm") | |||||
| public class TtMallImController extends BaseController { | |||||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | |||||
| @Autowired | |||||
| private TtMallImService ttMallImService; | |||||
| @ApiOperation("获取客服") | |||||
| @GetMapping("getIm") | |||||
| public ResultData getIm() { | |||||
| logger.debug("[" + getIpAddr() + "] TtMallImController::getIm"); | |||||
| TtMallIm record = new TtMallIm(); | |||||
| record.updateTenantInfo(getTenantInfo()); | |||||
| record.setStatus(EnumImStatus.online.getCode()); | |||||
| List<TtMallIm> list = ttMallImService.findList(record); | |||||
| if(list == null || list.isEmpty()){ | |||||
| return new ResultData(); | |||||
| }else if(list.size() == 1){ | |||||
| return new ResultData(list.get(0)); | |||||
| } | |||||
| Random rand = new Random(); | |||||
| return new ResultData(list.get(rand.nextInt(list.size()))); | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,33 @@ | |||||
| package com.iformall.domain.po; | |||||
| import com.baomidou.mybatisplus.annotation.TableField; | |||||
| import com.baomidou.mybatisplus.annotation.TableName; | |||||
| import com.iformall.domain.po.base.TenantEntity; | |||||
| import lombok.Data; | |||||
| import lombok.EqualsAndHashCode; | |||||
| import java.util.Date; | |||||
| import java.util.List; | |||||
| @TableName(value = "tt_mall_im") | |||||
| @Data | |||||
| @EqualsAndHashCode(callSuper = true) | |||||
| public class TtMallIm extends TenantEntity { | |||||
| protected Long id; | |||||
| @io.swagger.annotations.ApiModelProperty(value="",name="imId") | |||||
| private String imId; | |||||
| @io.swagger.annotations.ApiModelProperty(value="",name="name") | |||||
| private String name; | |||||
| @io.swagger.annotations.ApiModelProperty(value="EnumImStatus ",name="status") | |||||
| private Integer status; | |||||
| @io.swagger.annotations.ApiModelProperty(value="创建时间",name="createDate") | |||||
| private Date createDate; | |||||
| @io.swagger.annotations.ApiModelProperty(value="更新时间",name="updateDate") | |||||
| private Date updateDate; | |||||
| } | |||||
| @@ -0,0 +1,35 @@ | |||||
| package com.iformall.enums; | |||||
| /** | |||||
| * | |||||
| */ | |||||
| public enum EnumImStatus { | |||||
| online(1, "在线"), | |||||
| offline(2, "离线"), | |||||
| ; | |||||
| public static EnumImStatus getEnum(Integer code) { | |||||
| for (EnumImStatus value : values()) { | |||||
| if (value.getCode().equals(code)) { | |||||
| return value; | |||||
| } | |||||
| } | |||||
| return null; | |||||
| } | |||||
| private Integer code; | |||||
| private String message; | |||||
| EnumImStatus(Integer code, String message) { | |||||
| this.code = code; | |||||
| this.message = message; | |||||
| } | |||||
| public Integer getCode() { | |||||
| return code; | |||||
| } | |||||
| public String getMessage() { | |||||
| return message; | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,14 @@ | |||||
| package com.iformall.mapper; | |||||
| import com.iformall.common.CommonMapper; | |||||
| import com.iformall.domain.po.TtMallIm; | |||||
| import java.util.List; | |||||
| public interface TtMallImMapper extends CommonMapper<TtMallIm, Long> { | |||||
| List<TtMallIm> findList(TtMallIm recordVo); | |||||
| int deleteById(Long Id); | |||||
| } | |||||
| @@ -0,0 +1,18 @@ | |||||
| package com.iformall.service; | |||||
| import com.github.pagehelper.PageInfo; | |||||
| import com.iformall.domain.po.TtMallIm; | |||||
| import com.iformall.domain.po.base.TenantEntity; | |||||
| import java.util.List; | |||||
| public interface TtMallImService { | |||||
| List<TtMallIm> findList(TtMallIm record); | |||||
| PageInfo<TtMallIm> listAsPage(TtMallIm record, Integer pageIndex, Integer pageSize); | |||||
| void saveOrUpdate(TtMallIm record); | |||||
| void deleteById(Long id); | |||||
| } | |||||
| @@ -0,0 +1,70 @@ | |||||
| package com.iformall.service.impl; | |||||
| import com.github.pagehelper.PageHelper; | |||||
| import com.github.pagehelper.PageInfo; | |||||
| import com.iformall.common.IdWorker; | |||||
| import com.iformall.domain.po.TtMallIm; | |||||
| import com.iformall.enums.EnumImStatus; | |||||
| import com.iformall.mapper.TtMallImMapper; | |||||
| import com.iformall.service.TtMallImService; | |||||
| import org.slf4j.Logger; | |||||
| import org.slf4j.LoggerFactory; | |||||
| import org.springframework.beans.factory.annotation.Autowired; | |||||
| import org.springframework.beans.factory.annotation.Qualifier; | |||||
| import org.springframework.data.redis.core.RedisTemplate; | |||||
| import org.springframework.stereotype.Service; | |||||
| import java.util.ArrayList; | |||||
| import java.util.Date; | |||||
| import java.util.List; | |||||
| import java.util.stream.Collectors; | |||||
| @Service | |||||
| public class TtMallImServiceImpl implements TtMallImService { | |||||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | |||||
| @Autowired | |||||
| TtMallImMapper ttMallImMapper; | |||||
| @Autowired | |||||
| @Qualifier("objectCommonRedisTemplate") | |||||
| RedisTemplate<String, Object> categoryRedisTemplate; | |||||
| @Override | |||||
| public List<TtMallIm> findList(TtMallIm record) { | |||||
| return ttMallImMapper.findList(record); | |||||
| } | |||||
| @Override | |||||
| public PageInfo<TtMallIm> listAsPage(TtMallIm record, Integer pageIndex, Integer pageSize) { | |||||
| return PageHelper.startPage(pageIndex, pageSize).doSelectPageInfo(() -> ttMallImMapper.findList(record)); | |||||
| } | |||||
| @Override | |||||
| public void saveOrUpdate(TtMallIm record) { | |||||
| Date nowDate = new Date(); | |||||
| if (record.getId() == null) { | |||||
| //record.setId(UUID.randomUUID().toString().replaceAll("-", "")); | |||||
| final IdWorker idWorker = IdWorker.get(); | |||||
| record.setId(idWorker.nextId()); | |||||
| if(record.getStatus() == null){ | |||||
| record.setStatus(EnumImStatus.online.getCode()); | |||||
| } | |||||
| record.setCreateDate(nowDate); | |||||
| record.setUpdateDate(nowDate); | |||||
| ttMallImMapper.insert(record); | |||||
| } else { | |||||
| record.setUpdateDate(nowDate); | |||||
| ttMallImMapper.updateById(record); | |||||
| } | |||||
| } | |||||
| @Override | |||||
| public void deleteById(Long id) { | |||||
| ttMallImMapper.deleteById(id); | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,56 @@ | |||||
| <?xml version="1.0" encoding="UTF-8"?> | |||||
| <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | |||||
| <mapper namespace="com.iformall.mapper.TtMallImMapper"> | |||||
| <resultMap id="BaseResultMap" type="com.iformall.domain.po.TtMallIm"> | |||||
| <id column="id" jdbcType="BIGINT" property="id"/> | |||||
| <result column="tenant_id" jdbcType="VARCHAR" property="tenantId"/> | |||||
| <result column="parent_tenant_id" jdbcType="VARCHAR" property="parentTenantId"/> | |||||
| <result column="im_id" jdbcType="VARCHAR" property="imId"/> | |||||
| <result column="name" jdbcType="VARCHAR" property="name"/> | |||||
| <result column="status" jdbcType="INTEGER" property="status" /> | |||||
| <result column="create_date" jdbcType="TIMESTAMP" property="createDate"/> | |||||
| <result column="update_date" jdbcType="TIMESTAMP" property="updateDate"/> | |||||
| </resultMap> | |||||
| <sql id="allColumns"> | |||||
| `id`,`tenant_id`,`parent_tenant_id`,`im_id`,`name`,`status`,`create_date`,`update_date` | |||||
| </sql> | |||||
| <sql id="dynamicWhereConditions"> | |||||
| where `is_del` = 0 | |||||
| <if test=" null != id "> | |||||
| and `id` = #{id} | |||||
| </if> | |||||
| <if test=" null != tenantId and '' != tenantId"> | |||||
| and `tenant_id` = #{tenantId} | |||||
| </if> | |||||
| <if test=" null != parentTenantId and '' != parentTenantId"> | |||||
| and `parent_tenant_id` = #{parentTenantId} | |||||
| </if> | |||||
| <if test=" null != imId and '' != imId"> | |||||
| and `im_id` = #{imId} | |||||
| </if> | |||||
| <if test=" null != name and '' != name"> | |||||
| and `name` like concat('%', #{name},'%') | |||||
| </if> | |||||
| <if test=" null != ids "> | |||||
| and `id` in | |||||
| <foreach collection="ids" index="index" item="idItem" open="(" separator="," close=")"> | |||||
| #{idItem} | |||||
| </foreach> | |||||
| </if> | |||||
| <if test=" null != sortColumns"> order by ${sortColumns} </if> | |||||
| </sql> | |||||
| <select id="findList" parameterType="com.iformall.domain.po.TtMallIm" resultMap="BaseResultMap"> | |||||
| select <include refid="allColumns" /> from tt_mall_im | |||||
| <include refid="dynamicWhereConditions" /> | |||||
| </select> | |||||
| <delete id="deleteById" parameterType="Long"> | |||||
| update tt_mall_im set is_del = 1,update_date=now() where id = #{id} | |||||
| </delete> | |||||
| </mapper> | |||||