Commit 20f7477e authored by 廖旭伟's avatar 廖旭伟

用户常用模块收藏功能

parent 883197c3
...@@ -5,9 +5,9 @@ import com.alibaba.fastjson.JSONObject; ...@@ -5,9 +5,9 @@ import com.alibaba.fastjson.JSONObject;
import com.mortals.framework.annotation.UnAuth; import com.mortals.framework.annotation.UnAuth;
import com.mortals.framework.common.Rest; import com.mortals.framework.common.Rest;
import com.mortals.framework.exception.AppException; import com.mortals.framework.exception.AppException;
import com.mortals.framework.model.Context;
import com.mortals.framework.util.StringUtils; import com.mortals.framework.util.StringUtils;
import com.mortals.framework.web.BaseJsonBodyController; import com.mortals.framework.web.BaseJsonBodyController;
import com.mortals.xhx.common.code.ModelTypeEnum;
import com.mortals.xhx.common.code.YesNoEnum; import com.mortals.xhx.common.code.YesNoEnum;
import com.mortals.xhx.common.pdu.ModelPdu; import com.mortals.xhx.common.pdu.ModelPdu;
import com.mortals.xhx.feign.model.IApiModelFeign; import com.mortals.xhx.feign.model.IApiModelFeign;
...@@ -21,6 +21,7 @@ import org.springframework.web.bind.annotation.RequestBody; ...@@ -21,6 +21,7 @@ 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.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -97,9 +98,9 @@ public class ModelController extends BaseJsonBodyController { ...@@ -97,9 +98,9 @@ public class ModelController extends BaseJsonBodyController {
List<ModelFeignVO> modelFeignVOList = JSONObject.parseArray(apiResp.getData().get("data").toString(),ModelFeignVO.class); List<ModelFeignVO> modelFeignVOList = JSONObject.parseArray(apiResp.getData().get("data").toString(),ModelFeignVO.class);
List<ModelFeignVO> list = modelFeignVOList.stream().filter(item->map.containsKey(item.getId())).collect(Collectors.toList()); List<ModelFeignVO> list = modelFeignVOList.stream().filter(item->map.containsKey(item.getId())).collect(Collectors.toList());
if(this.getCurUser().getId()==1){ if(this.getCurUser().getId()==1){
model.put("data", modelFeignVOList); model.put("data", doGroup(modelFeignVOList));
}else { }else {
model.put("data", list); model.put("data", doGroup(list));
} }
model.put("message_info", busiDesc + "成功"); model.put("message_info", busiDesc + "成功");
this.recordSysLog(this.request, busiDesc + " 【成功】"); this.recordSysLog(this.request, busiDesc + " 【成功】");
...@@ -113,6 +114,21 @@ public class ModelController extends BaseJsonBodyController { ...@@ -113,6 +114,21 @@ public class ModelController extends BaseJsonBodyController {
return ret; return ret;
} }
private List<Map<String,List<ModelFeignVO>>> doGroup(List<ModelFeignVO> result){
Map<Integer,List<ModelFeignVO>> groupMap = result.stream().collect(Collectors.groupingBy(t -> t.getType()));
List<Map<String,List<ModelFeignVO>>> mapList = new ArrayList<>();
Map<String,List<ModelFeignVO>> jcMap = new HashMap<>();
jcMap.put(ModelTypeEnum.JC.getDesc(),groupMap.get(ModelTypeEnum.JC.getValue()));
mapList.add(jcMap);
Map<String,List<ModelFeignVO>> g2gMap = new HashMap<>();
g2gMap.put(ModelTypeEnum.G2G.getDesc(),groupMap.get(ModelTypeEnum.G2G.getValue()));
mapList.add(g2gMap);
Map<String,List<ModelFeignVO>> g2cMap = new HashMap<>();
g2cMap.put(ModelTypeEnum.G2C.getDesc(),groupMap.get(ModelTypeEnum.G2C.getValue()));
mapList.add(g2cMap);
return mapList;
}
/** /**
* 根据站点id查询数据管理列表 * 根据站点id查询数据管理列表
* @param query * @param query
......
package com.mortals.xhx.module.user.dao;
import com.mortals.framework.dao.ICRUDDao;
import com.mortals.xhx.module.user.model.UserModelCollectEntity;
import java.util.List;
/**
* 用户模块收藏Dao
* 用户模块收藏 DAO接口
*
* @author zxfei
* @date 2023-08-29
*/
public interface UserModelCollectDao extends ICRUDDao<UserModelCollectEntity,Long>{
}
package com.mortals.xhx.module.user.dao.ibatis;
import com.mortals.framework.dao.ibatis.BaseCRUDDaoMybatis;
import com.mortals.xhx.module.user.dao.UserModelCollectDao;
import com.mortals.xhx.module.user.model.UserModelCollectEntity;
import org.springframework.stereotype.Repository;
/**
* 用户模块收藏DaoImpl DAO接口
*
* @author zxfei
* @date 2023-08-29
*/
@Repository("userModelCollectDao")
public class UserModelCollectDaoImpl extends BaseCRUDDaoMybatis<UserModelCollectEntity,Long> implements UserModelCollectDao {
}
package com.mortals.xhx.module.user.model;
import java.util.List;
import java.util.ArrayList;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.mortals.framework.annotation.Excel;
import com.mortals.framework.model.BaseEntityLong;
import com.mortals.xhx.module.user.model.vo.UserModelCollectVo;
import lombok.Data;
/**
* 用户模块收藏实体对象
*
* @author zxfei
* @date 2023-08-29
*/
@Data
public class UserModelCollectEntity extends UserModelCollectVo {
private static final long serialVersionUID = 1L;
/**
* 用户ID,主键,自增长
*/
private Long userId;
/**
* 登录名
*/
private String realName;
/**
* 收藏模块
*/
private String modelIds;
@Override
public int hashCode() {
return this.getId().hashCode();
}
@Override
public boolean equals(Object obj) {
if (obj == null) return false;
if (obj instanceof UserModelCollectEntity) {
UserModelCollectEntity tmp = (UserModelCollectEntity) obj;
if (this.getId() == tmp.getId()) {
return true;
}
}
return false;
}
public void initAttrValue(){
this.userId = -1L;
this.realName = "";
this.modelIds = "";
}
}
\ No newline at end of file
package com.mortals.xhx.module.user.model.vo;
import com.mortals.framework.model.BaseEntityLong;
import com.mortals.xhx.module.user.model.UserModelCollectEntity;
import java.util.ArrayList;
import java.util.List;
import lombok.Data;
import com.mortals.framework.annotation.Excel;
import java.math.BigDecimal;
import java.util.Date;
/**
* 用户模块收藏视图对象
*
* @author zxfei
* @date 2023-08-29
*/
@Data
public class UserModelCollectVo extends BaseEntityLong {
}
\ No newline at end of file
package com.mortals.xhx.module.user.service;
import com.mortals.framework.service.ICRUDService;
import com.mortals.xhx.module.user.model.UserModelCollectEntity;
import com.mortals.xhx.module.user.dao.UserModelCollectDao;
/**
* UserModelCollectService
*
* 用户模块收藏 service接口
*
* @author zxfei
* @date 2023-08-29
*/
public interface UserModelCollectService extends ICRUDService<UserModelCollectEntity,Long>{
UserModelCollectDao getDao();
}
\ No newline at end of file
package com.mortals.xhx.module.user.service.impl;
import org.springframework.stereotype.Service;
import com.mortals.framework.service.impl.AbstractCRUDServiceImpl;
import com.mortals.framework.exception.AppException;
import com.mortals.framework.model.Context;
import com.mortals.xhx.module.user.dao.UserModelCollectDao;
import com.mortals.xhx.module.user.model.UserModelCollectEntity;
import com.mortals.xhx.module.user.service.UserModelCollectService;
import lombok.extern.slf4j.Slf4j;
/**
* UserModelCollectService
* 用户模块收藏 service实现
*
* @author zxfei
* @date 2023-08-29
*/
@Service("userModelCollectService")
@Slf4j
public class UserModelCollectServiceImpl extends AbstractCRUDServiceImpl<UserModelCollectDao, UserModelCollectEntity, Long> implements UserModelCollectService {
}
\ No newline at end of file
package com.mortals.xhx.module.user.web;
import com.alibaba.fastjson.JSONObject;
import com.mortals.framework.annotation.RepeatSubmit;
import com.mortals.framework.model.Context;
import com.mortals.framework.service.IUser;
import com.mortals.framework.util.StringUtils;
import com.mortals.framework.utils.BeanUtil;
import com.mortals.framework.utils.ReflectUtils;
import com.mortals.framework.web.BaseCRUDJsonBodyMappingController;
import com.mortals.xhx.module.user.model.UserModelCollectEntity;
import com.mortals.xhx.module.user.service.UserModelCollectService;
import org.springframework.beans.BeanUtils;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.PostMapping;
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.HashMap;
import java.util.Map;
/**
*
* 用户模块收藏
*
* @author zxfei
* @date 2023-08-29
*/
@RestController
@RequestMapping("user/model/collect")
public class UserModelCollectController extends BaseCRUDJsonBodyMappingController<UserModelCollectService,UserModelCollectEntity,Long> {
public UserModelCollectController(){
super.setModuleDesc( "用户模块收藏");
}
@Override
protected void init(Map<String, Object> model, Context context) {
super.init(model, context);
}
@PostMapping({"get"})
public String getCollect() {
Map<String, Object> model = new HashMap();
JSONObject ret = new JSONObject();
String busiDesc = "查看" + this.getModuleDesc();
Context context = this.getContext();
try {
UserModelCollectEntity query = new UserModelCollectEntity();
query.setUserId(this.getCurUser().getId());
UserModelCollectEntity entity = this.service.selectOne(query);
if (entity == null) {
entity = new UserModelCollectEntity();
entity.setUserId(this.getCurUser().getId());
entity.setRealName(this.getCurUser().getRealName());
entity.setModelIds("");
}
model.putAll(model);
model.put("entity", entity);
if (!ObjectUtils.isEmpty(context) && !ObjectUtils.isEmpty(context.getUser())) {
this.recordSysLog(this.request, busiDesc + " 【成功】");
}
} catch (Exception var8) {
this.doException(this.request, busiDesc, model, var8);
Object msg = model.get("message_info");
return this.createFailJsonResp(msg == null ? "系统异常" : msg.toString());
}
this.init(model, context);
ret.put("data", model);
ret.put("code", 1);
ret.put("msg", model.remove("message_info"));
return ret.toJSONString();
}
@Override
@PostMapping({"save"})
@RepeatSubmit
public String save(@RequestBody UserModelCollectEntity entity) {
Map<String, Object> model = new HashMap();
Context context = this.getContext();
int code = 1;
String busiDesc = "保存" + this.getModuleDesc();
if(StringUtils.isEmpty(entity.getModelIds())){
return this.createFailJsonResp("请选择要收藏的模块");
}
try {
UserModelCollectEntity query = new UserModelCollectEntity();
query.setUserId(this.getCurUser().getId());
UserModelCollectEntity temp = this.service.selectOne(query);
if (temp == null) {
Class<UserModelCollectEntity> tClass = ReflectUtils.getClassGenricType(this.getClass(), 1);
UserModelCollectEntity initEntity = (UserModelCollectEntity)tClass.newInstance();
initEntity.initAttrValue();
BeanUtils.copyProperties(entity, initEntity, BeanUtil.getNullPropertyNames(entity));
entity = initEntity;
busiDesc = "新增" + this.getModuleDesc();
initEntity.setCreateTime(new Date());
IUser user = this.getCurUser();
if (user != null) {
initEntity.setUserId(user.getId());
initEntity.setRealName(user.getRealName());
}
this.service.save(initEntity, context);
} else {
busiDesc = "修改" + this.getModuleDesc();
entity.setId(temp.getId());
this.service.update(entity, context);
}
model.put("id", entity.getId());
code = this.saveAfter(entity, model, context);
model.put("entity", entity);
model.put("message_info", busiDesc + "成功");
this.recordSysLog(this.request, busiDesc + " 【成功】 [id:" + entity.getId() + "]");
} catch (Exception var9) {
this.doException(this.request, busiDesc, model, var9);
model.put("entity", entity);
this.init(model, context);
code = this.saveException(entity, model, context, var9);
}
this.init(model, context);
JSONObject ret = new JSONObject();
ret.put("code", code);
ret.put("msg", model.remove("message_info"));
ret.put("data", model);
return ret.toJSONString();
}
}
\ No newline at end of file
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