Commit 42894b64 authored by 廖旭伟's avatar 廖旭伟

用户常用模块收藏功能

parent d0625552
package com.mortals.xhx.module.user.web; package com.mortals.xhx.module.user.web;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.mortals.framework.annotation.RepeatSubmit; import com.mortals.framework.annotation.RepeatSubmit;
import com.mortals.framework.exception.AppException;
import com.mortals.framework.model.Context; import com.mortals.framework.model.Context;
import com.mortals.framework.service.IUser; import com.mortals.framework.service.IUser;
import com.mortals.framework.util.DataUtil;
import com.mortals.framework.util.StringUtils; import com.mortals.framework.util.StringUtils;
import com.mortals.framework.utils.BeanUtil; import com.mortals.framework.utils.BeanUtil;
import com.mortals.framework.utils.ReflectUtils; import com.mortals.framework.utils.ReflectUtils;
import com.mortals.framework.web.BaseCRUDJsonBodyMappingController; import com.mortals.framework.web.BaseCRUDJsonBodyMappingController;
import com.mortals.xhx.common.code.YesNoEnum;
import com.mortals.xhx.common.pdu.ModelPdu;
import com.mortals.xhx.feign.model.IApiModelFeign;
import com.mortals.xhx.feign.rsp.ApiResp;
import com.mortals.xhx.module.user.model.UserModelCollectEntity; import com.mortals.xhx.module.user.model.UserModelCollectEntity;
import com.mortals.xhx.module.user.service.UserModelCollectService; import com.mortals.xhx.module.user.service.UserModelCollectService;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils; import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import java.util.Date; import java.util.*;
import java.util.HashMap;
import java.util.Map;
/** /**
* *
* 用户模块收藏 * 用户模块收藏
...@@ -30,6 +38,9 @@ import java.util.Map; ...@@ -30,6 +38,9 @@ import java.util.Map;
@RequestMapping("user/model/collect") @RequestMapping("user/model/collect")
public class UserModelCollectController extends BaseCRUDJsonBodyMappingController<UserModelCollectService,UserModelCollectEntity,Long> { public class UserModelCollectController extends BaseCRUDJsonBodyMappingController<UserModelCollectService,UserModelCollectEntity,Long> {
@Autowired
private IApiModelFeign apiModelFeign;
public UserModelCollectController(){ public UserModelCollectController(){
super.setModuleDesc( "用户模块收藏"); super.setModuleDesc( "用户模块收藏");
} }
...@@ -46,7 +57,7 @@ public class UserModelCollectController extends BaseCRUDJsonBodyMappingControlle ...@@ -46,7 +57,7 @@ public class UserModelCollectController extends BaseCRUDJsonBodyMappingControlle
JSONObject ret = new JSONObject(); JSONObject ret = new JSONObject();
String busiDesc = "查看" + this.getModuleDesc(); String busiDesc = "查看" + this.getModuleDesc();
Context context = this.getContext(); Context context = this.getContext();
model.put("data", Collections.emptyList());
try { try {
UserModelCollectEntity query = new UserModelCollectEntity(); UserModelCollectEntity query = new UserModelCollectEntity();
query.setUserId(this.getCurUser().getId()); query.setUserId(this.getCurUser().getId());
...@@ -56,10 +67,24 @@ public class UserModelCollectController extends BaseCRUDJsonBodyMappingControlle ...@@ -56,10 +67,24 @@ public class UserModelCollectController extends BaseCRUDJsonBodyMappingControlle
entity.setUserId(this.getCurUser().getId()); entity.setUserId(this.getCurUser().getId());
entity.setRealName(this.getCurUser().getRealName()); entity.setRealName(this.getCurUser().getRealName());
entity.setModelIds(""); entity.setModelIds("");
}else {
if(StringUtils.isNotEmpty(entity.getModelIds())){
List<Long> idList = new ArrayList();
for(String id:entity.getModelIds().split(",")){
Long idL = DataUtil.converStr2Long(id,0l);
idList.add(idL);
}
ModelPdu pdu = new ModelPdu();
pdu.setIdList(idList);
String resp = apiModelFeign.getModelByQuery(pdu);
ApiResp<JSONObject> apiResp = JSON.parseObject(resp, ApiResp.class);
if (apiResp.getCode() != YesNoEnum.YES.getValue()) {
throw new AppException("获取站点列表信息失败:" + apiResp.getMsg());
}
model.put("data", apiResp.getData().get("data"));
}
} }
model.put("message_info", busiDesc + "成功");
model.putAll(model);
model.put("entity", entity);
if (!ObjectUtils.isEmpty(context) && !ObjectUtils.isEmpty(context.getUser())) { if (!ObjectUtils.isEmpty(context) && !ObjectUtils.isEmpty(context.getUser())) {
this.recordSysLog(this.request, busiDesc + " 【成功】"); this.recordSysLog(this.request, busiDesc + " 【成功】");
} }
...@@ -68,9 +93,7 @@ public class UserModelCollectController extends BaseCRUDJsonBodyMappingControlle ...@@ -68,9 +93,7 @@ public class UserModelCollectController extends BaseCRUDJsonBodyMappingControlle
Object msg = model.get("message_info"); Object msg = model.get("message_info");
return this.createFailJsonResp(msg == null ? "系统异常" : msg.toString()); return this.createFailJsonResp(msg == null ? "系统异常" : msg.toString());
} }
ret.put("data", model.get("data"));
this.init(model, context);
ret.put("data", model);
ret.put("code", 1); ret.put("code", 1);
ret.put("msg", model.remove("message_info")); ret.put("msg", model.remove("message_info"));
return ret.toJSONString(); return ret.toJSONString();
......
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