Bläddra i källkod

新增消息模块

李书文 1 år sedan
förälder
incheckning
6d7e3a82a3

+ 42 - 30
sp-core/sp-api/src/main/java/com/pj/api/client/admin/AdminInterface.java

@@ -5,7 +5,9 @@ import com.pj.api.consts.FeignConsts;
 import com.pj.api.dto.AppUserDto;
 import com.pj.api.dto.DistrictDTO;
 import com.pj.api.dto.DistrictInfoDTO;
+import com.pj.api.dto.MessageDto;
 import org.springframework.cloud.openfeign.FeignClient;
+import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestParam;
 
@@ -13,40 +15,50 @@ import java.util.List;
 
 /**
  * 系统配置 服务
- * @author kong
  *
+ * @author kong
  */
 @FeignClient(
-		name = FeignConsts.SP_ADMIN, 				// 服务名称
-		configuration = FeignInterceptor.class,		// 请求拦截器 
-		fallbackFactory = AdminInterfaceFallback.class	// 服务降级
-		)	
+        name = FeignConsts.SP_ADMIN,                // 服务名称
+        configuration = FeignInterceptor.class,        // 请求拦截器
+        fallbackFactory = AdminInterfaceFallback.class    // 服务降级
+)
 public interface AdminInterface {
 
-	/** 启/停边民的app账号登陆限制 */
-	@RequestMapping("/AppUser/rpc/isLock")
-	int isLock(@RequestParam("id") String id,
-			   @RequestParam("type") Integer type,
-			   @RequestParam("status") Integer status);
-
-	/** 查单个app用户 - 根据id */
-	@RequestMapping("/AppUser/rpc/getById")
-	AppUserDto getAppUserById(@RequestParam("id") Long id);
-
-	/**
-	 * 根据城市名称查找地区数据
-	 * @param cityName
-	 * @return
-	 */
-	@RequestMapping("/TbDistrict/rpc/findInfoByCityName")
-	DistrictInfoDTO findInfoByCityName(String cityName);
-
-	/**
-	 * 根据IDs查找地区
-	 * @param ids
-	 * @return
-	 */
-	@RequestMapping(value = "TbDistrict/rpc/getByIds")
-	List<DistrictDTO> getDistrictList(@RequestParam("ids")String ids);
+    /**
+     * 启/停边民的app账号登陆限制
+     */
+    @RequestMapping("/AppUser/rpc/isLock")
+    int isLock(@RequestParam("id") String id,
+               @RequestParam("type") Integer type,
+               @RequestParam("status") Integer status);
+
+    /**
+     * 查单个app用户 - 根据id
+     */
+    @RequestMapping("/AppUser/rpc/getById")
+    AppUserDto getAppUserById(@RequestParam("id") Long id);
+
+
+    @RequestMapping("/TbMessage/rpc/save")
+    public void messageSave(@RequestBody MessageDto dto);
+
+    /**
+     * 根据城市名称查找地区数据
+     *
+     * @param cityName
+     * @return
+     */
+    @RequestMapping("/TbDistrict/rpc/findInfoByCityName")
+    DistrictInfoDTO findInfoByCityName(String cityName);
+
+    /**
+     * 根据IDs查找地区
+     *
+     * @param ids
+     * @return
+     */
+    @RequestMapping(value = "TbDistrict/rpc/getByIds")
+    List<DistrictDTO> getDistrictList(@RequestParam("ids") String ids);
 
 }

+ 47 - 42
sp-core/sp-api/src/main/java/com/pj/api/client/admin/AdminInterfaceFallback.java

@@ -3,6 +3,7 @@ package com.pj.api.client.admin;
 import com.pj.api.dto.DistrictDTO;
 import com.pj.api.dto.DistrictInfoDTO;
 import com.pj.api.dto.AppUserDto;
+import com.pj.api.dto.MessageDto;
 import feign.hystrix.FallbackFactory;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -12,50 +13,54 @@ import java.util.List;
 
 /**
  * 系统配置 服务降级处理
- * @author kong
  *
+ * @author kong
  */
 @Component
-public class AdminInterfaceFallback implements FallbackFactory<AdminInterface>
-{
-
-	private static final Logger log = LoggerFactory.getLogger(AdminInterfaceFallback.class);
-	
-	/**
-	 * 服务降级时触发的方法 
-	 */
-	@Override
-	public AdminInterface create(Throwable cause) {
-		
-		
-		log.error("--------------------系统配置服务异常,触发降级: {}", cause.getMessage());
-		
-		// 返回熔断后的对象 
-		return new AdminInterface() {
-
-			//启/停边民的app账号登陆限制
-			@Override
-			public int isLock(String id,Integer type,Integer status) {
-				log.error("错误的id:{},边民类型:{},状态:{},保护操作:{}",id,type,status,"熔断");
-				return 0;
-			}
-
-			@Override
-			public AppUserDto getAppUserById(Long id) {
-				log.error("错误的id:{},保护操作:{}",id,"熔断");
-				return null;
-			}
-
-			@Override
-			public DistrictInfoDTO findInfoByCityName(String cityName) {
-				return null;
-			}
-
-			@Override
-			public List<DistrictDTO> getDistrictList(String ids) {
-				return null;
-			}
-		};
-	}
+public class AdminInterfaceFallback implements FallbackFactory<AdminInterface> {
+
+    private static final Logger log = LoggerFactory.getLogger(AdminInterfaceFallback.class);
+
+    /**
+     * 服务降级时触发的方法
+     */
+    @Override
+    public AdminInterface create(Throwable cause) {
+
+
+        log.error("--------------------系统配置服务异常,触发降级: {}", cause.getMessage());
+
+        // 返回熔断后的对象
+        return new AdminInterface() {
+
+            //启/停边民的app账号登陆限制
+            @Override
+            public int isLock(String id, Integer type, Integer status) {
+                log.error("错误的id:{},边民类型:{},状态:{},保护操作:{}", id, type, status, "熔断");
+                return 0;
+            }
+
+            @Override
+            public AppUserDto getAppUserById(Long id) {
+                log.error("错误的id:{},保护操作:{}", id, "熔断");
+                return null;
+            }
+
+            @Override
+            public void messageSave(MessageDto dto) {
+                log.error("错误的id:{},保护操作:{}", dto, "熔断");
+            }
+
+            @Override
+            public DistrictInfoDTO findInfoByCityName(String cityName) {
+                return null;
+            }
+
+            @Override
+            public List<DistrictDTO> getDistrictList(String ids) {
+                return null;
+            }
+        };
+    }
 
 }

+ 90 - 0
sp-core/sp-api/src/main/java/com/pj/api/dto/MessageDto.java

@@ -0,0 +1,90 @@
+package com.pj.api.dto;
+
+import java.util.Date;
+
+/**
+ * Model: tb_message -- 通知消息
+ *
+ * @author lsw
+ */
+public class MessageDto {
+
+    /**
+     * 消息类型
+     */
+    private Integer types;
+
+    /**
+     * 消息类型
+     */
+    private Integer module;
+
+    /**
+     * 消息内容
+     */
+    private String contents;
+
+    /**
+     * 关联用户
+     */
+    private Long userId;
+
+    /**
+     * 创建时间
+     */
+    private Date createTime;
+
+
+    /**
+     * 状态(0=禁用,1=启用)
+     */
+    private String enable;
+
+    public Integer getTypes() {
+        return types;
+    }
+
+    public void setTypes(Integer types) {
+        this.types = types;
+    }
+
+    public Integer getModule() {
+        return module;
+    }
+
+    public void setModule(Integer module) {
+        this.module = module;
+    }
+
+    public String getContents() {
+        return contents;
+    }
+
+    public void setContents(String contents) {
+        this.contents = contents;
+    }
+
+    public Long getUserId() {
+        return userId;
+    }
+
+    public void setUserId(Long userId) {
+        this.userId = userId;
+    }
+
+    public Date getCreateTime() {
+        return createTime;
+    }
+
+    public void setCreateTime(Date createTime) {
+        this.createTime = createTime;
+    }
+
+    public String getEnable() {
+        return enable;
+    }
+
+    public void setEnable(String enable) {
+        this.enable = enable;
+    }
+}

+ 16 - 0
sp-service/level-two-server/src/main/java/com/pj/tb_demand_quotation/TbDemandQuotationService.java

@@ -3,7 +3,9 @@ package com.pj.tb_demand_quotation;
 import java.util.Date;
 import java.util.List;
 
+import com.pj.api.client.admin.AdminInterface;
 import com.pj.api.client.level_one_server.LevelOneServerInterface;
+import com.pj.api.dto.MessageDto;
 import com.pj.api.dto.PeopleDto;
 import com.pj.common.core.exception.ServiceException;
 import com.pj.current.dto.APPLoginUserInfo;
@@ -41,6 +43,13 @@ public class TbDemandQuotationService extends ServiceImpl<TbDemandQuotationMappe
      */
     @Autowired
     private LevelOneServerInterface levelOneServerInterface;
+
+    /**
+     * 远程调用
+     */
+    @Autowired
+    private AdminInterface adminInterface;
+
     /**
      * 失败重试机制
      */
@@ -137,6 +146,13 @@ public class TbDemandQuotationService extends ServiceImpl<TbDemandQuotationMappe
             //短信提示二级市场收购商,需求已报价,进入app进行确认接单
             TbPurchaser tbPurchaser = tbPurchaserMapper.selectById(tbGoodsDemand.getPurchaserId());
             if (tbPurchaser == null) throw new RuntimeException("二级商户信息异常!~");
+            //todo:给收购商发一条接单消息
+            MessageDto dto=new MessageDto();
+            dto.setEnable("1");
+            dto.setModule(2);
+            dto.setUserId(tbGoodsDemand.getPurchaserId());
+            dto.setContents("你的发布的"+tbGoodsDemand.getGoodsName()+"已有人接单,请及时确认。");
+            adminInterface.messageSave(dto);
             //todo:发送短信
 //			smsRetryService.sendSmsMsg(tbPurchaser.getContact());
             return true;

+ 81 - 0
sp-service/sp-admin/src/main/java/com/pj/project/tb_message/TbMessage.java

@@ -0,0 +1,81 @@
+package com.pj.project.tb_message;
+
+import java.io.Serializable;
+import java.util.Date;
+
+import com.baomidou.mybatisplus.annotation.*;
+import com.baomidou.mybatisplus.extension.activerecord.Model;
+import lombok.EqualsAndHashCode;
+
+import lombok.Data;
+import lombok.experimental.Accessors;
+
+/**
+ * Model: tb_message -- 通知消息
+ * @author lsw 
+ */
+@Data
+@Accessors(chain = true)
+@TableName(TbMessage.TABLE_NAME)
+@EqualsAndHashCode(callSuper = false)
+public class TbMessage extends Model<TbMessage> implements Serializable {
+
+	// ---------- 模块常量 ----------
+	/**
+	 * 序列化版本id 
+	 */
+	private static final long serialVersionUID = 1L;	
+	/**
+	 * 此模块对应的表名 
+	 */
+	public static final String TABLE_NAME = "tb_message";	
+	/**
+	 * 此模块对应的权限码 
+	 */
+	public static final String PERMISSION_CODE = "tb-message";
+	public static final String PERMISSION_CODE_ADD = "tb-message-add";
+	public static final String PERMISSION_CODE_EDIT = "tb-message-edit";
+	public static final String PERMISSION_CODE_DEL = "tb-message-del";
+
+
+
+
+	// ---------- 表中字段 ----------
+	/**
+	 *  
+	 */
+	@TableId(type = IdType.AUTO)
+	private Integer id;	
+
+	/**
+	 * 消息类型 
+	 */
+	private Integer types;	
+
+	/**
+	 * 消息类型 
+	 */
+	private Integer module;	
+
+	/**
+	 * 消息内容 
+	 */
+	private String contents;	
+
+	/**
+	 * 关联用户 
+	 */
+	private Long userId;
+
+	/**
+	 * 创建时间 
+	 */
+	private Date createTime;
+
+
+	/**
+	 * 状态(0=禁用,1=启用)
+	 */
+	private String enable;
+
+}

+ 45 - 0
sp-service/sp-admin/src/main/java/com/pj/project/tb_message/TbMessageAppController.java

@@ -0,0 +1,45 @@
+package com.pj.project.tb_message;
+
+import cn.dev33.satoken.annotation.SaCheckPermission;
+import com.pj.current.satoken.StpAPPUserUtil;
+import com.pj.project4sp.SP;
+import com.pj.utils.sg.AjaxJson;
+import com.pj.utils.so.SoMap;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.util.List;
+
+
+/**
+ * Controller: tb_message -- 通知消息
+ *
+ * @author lsw
+ */
+@RestController
+@RequestMapping("/app/TbMessage/")
+public class TbMessageAppController {
+
+    /**
+     * 底层 Service 对象
+     */
+    @Autowired
+    TbMessageService tbMessageService;
+
+    /**
+     * 消息中心
+     */
+    @RequestMapping("getList")
+    public AjaxJson getList() {
+        SoMap so = SoMap.getRequestSoMap();
+        so.put("enable", 1);
+        if (so.get("types").toString().equals("2")) {
+            so.put("userId", StpAPPUserUtil.getAPPLoginInfo().getLoginId());
+        }
+        List<TbMessage> list = tbMessageService.getList(so.startPage());
+        return AjaxJson.getPageData(so.getDataCount(), list);
+    }
+
+
+}

+ 114 - 0
sp-service/sp-admin/src/main/java/com/pj/project/tb_message/TbMessageController.java

@@ -0,0 +1,114 @@
+package com.pj.project.tb_message;
+
+import cn.dev33.satoken.annotation.SaCheckPermission;
+import com.pj.api.dto.DistrictInfoDTO;
+import com.pj.api.dto.MessageDto;
+import com.pj.project4sp.SP;
+import com.pj.utils.sg.AjaxJson;
+import com.pj.utils.so.SoMap;
+import org.apache.xmlbeans.impl.xb.xsdschema.Public;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.util.Date;
+import java.util.List;
+
+
+/**
+ * Controller: tb_message -- 通知消息
+ *
+ * @author lsw
+ */
+@RestController
+@RequestMapping("/TbMessage/")
+public class TbMessageController {
+
+    /**
+     * 底层 Service 对象
+     */
+    @Autowired
+    TbMessageService tbMessageService;
+
+    /**
+     * 增
+     */
+    @RequestMapping("add")
+    @SaCheckPermission(TbMessage.PERMISSION_CODE_ADD)
+    public AjaxJson add(TbMessage t) {
+        t.setTypes(1);
+        tbMessageService.add(t);
+        return AjaxJson.getSuccess();
+    }
+
+    /**
+     * 删
+     */
+    @RequestMapping("delete")
+    @SaCheckPermission(TbMessage.PERMISSION_CODE_DEL)
+    public AjaxJson delete(Long id) {
+        tbMessageService.delete(id);
+        return AjaxJson.getSuccess();
+    }
+
+    /**
+     * 删 - 根据id列表
+     */
+    @RequestMapping("deleteByIds")
+    @SaCheckPermission(TbMessage.PERMISSION_CODE_DEL)
+    public AjaxJson deleteByIds() {
+        List<Long> ids = SoMap.getRequestSoMap().getListByComma("ids", long.class);
+        int line = SP.publicMapper.deleteByIds(TbMessage.TABLE_NAME, ids);
+        return AjaxJson.getByLine(line);
+    }
+
+    /**
+     * 改
+     */
+    @RequestMapping("update")
+    @SaCheckPermission(TbMessage.PERMISSION_CODE_EDIT)
+    public AjaxJson update(TbMessage t) {
+        tbMessageService.update(t);
+        return AjaxJson.getSuccess();
+    }
+
+    /**
+     * 查 - 根据id
+     */
+    @RequestMapping("getById")
+    @SaCheckPermission(TbMessage.PERMISSION_CODE)
+    public AjaxJson getById(Integer id) {
+        TbMessage t = tbMessageService.getById(id);
+        return AjaxJson.getSuccessData(t);
+    }
+
+    /**
+     * 查集合 - 根据条件(参数为空时代表忽略指定条件)
+     */
+    @RequestMapping("getList")
+    @SaCheckPermission(TbMessage.PERMISSION_CODE)
+    public AjaxJson getList() {
+        SoMap so = SoMap.getRequestSoMap();
+        so.set("types", 1);
+        List<TbMessage> list = tbMessageService.getList(so.startPage());
+        return AjaxJson.getPageData(so.getDataCount(), list);
+    }
+
+    @RequestMapping(value = "rpc/save")
+    public AjaxJson save(@RequestBody MessageDto dto) {
+        System.out.println("远程调用:" + dto.getUserId());
+        TbMessage message = new TbMessage();
+        message.setEnable("1");
+        message.setContents(dto.getContents());
+        message.setTypes(2);
+        message.setUserId(dto.getUserId());
+        message.setCreateTime(new Date());
+        tbMessageService.save(message);
+/*        System.out.println("远程调用:"+t.toString());
+        t.setTypes(2);
+        tbMessageService.add(t);*/
+        return AjaxJson.getSuccess();
+    }
+
+}

+ 30 - 0
sp-service/sp-admin/src/main/java/com/pj/project/tb_message/TbMessageMapper.java

@@ -0,0 +1,30 @@
+package com.pj.project.tb_message;
+
+import java.util.List;
+
+import org.apache.ibatis.annotations.Mapper;
+
+import com.pj.utils.so.*;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.springframework.stereotype.Repository;
+
+/**
+ * Mapper: tb_message -- 通知消息
+ * @author lsw 
+ */
+
+@Mapper
+@Repository
+public interface TbMessageMapper extends BaseMapper <TbMessage> {
+
+
+
+	/**
+	 * 查集合 - 根据条件(参数为空时代表忽略指定条件)
+	 * @param so 参数集合 
+	 * @return 数据列表 
+	 */
+	List<TbMessage> getList(SoMap so);
+
+
+}

+ 53 - 0
sp-service/sp-admin/src/main/java/com/pj/project/tb_message/TbMessageMapper.xml

@@ -0,0 +1,53 @@
+<?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.pj.project.tb_message.TbMessageMapper">
+
+
+
+
+	<!-- ================================== 查询相关 ================================== -->
+	<!-- select id, types, module, contents, user_id, create_time from tb_message  -->
+	
+	<!-- 通用映射:自动模式 -->
+	<resultMap id="model" autoMapping="true" type="com.pj.project.tb_message.TbMessage"></resultMap>
+	
+	<!-- 公共查询sql片段 -->
+	<sql id="select_sql">
+		select * 
+		from tb_message 
+	</sql>
+
+	
+	<!-- 查集合 - 根据条件(参数为空时代表忽略指定条件) [G] -->
+	<select id="getList" resultMap="model">
+		<include refid="select_sql"></include>
+		<where>
+			<if test=' this.has("id") '> and id = #{id} </if>
+			<if test=' this.has("types") '> and types = #{types} </if>
+			<if test=' this.has("contents") '> and contents like concat('%', #{contents}, '%') </if>
+			<if test=' this.has("userId") '> and user_id = #{userId} </if>
+			<if test=' this.has("enable") '> and enable = #{enable} </if>
+			<if test=' this.has("createTime") '> and create_time = #{createTime} </if>
+		</where>
+		order by
+		<choose>
+			<when test='sortType == 1'> id desc </when>
+			<when test='sortType == 2'> types desc </when>
+			<when test='sortType == 3'> module desc </when>
+			<when test='sortType == 4'> contents desc </when>
+			<when test='sortType == 5'> user_id desc </when>
+			<when test='sortType == 6'> create_time desc </when>
+			<otherwise> id desc </otherwise>
+		</choose>
+	</select>
+	
+	
+	
+	
+	
+	
+	
+	
+	
+
+</mapper>

+ 68 - 0
sp-service/sp-admin/src/main/java/com/pj/project/tb_message/TbMessageService.java

@@ -0,0 +1,68 @@
+package com.pj.project.tb_message;
+
+import java.util.Date;
+import java.util.List;
+
+import com.pj.current.satoken.StpAPPUserUtil;
+import com.pj.utils.so.SoMap;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import org.springframework.transaction.annotation.Transactional;
+import com.pj.utils.sg.*;
+
+import javax.xml.crypto.Data;
+
+/**
+ * Service: tb_message -- 通知消息
+ *
+ * @author lsw
+ */
+@Service
+@Transactional(rollbackFor = Exception.class)
+public class TbMessageService extends ServiceImpl<TbMessageMapper, TbMessage> implements IService<TbMessage> {
+
+    /**
+     * 底层 Mapper 对象
+     */
+    @Autowired
+    TbMessageMapper tbMessageMapper;
+
+    /**
+     * 增
+     */
+    void add(TbMessage t) {
+        t.setCreateTime(new Date());
+        save(t);
+    }
+
+    /**
+     * 删
+     */
+    void delete(Long id) {
+        removeById(id);
+    }
+
+    /**
+     * 改
+     */
+    void update(TbMessage t) {
+        updateById(t);
+
+    }
+
+    /**
+     * 查
+     */
+    TbMessage getById(Integer id) {
+        return super.getById(id);
+    }
+
+    /**
+     * 查集合 - 根据条件(参数为空时代表忽略指定条件)
+     */
+    List<TbMessage> getList(SoMap so) {
+        return tbMessageMapper.getList(so);
+    }
+}

+ 29 - 0
sp-service/sp-admin/src/main/java/com/pj/project/tb_message/TbMessageUtil.java

@@ -0,0 +1,29 @@
+package com.pj.project.tb_message;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import com.pj.utils.sg.*;
+
+/**
+ * 工具类:tb_message -- 通知消息
+ * @author lsw 
+ *
+ */
+@Component
+public class TbMessageUtil {
+
+	
+	/** 底层 Mapper 对象 */
+	public static TbMessageMapper tbMessageMapper;
+	@Autowired
+	private void setTbMessageMapper(TbMessageMapper tbMessageMapper) {
+		TbMessageUtil.tbMessageMapper = tbMessageMapper;
+	}
+	
+
+
+	
+	
+	
+}