AdminMessageController.java 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. package com.goafanti.message.controller;
  2. import java.text.ParseException;
  3. import java.util.Date;
  4. import java.util.HashMap;
  5. import java.util.Map;
  6. import java.util.regex.Pattern;
  7. import javax.annotation.Resource;
  8. import org.apache.commons.lang3.StringUtils;
  9. import org.springframework.web.bind.annotation.RequestMapping;
  10. import org.springframework.web.bind.annotation.RequestMethod;
  11. import org.springframework.web.bind.annotation.RestController;
  12. import com.alibaba.fastjson.JSONObject;
  13. import com.goafanti.common.bo.Result;
  14. import com.goafanti.common.constant.AFTConstants;
  15. import com.goafanti.common.constant.ErrorConstants;
  16. import com.goafanti.common.controller.CertifyApiController;
  17. import com.goafanti.common.error.BusinessException;
  18. import com.goafanti.common.model.JtMessageProducer;
  19. import com.goafanti.common.model.MessageFromSystem;
  20. import com.goafanti.common.utils.DateUtils;
  21. import com.goafanti.message.bo.MessageListBo;
  22. import com.goafanti.message.enums.ConsumerType;
  23. import com.goafanti.message.enums.RecommendType;
  24. import com.goafanti.message.enums.SubjectType;
  25. import com.goafanti.message.service.MessageService;
  26. /**
  27. * 消息推送
  28. * @author Administrator
  29. *
  30. */
  31. @RestController
  32. @RequestMapping(value = "/api/admin/message")
  33. public class AdminMessageController extends CertifyApiController{
  34. @Resource
  35. private MessageService messageService;
  36. /**
  37. * 进入创建系统消息
  38. */
  39. @RequestMapping(value = "/toCreateSystemMessage", method = RequestMethod.GET)
  40. public Result toCreateSystemMessage(){
  41. Result res = new Result();
  42. JSONObject jsonObject = new JSONObject();
  43. jsonObject.put("createTime", DateUtils.formatDate(new Date(), AFTConstants.YYYYMMDDHHMMSS));
  44. res.setData(jsonObject);
  45. return res;
  46. }
  47. /**
  48. *
  49. * @param companyIds 公司集
  50. * @param userIds 用户集
  51. * @param adminIds 运营人员
  52. * @param societyTags 社会属性集
  53. * @param provinceIds 省份集
  54. * @param cityIds 城市集
  55. * @param areas 区域集
  56. * @param roles 角色集
  57. * @param industryIds 行业
  58. * @param subject 0-运营消息 , 1-客户消息 , 2-技淘推荐
  59. * @param isDraft 是否草稿
  60. * @throws ParseException
  61. */
  62. @RequestMapping(value = "/createSystemMessage", method = RequestMethod.POST)
  63. public Result createSystemMessage(String personalUserIds,String organizationUserIds, String adminIds,String companyIds,String societyTags,String provinceIds,String cityIds,String areaIds,
  64. String roles,String industryIds,String title,String body,Integer subject,Integer targetType,String createTime,Integer isDraft) throws ParseException{
  65. Result res = new Result();
  66. if(null == targetType){
  67. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR,"", "必须指定人员类型"));
  68. return res;
  69. }
  70. if(null == subject){
  71. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR,"", "必须指定消息类型"));
  72. return res;
  73. }
  74. if(StringUtils.isBlank(title) || StringUtils.isBlank(body)){
  75. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR,"", "消息是的标题和内容不能为空"));
  76. return res;
  77. }
  78. if(null == isDraft){
  79. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR,"", "必须说明是否为草稿"));
  80. return res;
  81. }
  82. checkParam(personalUserIds,organizationUserIds,adminIds,companyIds,societyTags,provinceIds,cityIds,areaIds,roles,industryIds);
  83. Map<Integer,String> targetMap = new HashMap<Integer, String>();
  84. if(targetType == ConsumerType.PERSON_CUSTOMER_RETAIL.getTypeCode()) targetMap.put(targetType, personalUserIds);
  85. if(targetType == ConsumerType.ORGANIZATION_CUSTOMER_RETAIL.getTypeCode()) targetMap.put(targetType, organizationUserIds);
  86. if(targetType == ConsumerType.USER_RETAIL.getTypeCode()) targetMap.put(targetType, adminIds);
  87. if(targetType == ConsumerType.SOCIETY_TAG.getTypeCode()) targetMap.put(targetType, societyTags);
  88. if(targetType == ConsumerType.LOCATION.getTypeCode()){
  89. targetMap.put(targetType, ConsumerType.LOCATION.getTypeName());
  90. targetMap.put(ConsumerType.LOCATION_PROVINCE.getTypeCode(), provinceIds);
  91. targetMap.put(ConsumerType.LOCATION_CITY.getTypeCode(), cityIds);
  92. targetMap.put(ConsumerType.LOCATION_AREA.getTypeCode(), areaIds);
  93. }
  94. if(targetType == ConsumerType.COMPANY.getTypeCode()) targetMap.put(targetType, companyIds);
  95. if(targetType == ConsumerType.ROLE.getTypeCode()) targetMap.put(targetType, roles);
  96. if(targetType == ConsumerType.INDUSTRY.getTypeCode()) targetMap.put(targetType, industryIds);
  97. if(StringUtils.isBlank(targetMap.get(targetType))){
  98. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR,"", "必须选定目标群体"));
  99. return res;
  100. }
  101. messageService.insertSystemMessage(targetMap,targetType, title, body, subject,
  102. DateUtils.parseDate(createTime,AFTConstants.YYYYMMDDHHMMSS),isDraft);
  103. return res;
  104. }
  105. /**
  106. *
  107. * @param projectIds 项目
  108. * @param personalAchievementIds 个人成果
  109. * @param organizationAchievementIds 组织成果
  110. * @param personalDemandIds 个人需求
  111. * @param organizationDemandIds 组织需求
  112. * @param userIds 专家
  113. * @param newsIds 政策
  114. * @param sourceType 资源类型
  115. * @param userIds 用户类型
  116. * @param societyTags 社会属性
  117. * @param provinceIds 省
  118. * @param cityIds 市
  119. * @param areaIds 区
  120. * @param targetType 目标类型
  121. * @param isDraft 是否草稿
  122. * @return
  123. */
  124. @RequestMapping(value = "/createRecommendMessage", method = RequestMethod.POST)
  125. public Result createRecommendMessage(String projectIds,String personalAchievementIds,String organizationAchievementIds,
  126. String personalDemandIds,String organizationDemandIds, String expertIds, String newsIds,Integer sourceType,
  127. String personalUserIds,String organizationUserIds,String societyTags,String provinceIds,String cityIds,String areaIds,String industryIds,Integer targetType,Integer isDraft){
  128. Result res = new Result();
  129. if(null == sourceType){
  130. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR,"", "必须指定推荐类型"));
  131. return res;
  132. }
  133. if(null == targetType){
  134. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR,"", "必须指定目标群体"));
  135. return res;
  136. }
  137. if(null == isDraft){
  138. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR,"", "必须说明是否为草稿"));
  139. return res;
  140. }
  141. checkParam(projectIds,projectIds,personalAchievementIds,organizationAchievementIds,personalDemandIds,organizationDemandIds,
  142. expertIds,newsIds,personalUserIds,organizationUserIds,provinceIds,cityIds,areaIds,industryIds);
  143. Map<Integer,String> sourceMap = new HashMap<Integer, String>();
  144. if(sourceType == RecommendType.TECH_SERVICE.getTypeCode()) sourceMap.put(sourceType, projectIds);
  145. if(sourceType == RecommendType.PERSON_ACHIEVEMENT.getTypeCode()) sourceMap.put(sourceType, personalAchievementIds);
  146. if(sourceType == RecommendType.ORGANIZATION_ACHIEVEMENT.getTypeCode()) sourceMap.put(sourceType, organizationAchievementIds);
  147. if(sourceType == RecommendType.PERSONAL_DEMAND.getTypeCode()) sourceMap.put(sourceType, personalDemandIds);
  148. if(sourceType == RecommendType.ORGANIZATION_DEMAND.getTypeCode()) sourceMap.put(sourceType, organizationDemandIds);
  149. if(sourceType == RecommendType.EXPERT.getTypeCode()) sourceMap.put(sourceType, expertIds);
  150. if(sourceType == RecommendType.NEWS.getTypeCode()) sourceMap.put(sourceType, newsIds);
  151. if(StringUtils.isBlank(sourceMap.get(sourceType))){
  152. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR,"", "必须选定推荐内容"));
  153. return res;
  154. }
  155. Map<Integer,String> targetMap = new HashMap<Integer, String>();
  156. if(targetType == ConsumerType.PERSON_CUSTOMER_RETAIL.getTypeCode()) targetMap.put(targetType, personalUserIds);
  157. if(targetType == ConsumerType.ORGANIZATION_CUSTOMER_RETAIL.getTypeCode()) targetMap.put(targetType, organizationUserIds);
  158. if(targetType == ConsumerType.SOCIETY_TAG.getTypeCode()) targetMap.put(targetType, societyTags);
  159. if(targetType == ConsumerType.LOCATION.getTypeCode()){
  160. targetMap.put(targetType, ConsumerType.LOCATION.getTypeName());
  161. targetMap.put(ConsumerType.LOCATION_PROVINCE.getTypeCode(), provinceIds);
  162. targetMap.put(ConsumerType.LOCATION_CITY.getTypeCode(), cityIds);
  163. targetMap.put(ConsumerType.LOCATION_AREA.getTypeCode(), areaIds);
  164. }
  165. if(targetType == ConsumerType.INDUSTRY.getTypeCode()) targetMap.put(targetType, industryIds);
  166. if(StringUtils.isBlank(targetMap.get(targetType))){
  167. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR,"", "必须指定目标群体"));
  168. return res;
  169. }
  170. messageService.insertRecommendMessage(sourceMap,sourceType,targetMap,targetType,SubjectType.TUI_JIAN.getTypeCode(),isDraft);
  171. return res;
  172. }
  173. /**
  174. * 查看消息列表
  175. * @param isDraft 是否未草稿
  176. * @param subject 消息类型
  177. * @return
  178. */
  179. @RequestMapping(value = "/listSystemMessage", method = RequestMethod.GET)
  180. public Result listSystemMessage(Integer isDraft,Integer subject,Integer page,Integer pageNo,Integer pageSize){
  181. Result res = new Result();
  182. if(null == isDraft){
  183. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR,"", "消息发送状态不能为空"));
  184. return res;
  185. }
  186. /*if(null == subject){
  187. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "消息类型不能为空"));
  188. return res;
  189. }*/
  190. res.setData(messageService.listSystemMessage(isDraft, subject,pageNo,pageSize));
  191. return res;
  192. }
  193. /**
  194. * 更新消息
  195. * @param messageId 消息ID
  196. * @param title 消息标题
  197. * @param body 消息内容
  198. * @return
  199. */
  200. @RequestMapping(value = "/updateSystemMessage", method = RequestMethod.POST)
  201. public Result updateSystemMessage(String messageId,String title,String body,Integer isDraft){
  202. Result res = new Result();
  203. if(StringUtils.isBlank(messageId)){
  204. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR,"", "消息编号不能为空"));
  205. return res;
  206. }
  207. if(null == isDraft){
  208. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR,"", "消息发送状态不能为空"));
  209. return res;
  210. }
  211. if(StringUtils.isBlank(title) || StringUtils.isBlank(body)){
  212. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR,"", "消息标题和消息内容不能为空"));
  213. return res;
  214. }
  215. messageService.updateSystemMessage(messageId, title, body, isDraft);
  216. return res;
  217. }
  218. /**
  219. * 删除消息
  220. * @param messageId 消息ID
  221. * @return
  222. */
  223. @RequestMapping(value = "/deleteSystemMessage", method = RequestMethod.GET)
  224. public Result deleteSystemMessage(String messageId){
  225. Result res = new Result();
  226. if(StringUtils.isBlank(messageId)){
  227. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR,"", "消息编号为空"));
  228. return res;
  229. }
  230. messageService.deleteSystemMessage(messageId);
  231. return res;
  232. }
  233. /**
  234. * 读取消息详情
  235. * @param messageId 消息ID
  236. * @return
  237. */
  238. @RequestMapping(value = "/getSystemMessageDetail", method = RequestMethod.GET)
  239. public Result getSystemMessageDetail(String messageId){
  240. Result res = new Result();
  241. if(StringUtils.isBlank(messageId)){
  242. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR,"", "消息编号为空"));
  243. return res;
  244. }
  245. // 读取消息详情
  246. MessageFromSystem mfs = messageService.selectSystemMessageDetail(messageId);
  247. MessageListBo bo = new MessageListBo();
  248. bo.setCreateTime(mfs.getCreateTime() == null ? ""
  249. : DateUtils.formatDate(mfs.getCreateTime(), AFTConstants.YYYYMMDDHHMMSS));
  250. bo.setResourceType(String.valueOf(mfs.getResourceType()));
  251. bo.setSubject(String.valueOf(mfs.getSubject()));
  252. bo.setMessageId(mfs.getId());
  253. bo.setTitle(mfs.getTitle());
  254. bo.setBody(mfs.getBody());
  255. bo.setResourceId(mfs.getResourceId());
  256. bo.setConsumerType(""+mfs.getConsumerType());
  257. res.setData(bo);
  258. return res;
  259. }
  260. /**
  261. * 校验
  262. * @param ids
  263. */
  264. public void checkParam(String... ids){
  265. String regex = "^[0-9a-z-,]*$";
  266. for(String s:ids){
  267. if(StringUtils.isNotBlank(s) && !Pattern.matches(regex, s)){
  268. throw new BusinessException(buildError(ErrorConstants.PARAM_ERROR, "参数不合法", s));
  269. }
  270. }
  271. }
  272. /**
  273. * 新增消息接口
  274. * @param messageProducer
  275. * @return
  276. */
  277. @RequestMapping(value="/addMessage", method=RequestMethod.GET)
  278. public Result addMessage(JtMessageProducer messageProducer){
  279. Result res = new Result();
  280. //必填项的检查
  281. if(StringUtils.isBlank(messageProducer.getTitle())){
  282. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR,"", "消息标题不能为空"));
  283. }
  284. if(null == messageProducer.getSubject()){
  285. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR,"", "消息类别不能为空"));
  286. }
  287. if(null == messageProducer.getIsDraft()){
  288. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR,"", "消息是否为草稿没指定"));
  289. }
  290. if (res.getError().isEmpty()) {
  291. //新增消息
  292. res.setData(messageService.addMessage(messageProducer));
  293. }
  294. return res;
  295. }
  296. @RequestMapping(value="/sendMessage", method=RequestMethod.GET)
  297. public Result sendMessage(String messageId){
  298. return null;
  299. }
  300. }