|
@@ -25,6 +25,7 @@ import org.springframework.web.client.RestTemplate;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* 粉丝标签controller
|
|
@@ -51,25 +52,39 @@ public class WxFansTagController {
|
|
|
|
|
|
/**
|
|
|
* 获取标签 如果标签不同步 默认就给他同步
|
|
|
+ *
|
|
|
* @param appid
|
|
|
- * @param data 查询参数
|
|
|
+ * @param data 查询参数
|
|
|
* @return
|
|
|
*/
|
|
|
@PostMapping("/list")
|
|
|
- public ResultInfo list(@PathVariable String appid, @RequestBody FiltersData data){
|
|
|
- if(appid!=null && !appid.equals("") && !appid.equals("all")){
|
|
|
+ public ResultInfo list(@PathVariable String appid, @RequestBody FiltersData data) {
|
|
|
+ if (appid != null && !appid.equals("") && !appid.equals("all")) {
|
|
|
List<FiltersUtils> filters = data.getFilters();
|
|
|
- filters.add(new FiltersUtils("appId","equal",appid));
|
|
|
-
|
|
|
+ filters.add(new FiltersUtils("appId", "equal", appid));
|
|
|
}
|
|
|
- try {
|
|
|
- WxMpUserTagService userTagService = wxService.switchoverTo(appid).getUserTagService();
|
|
|
|
|
|
+ try {
|
|
|
+ WxMpUserTagService userTagService = wxService.switchoverTo(appid).getUserTagService();
|
|
|
//自动同步 因为只有100个 同一个微信最多支持100个标签
|
|
|
List<WxUserTag> tagList = userTagService.tagGet();
|
|
|
- for(WxUserTag wxUserTag : tagList) {
|
|
|
+ List<String> tagNameList = tagService.queryAll(appid).stream().map(EsTagInfo::getTagName).collect(Collectors.toList());
|
|
|
+
|
|
|
+ new
|
|
|
+ for (WxUserTag wxUserTag : tagList) {
|
|
|
+ String tagName = wxUserTag.getName();
|
|
|
+ if(tagNameList.contains(tagName)){
|
|
|
+ tagNameList.remove(tagName);
|
|
|
+ }else {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ for (WxUserTag wxUserTag : tagList) {
|
|
|
QueryWrapper wrapper = new QueryWrapper();
|
|
|
- wrapper.eq("tagValue",wxUserTag.getId().toString());
|
|
|
+ wrapper.eq("tagValue", wxUserTag.getId().toString());
|
|
|
List<EsTagInfo> tags = tagService.list(wrapper);
|
|
|
if (tags == null || tags.size() == 0) {
|
|
|
EsTagInfo tag = new EsTagInfo();
|
|
@@ -80,16 +95,12 @@ public class WxFansTagController {
|
|
|
tagService.save(tag);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
-// Map<String, Object> body = restTemplate.postForEntity("http://" + client + "/memcount/AllTagList",data, HashMap.class).getBody();
|
|
|
- //totalCount
|
|
|
- //items
|
|
|
ResultInfo body = tagService.queryTagList(data);
|
|
|
|
|
|
- return ResultUtil.createSuccess(200,body);
|
|
|
+ return ResultUtil.createSuccess(200, body);
|
|
|
} catch (WxErrorException e) {
|
|
|
e.printStackTrace();
|
|
|
- ResultInfo result = new ResultInfo(0,500,null,"出错",new String[]{},0);
|
|
|
+ ResultInfo result = new ResultInfo(0, 500, null, "出错", new String[]{}, 0);
|
|
|
return result;
|
|
|
}
|
|
|
}
|
|
@@ -97,14 +108,15 @@ public class WxFansTagController {
|
|
|
|
|
|
/**
|
|
|
* 创建标签
|
|
|
+ *
|
|
|
* @param appid
|
|
|
- * @param tag 标签数据
|
|
|
+ * @param tag 标签数据
|
|
|
* @return
|
|
|
*/
|
|
|
@PostMapping("/add")
|
|
|
public ResultInfo addTag(@PathVariable String appid,
|
|
|
- @RequestBody EsTagInfo tag ){
|
|
|
- if(tag == null || tag.getTagName()==null || "".equals(tag.getTagName())){
|
|
|
+ @RequestBody EsTagInfo tag) {
|
|
|
+ if (tag == null || tag.getTagName() == null || "".equals(tag.getTagName())) {
|
|
|
return ResultUtil.createFail("标签名为空,请输入标签名!");
|
|
|
}
|
|
|
try {
|
|
@@ -118,42 +130,44 @@ public class WxFansTagController {
|
|
|
|
|
|
// ResultObject body = restTemplate.postForEntity("http://" + client + "/memcount/EditTag",tag, ResultObject.class).getBody();
|
|
|
|
|
|
- return ResultUtil.createSuccess(200,userTag);
|
|
|
+ return ResultUtil.createSuccess(200, userTag);
|
|
|
} catch (WxErrorException e) {
|
|
|
e.printStackTrace();
|
|
|
- if(e.getMessage().contains("错误代码:45157")){
|
|
|
- return ResultUtil.createFail(600,null);//标签已存在
|
|
|
- }else{
|
|
|
- return ResultUtil.createFail(199,e.getStackTrace());
|
|
|
+ if (e.getMessage().contains("错误代码:45157")) {
|
|
|
+ return ResultUtil.createFail(600, null);//标签已存在
|
|
|
+ } else {
|
|
|
+ return ResultUtil.createFail(199, e.getStackTrace());
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 删除标签
|
|
|
+ *
|
|
|
* @param appid
|
|
|
* @param idList
|
|
|
* @return
|
|
|
*/
|
|
|
@CrossOrigin
|
|
|
@RequestMapping("/delete")
|
|
|
- public ResultInfo deleteTag(@PathVariable String appid, @RequestParam("idList") Integer idList){
|
|
|
+ public ResultInfo deleteTag(@PathVariable String appid, @RequestParam("idList") Integer idList) {
|
|
|
try {
|
|
|
WxMpUserTagService userTagService = wxService.switchoverTo(appid).getUserTagService();
|
|
|
return tagService.deleteById(userTagService, idList);
|
|
|
} catch (WxErrorException e) {
|
|
|
e.printStackTrace();
|
|
|
- return ResultUtil.createFail(199,e.getStackTrace());
|
|
|
+ return ResultUtil.createFail(199, e.getStackTrace());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 修改标签
|
|
|
+ *
|
|
|
* @param appid
|
|
|
* @return
|
|
|
*/
|
|
|
@PutMapping("/update")
|
|
|
- public ResultInfo updateTag(@PathVariable String appid, @RequestBody EsTagInfo tag){
|
|
|
+ public ResultInfo updateTag(@PathVariable String appid, @RequestBody EsTagInfo tag) {
|
|
|
try {
|
|
|
WxMpUserTagService userTagService = wxService.switchoverTo(appid).getUserTagService();
|
|
|
Long id = Long.valueOf(tag.getTagValue());
|
|
@@ -164,20 +178,20 @@ public class WxFansTagController {
|
|
|
// ResultObject body = restTemplate.postForEntity("http://" + client + "/memcount/EditTag",tag, ResultObject.class).getBody();
|
|
|
|
|
|
Boolean update = userTagService.tagUpdate(id, name);
|
|
|
- return ResultUtil.createSuccess(200,update);
|
|
|
+ return ResultUtil.createSuccess(200, update);
|
|
|
} catch (WxErrorException e) {
|
|
|
e.printStackTrace();
|
|
|
|
|
|
- if(e.getMessage().contains("错误代码:45057")){
|
|
|
- return ResultUtil.createFail(601,e.getStackTrace());//
|
|
|
- }else{
|
|
|
- return ResultUtil.createFail(199,e.getStackTrace());
|
|
|
+ if (e.getMessage().contains("错误代码:45057")) {
|
|
|
+ return ResultUtil.createFail(601, e.getStackTrace());//
|
|
|
+ } else {
|
|
|
+ return ResultUtil.createFail(199, e.getStackTrace());
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@GetMapping("/queryAll")
|
|
|
- public ResultInfo queryAll(@PathVariable String appid){
|
|
|
+ public ResultInfo queryAll(@PathVariable String appid) {
|
|
|
return tagService.queryAll(appid);
|
|
|
}
|
|
|
|