From bfb51745db4fa9559de5c65f9deed50e7e4bcf2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E8=A3=95=E8=B4=A2?= Date: Tue, 19 Jul 2022 13:27:19 +0800 Subject: [PATCH] bug --- .../com/xm/core/ctrl/XmFuncController.java | 296 ++++++++++++++++++ .../main/java/com/xm/core/entity/XmFunc.java | 55 ++++ .../com/xm/core/service/XmFuncService.java | 24 ++ .../mapper/xm/core/dao/XmFuncMapper.xml | 184 +++++++++++ 4 files changed, 559 insertions(+) create mode 100644 xm-core/src/main/java/com/xm/core/ctrl/XmFuncController.java create mode 100644 xm-core/src/main/java/com/xm/core/entity/XmFunc.java create mode 100644 xm-core/src/main/java/com/xm/core/service/XmFuncService.java create mode 100644 xm-core/src/main/resources/mybatis/mapper/xm/core/dao/XmFuncMapper.xml diff --git a/xm-core/src/main/java/com/xm/core/ctrl/XmFuncController.java b/xm-core/src/main/java/com/xm/core/ctrl/XmFuncController.java new file mode 100644 index 00000000..21afa82b --- /dev/null +++ b/xm-core/src/main/java/com/xm/core/ctrl/XmFuncController.java @@ -0,0 +1,296 @@ +package com.xm.core.ctrl; + +import java.util.*; +import java.util.stream.Collectors; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.util.StringUtils; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; +import io.swagger.annotations.*; + +import static com.mdp.core.utils.ResponseHelper.*; +import static com.mdp.core.utils.BaseUtils.*; +import com.mdp.core.entity.Tips; +import com.mdp.core.err.BizException; +import com.mdp.mybatis.PageUtils; +import com.mdp.core.utils.RequestUtils; +import com.mdp.core.utils.NumberUtil; +import com.mdp.safe.client.entity.User; +import com.mdp.safe.client.utils.LoginUtils; +import com.mdp.swagger.ApiEntityParams; +import springfox.documentation.annotations.ApiIgnore; + +import com.xm.core.service.XmFuncService; +import com.xm.core.entity.XmFunc; + +/** + * url编制采用rest风格,如对xm_func 功能模块表的操作有增删改查,对应的url分别为:
+ * 组织 com 顶级模块 xm 大模块 core 小模块
+ * 实体 XmFunc 表 xm_func 当前主键(包括多主键): id; + ***/ +@RestController("xm.core.xmFuncController") +@RequestMapping(value="/**/core/xmFunc") +@Api(tags={"功能模块表操作接口"}) +public class XmFuncController { + + static Logger logger =LoggerFactory.getLogger(XmFuncController.class); + + @Autowired + private XmFuncService xmFuncService; + + + Map fieldsMap = toMap(new XmFunc()); + + + @ApiOperation( value = "查询功能模块表信息列表",notes=" ") + @ApiEntityParams( XmFunc.class ) + @ApiImplicitParams({ + @ApiImplicitParam(name="pageSize",value="每页大小,默认20条",required=false), + @ApiImplicitParam(name="pageNum",value="当前页码,从1开始",required=false), + @ApiImplicitParam(name="total",value="总记录数,服务器端收到0时,会自动计算总记录数,如果上传>0的不自动计算",required=false), + @ApiImplicitParam(name="count",value="是否计算总记录条数,如果count=true,则计算计算总条数,如果count=false 则不计算",required=false), + @ApiImplicitParam(name="orderBy",value="排序列 如性别、学生编号排序 orderBy = sex desc,student desc",required=false), + }) + @ApiResponses({ + @ApiResponse(code = 200,response=XmFunc.class,message = "{tips:{isOk:true/false,msg:'成功/失败原因',tipscode:'错误码'},total:总记录数,data:[数据对象1,数据对象2,...]}") + }) + @RequestMapping(value="/list",method=RequestMethod.GET) + public Map listXmFunc( @ApiIgnore @RequestParam Map xmFunc){ + Map m = new HashMap<>(); + Tips tips=new Tips("查询成功"); + RequestUtils.transformArray(xmFunc, "ids"); + PageUtils.startPage(xmFunc); + List> xmFuncList = xmFuncService.selectListMapByWhere(xmFunc); //列出XmFunc列表 + PageUtils.responePage(m, xmFuncList); + m.put("data",xmFuncList); + + m.put("tips", tips); + return m; + } + + + + /** + @ApiOperation( value = "新增一条功能模块表信息",notes=" ") + @ApiResponses({ + @ApiResponse(code = 200,response=XmFunc.class,message = "{tips:{isOk:true/false,msg:'成功/失败原因',tipscode:'失败时错误码'},data:数据对象}") + }) + @RequestMapping(value="/add",method=RequestMethod.POST) + public Map addXmFunc(@RequestBody XmFunc xmFunc) { + Map m = new HashMap<>(); + Tips tips=new Tips("成功新增一条数据"); + try{ + boolean createPk=false; + if(!StringUtils.hasText(xmFunc.getId())) { + createPk=true; + xmFunc.setId(xmFuncService.createKey("id")); + } + if(createPk==false){ + if(xmFuncService.selectOneObject(xmFunc) !=null ){ + return failed("pk-exists","编号重复,请修改编号再提交"); + } + } + xmFuncService.insert(xmFunc); + m.put("data",xmFunc); + }catch (BizException e) { + tips=e.getTips(); + logger.error("",e); + }catch (Exception e) { + tips.setFailureMsg(e.getMessage()); + logger.error("",e); + } + m.put("tips", tips); + return m; + } + */ + + /** + @ApiOperation( value = "删除一条功能模块表信息",notes=" ") + @ApiResponses({ + @ApiResponse(code = 200, message = "{tips:{isOk:true/false,msg:'成功/失败原因',tipscode:'失败时错误码'}}") + }) + @RequestMapping(value="/del",method=RequestMethod.POST) + public Map delXmFunc(@RequestBody XmFunc xmFunc){ + Map m = new HashMap<>(); + Tips tips=new Tips("成功删除一条数据"); + try{ + if(!StringUtils.hasText(xmFunc.getId())) { + return failed("pk-not-exists","请上送主键参数id"); + } + XmFunc xmFuncDb = xmFuncService.selectOneObject(xmFunc); + if( xmFuncDb == null ){ + return failed("data-not-exists","数据不存在,无法删除"); + } + xmFuncService.deleteByPk(xmFunc); + }catch (BizException e) { + tips=e.getTips(); + logger.error("",e); + }catch (Exception e) { + tips.setFailureMsg(e.getMessage()); + logger.error("",e); + } + m.put("tips", tips); + return m; + } + */ + + /** + @ApiOperation( value = "根据主键修改一条功能模块表信息",notes=" ") + @ApiResponses({ + @ApiResponse(code = 200,response=XmFunc.class, message = "{tips:{isOk:true/false,msg:'成功/失败原因',tipscode:'失败时错误码'},data:数据对象}") + }) + @RequestMapping(value="/edit",method=RequestMethod.POST) + public Map editXmFunc(@RequestBody XmFunc xmFunc) { + Map m = new HashMap<>(); + Tips tips=new Tips("成功更新一条数据"); + try{ + if(!StringUtils.hasText(xmFunc.getId())) { + return failed("pk-not-exists","请上送主键参数id"); + } + XmFunc xmFuncDb = xmFuncService.selectOneObject(xmFunc); + if( xmFuncDb == null ){ + return failed("data-not-exists","数据不存在,无法修改"); + } + xmFuncService.updateSomeFieldByPk(xmFunc); + m.put("data",xmFunc); + }catch (BizException e) { + tips=e.getTips(); + logger.error("",e); + }catch (Exception e) { + tips.setFailureMsg(e.getMessage()); + logger.error("",e); + } + m.put("tips", tips); + return m; + } + */ + + /** + @ApiOperation( value = "批量修改某些字段",notes="") + @ApiEntityParams( value = XmFunc.class, props={ }, remark = "功能模块表", paramType = "body" ) + @ApiResponses({ + @ApiResponse(code = 200,response=XmFunc.class, message = "{tips:{isOk:true/false,msg:'成功/失败原因',tipscode:'失败时错误码'},data:数据对象}") + }) + @RequestMapping(value="/editSomeFields",method=RequestMethod.POST) + public Map editSomeFields( @ApiIgnore @RequestBody Map xmFuncMap) { + Map m = new HashMap<>(); + Tips tips=new Tips("成功更新一条数据"); + try{ + List ids= (List) xmFuncMap.get("ids"); + if(ids==null || ids.size()==0){ + return failed("ids-0","ids不能为空"); + } + + Set fields=new HashSet<>(); + fields.add("id"); + for (String fieldName : xmFuncMap.keySet()) { + if(fields.contains(fieldName)){ + return failed(fieldName+"-no-edit",fieldName+"不允许修改"); + } + } + Set fieldKey=xmFuncMap.keySet().stream().filter(i-> fieldsMap.containsKey(i)).collect(Collectors.toSet()); + fieldKey=fieldKey.stream().filter(i->!StringUtils.isEmpty(xmFuncMap.get(i) )).collect(Collectors.toSet()); + + if(fieldKey.size()<=0) { + return failed("fieldKey-0","没有需要更新的字段"); + } + XmFunc xmFunc = fromMap(xmFuncMap,XmFunc.class); + List xmFuncsDb=xmFuncService.selectListByIds(ids); + if(xmFuncsDb==null ||xmFuncsDb.size()==0){ + return failed("data-0","记录已不存在"); + } + List can=new ArrayList<>(); + List no=new ArrayList<>(); + User user = LoginUtils.getCurrentUserInfo(); + for (XmFunc xmFuncDb : xmFuncsDb) { + Tips tips2 = new Tips("检查通过"); + if(!tips2.isOk()){ + no.add(xmFuncDb); + }else{ + can.add(xmFuncDb); + } + } + if(can.size()>0){ + xmFuncMap.put("ids",can.stream().map(i->i.getId()).collect(Collectors.toList())); + xmFuncService.editSomeFields(xmFuncMap); + } + List msgs=new ArrayList<>(); + if(can.size()>0){ + msgs.add(String.format("成功更新以下%s条数据",can.size())); + } + if(no.size()>0){ + msgs.add(String.format("以下%s个数据无权限更新",no.size())); + } + if(can.size()>0){ + tips.setOkMsg(msgs.stream().collect(Collectors.joining())); + }else { + tips.setFailureMsg(msgs.stream().collect(Collectors.joining())); + } + //m.put("data",xmMenu); + }catch (BizException e) { + tips=e.getTips(); + logger.error("",e); + }catch (Exception e) { + tips.setFailureMsg(e.getMessage()); + logger.error("",e); + } + m.put("tips", tips); + return m; + } + */ + + /** + @ApiOperation( value = "根据主键列表批量删除功能模块表信息",notes=" ") + @ApiResponses({ + @ApiResponse(code = 200, message = "{tips:{isOk:true/false,msg:'成功/失败原因',tipscode:'失败时错误码'}") + }) + @RequestMapping(value="/batchDel",method=RequestMethod.POST) + public Map batchDelXmFunc(@RequestBody List xmFuncs) { + Map m = new HashMap<>(); + Tips tips=new Tips("成功删除"); + try{ + if(xmFuncs.size()<=0){ + return failed("data-0","请上送待删除数据列表"); + } + List datasDb=xmFuncService.selectListByIds(xmFuncs.stream().map(i-> i.getId() ).collect(Collectors.toList())); + + List can=new ArrayList<>(); + List no=new ArrayList<>(); + for (XmFunc data : datasDb) { + if(true){ + can.add(data); + }else{ + no.add(data); + } + } + List msgs=new ArrayList<>(); + if(can.size()>0){ + xmFuncService.batchDelete(can); + msgs.add(String.format("成功删除%s条数据.",can.size())); + } + + if(no.size()>0){ + msgs.add(String.format("以下%s条数据不能删除.【%s】",no.size(),no.stream().map(i-> i.getId() ).collect(Collectors.joining(",")))); + } + if(can.size()>0){ + tips.setOkMsg(msgs.stream().collect(Collectors.joining())); + }else { + tips.setFailureMsg(msgs.stream().collect(Collectors.joining())); + } + }catch (BizException e) { + tips=e.getTips(); + logger.error("",e); + }catch (Exception e) { + tips.setFailureMsg(e.getMessage()); + logger.error("",e); + } + m.put("tips", tips); + return m; + } + */ +} diff --git a/xm-core/src/main/java/com/xm/core/entity/XmFunc.java b/xm-core/src/main/java/com/xm/core/entity/XmFunc.java new file mode 100644 index 00000000..93473e06 --- /dev/null +++ b/xm-core/src/main/java/com/xm/core/entity/XmFunc.java @@ -0,0 +1,55 @@ +package com.xm.core.entity; + +import lombok.Data; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + +/** + * 组织 com 顶级模块 xm 大模块 core 小模块
+ * 实体 XmFunc所有属性名:
+ * "id","主键","name","名称","pid","上级编号","pname","上级名称","pidPaths","上级路径,直到自身,逗号分割,包含自身","productId","产品编号","lvl","菜单级别0-根,1,2,3,4,5依次类推";
+ * 当前主键(包括多主键):
+ * id;
+ */ + @Data +@ApiModel(description="功能模块表") +public class XmFunc implements java.io.Serializable { + + private static final long serialVersionUID = 1L; + + @ApiModelProperty(notes="主键,主键",allowEmptyValue=true,example="",allowableValues="") + String id; + + + @ApiModelProperty(notes="名称",allowEmptyValue=true,example="",allowableValues="") + String name; + + @ApiModelProperty(notes="上级编号",allowEmptyValue=true,example="",allowableValues="") + String pid; + + @ApiModelProperty(notes="上级名称",allowEmptyValue=true,example="",allowableValues="") + String pname; + + @ApiModelProperty(notes="上级路径,直到自身,逗号分割,包含自身",allowEmptyValue=true,example="",allowableValues="") + String pidPaths; + + @ApiModelProperty(notes="产品编号",allowEmptyValue=true,example="",allowableValues="") + String productId; + + @ApiModelProperty(notes="菜单级别0-根,1,2,3,4,5依次类推",allowEmptyValue=true,example="",allowableValues="") + Integer lvl; + + /** + *主键 + **/ + public XmFunc(String id) { + this.id = id; + } + + /** + * 功能模块表 + **/ + public XmFunc() { + } + +} \ No newline at end of file diff --git a/xm-core/src/main/java/com/xm/core/service/XmFuncService.java b/xm-core/src/main/java/com/xm/core/service/XmFuncService.java new file mode 100644 index 00000000..d2b78e3b --- /dev/null +++ b/xm-core/src/main/java/com/xm/core/service/XmFuncService.java @@ -0,0 +1,24 @@ +package com.xm.core.service; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import java.util.List; +import java.util.Map; +import org.springframework.stereotype.Service; +import com.mdp.core.service.BaseService; +import static com.mdp.core.utils.BaseUtils.*; +import com.mdp.core.entity.Tips; +import com.mdp.core.err.BizException; + +import com.xm.core.entity.XmFunc; +/** + * 父类已经支持增删改查操作,因此,即使本类什么也不写,也已经可以满足一般的增删改查操作了.
+ * 组织 com 顶级模块 xm 大模块 core 小模块
+ * 实体 XmFunc 表 xm_func 当前主键(包括多主键): id; + ***/ +@Service("xm.core.xmFuncService") +public class XmFuncService extends BaseService { + static Logger logger =LoggerFactory.getLogger(XmFuncService.class); + +} + diff --git a/xm-core/src/main/resources/mybatis/mapper/xm/core/dao/XmFuncMapper.xml b/xm-core/src/main/resources/mybatis/mapper/xm/core/dao/XmFuncMapper.xml new file mode 100644 index 00000000..f4df9de9 --- /dev/null +++ b/xm-core/src/main/resources/mybatis/mapper/xm/core/dao/XmFuncMapper.xml @@ -0,0 +1,184 @@ + + + + + + + + + and (res.id) in + + ( #{item}) + + + + + + + + + + + + + + + + + + + + + + + + + + insert into xm_func( + + ) values ( + #{id},#{name},#{pid},#{pname},#{pidPaths},#{productId},#{lvl} + ) + + + + + delete from xm_func res + + + + + + + + delete from xm_func + where id = #{id} + + + + + update xm_func + + + + where id = #{id} + + + + + update xm_func + + + + where id = #{id} + + + + + + + + update xm_func + set + + where id = #{item.id} + + + + + + update xm_func + + + + where (id) in + + ( #{item}) + + + + + delete from xm_func + where + (id) in + + ( #{item.id} ) + + + + + + + id,name,pid,pname,pid_paths,product_id,lvl + + + + + and res.id = #{id} + and res.name = #{name} + and res.pid = #{pid} + and res.pname = #{pname} + and res.pid_paths = #{pidPaths} + and res.product_id = #{productId} + and res.lvl = #{lvl} + + + + name = #{name}, + pid = #{pid}, + pname = #{pname}, + pid_paths = #{pidPaths}, + product_id = #{productId}, + lvl = #{lvl} + + + name = #{name}, + pid = #{pid}, + pname = #{pname}, + pid_paths = #{pidPaths}, + product_id = #{productId}, + lvl = #{lvl}, + + + + name = #{item.name}, + pid = #{item.pid}, + pname = #{item.pname}, + pid_paths = #{item.pidPaths}, + product_id = #{item.productId}, + lvl = #{item.lvl} + + \ No newline at end of file