Commit bdbb316c authored by 陈晓晋's avatar 陈晓晋
Browse files

Merge branch 'xjchen' into 'develop'

加入mybatis-plus-join20230807

See merge request !26
parents e146e61a 18081f61
Loading
Loading
Loading
Loading
+92 −6
Original line number Diff line number Diff line
@@ -8,9 +8,11 @@ import com.censoft.censoftrongtong.service.ILedgerProjectService;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.domain.entity.SysDept;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.apache.ibatis.annotations.Param;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@@ -66,20 +68,32 @@ public class IndexController extends BaseController {

    @ApiOperation("项目按照不同纬度统计")
    @GetMapping("/getProjectNumByType")
    public R getProjectNumByType() {
    public R getProjectNumByType(@Param("statisticsType") String statisticsType) {


        Map<String, Object> map_rs = new HashMap<>();
        List<Map<String,String>> list_rs=new ArrayList<>();
        List<String> legendList=new ArrayList<>();
        QueryWrapper<LedgerProject> queryWrap=new QueryWrapper<>();
        if(statisticsType!=null&&statisticsType.equals("city")){
            queryWrap.select("count(*) 'num'","city").groupBy("city");
        }else{
            queryWrap.select("count(*) 'num'","dept_id").groupBy("dept_id");
        }

        List<LedgerProject> list=ledgerProjectService.list(queryWrap);
        if (list!=null&&list.size() > 0) {
            for (int i = 0; i < list.size(); i++) {
                Map<String,String> map_item=new HashMap<>();
                LedgerProject ledgerProject=list.get(i);

                if(statisticsType!=null&&statisticsType.equals("city")){
                    map_item.put("name",ledgerProject.getCity());
                }else{
                    map_item.put("name",ledgerProject.getDeptId()+"");
                }


                map_item.put("value",ledgerProject.getNum());
                list_rs.add(map_item);
                legendList.add(ledgerProject.getCity());
@@ -88,10 +102,81 @@ public class IndexController extends BaseController {
        map_rs.put("legendData",legendList);
        map_rs.put("seriesData",list_rs);

        //MPJLambdaWrapper<LedgerBuilding> queryWrapper=new MPJLambdaWrapper<>();
        //queryWrapper.select("count(*) num").select(LedgerProject::getName).leftJoin(LedgerProject.class,LedgerProject::getId,LedgerBuilding::getProjectId).groupBy(LedgerBuilding::getProjectId);
        //        //.eq(LedgerBuilding::getProjectId,1);
        //List<LedgerBuilding> list1=ledgerBuildingService.selectJoinList(LedgerBuilding.class,queryWrapper);









        return R.ok(map_rs);
    }

    /**
     * 使用join实现连表查询
     */

    @ApiOperation("项目按照不同纬度统计")
    @GetMapping("/getProjectNumByTypeByJoin")
    public R getProjectNumByTypeByJoin(@Param("statisticsType") String statisticsType) {


        Map<String, Object> map_rs = new HashMap<>();
        List<Map<String,String>> list_rs=new ArrayList<>();
        List<String> legendList=new ArrayList<>();
        List<LedgerBuilding> list1=new ArrayList<>();
        List<LedgerProject> list2=new ArrayList<>();
        MPJLambdaWrapper<LedgerBuilding> queryWrapper=new MPJLambdaWrapper<>();
        queryWrapper.selectAll(LedgerBuilding.class).leftJoin(LedgerProject.class,LedgerProject::getId,LedgerBuilding::getProjectId)
                .eq(LedgerBuilding::getProjectId,1);
        List<LedgerBuilding> list1=ledgerBuildingService.selectJoinList(LedgerBuilding.class,queryWrapper);
        MPJLambdaWrapper<LedgerProject> queryWrapper1=new MPJLambdaWrapper<>();
        if(statisticsType!=null&&statisticsType.equals("city")){
            queryWrapper=new MPJLambdaWrapper<>();
            queryWrapper.select("count(*) num").select(LedgerProject::getCity).leftJoin(LedgerProject.class,LedgerProject::getId,LedgerBuilding::getProjectId).groupBy(LedgerBuilding::getCity);
            //.eq(LedgerBuilding::getProjectId,1);
             list1=ledgerBuildingService.selectJoinList(LedgerBuilding.class,queryWrapper);
            if (list1!=null&&list1.size() > 0) {
                for (int i = 0; i < list1.size(); i++) {
                    Map<String,String> map_item=new HashMap<>();
                    LedgerBuilding ledgerBuilding=list1.get(i);
                    map_item.put("name",ledgerBuilding.getCity());
                    legendList.add(ledgerBuilding.getCity());

                    map_item.put("value",ledgerBuilding.getNum());
                    list_rs.add(map_item);

                }
            }

        }else{
            queryWrapper1=new MPJLambdaWrapper<>();
            queryWrapper1.select("count(*) num").select(SysDept::getDeptName).leftJoin(SysDept.class,SysDept::getDeptId,LedgerProject::getDeptId).groupBy(LedgerProject::getDeptId);
            //.eq(LedgerBuilding::getProjectId,1);
            list2=ledgerProjectService.selectJoinList(LedgerProject.class,queryWrapper1);
            if (list2!=null&&list2.size() > 0) {
                for (int i = 0; i < list2.size(); i++) {
                    Map<String,String> map_item=new HashMap<>();
                    LedgerProject ledgerProject=list2.get(i);

                        map_item.put("name",ledgerProject.getDeptName());
                        legendList.add(ledgerProject.getDeptName());

                    map_item.put("value",ledgerProject.getNum());
                    list_rs.add(map_item);

                }
            }

        }


        map_rs.put("legendData",legendList);
        map_rs.put("seriesData",list_rs);




@@ -107,4 +192,5 @@ public class IndexController extends BaseController {




}
+9 −6
Original line number Diff line number Diff line
package com.censoft.censoftrongtong.domain;

import java.math.BigDecimal;

import com.baomidou.mybatisplus.annotation.TableField;
import com.ruoyi.common.annotation.Excel;
import com.ruoyi.common.core.domain.BaseEntityClean;
import lombok.Data;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.ruoyi.common.annotation.Excel;
import com.ruoyi.common.core.domain.BaseEntity;

import java.math.BigDecimal;

/**
 * 基础数据-楼宇对象 ledger_building
@@ -86,6 +83,12 @@ public class LedgerBuilding extends BaseEntityClean
    @TableField(exist = false)
    private String deptName;

    /**
     * 数量
     */
    @TableField(exist = false)
    private String num;




+8 −0
Original line number Diff line number Diff line
@@ -184,6 +184,14 @@
                <artifactId>mybatis-plus-boot-starter</artifactId>
                <version>${mybatis-plus.version}</version>
            </dependency>
            <!--mybatis-plus-join-->
            <dependency>
                <groupId>com.github.yulichang</groupId>
                <artifactId>mybatis-plus-join-boot-starter</artifactId>
                <version>1.4.5</version>
            </dependency>


            <!-- pagehelper 分页插件 -->
            <dependency>
                <groupId>com.github.pagehelper</groupId>
+11 −17
Original line number Diff line number Diff line
package com.ruoyi.web.controller.system;

import java.util.List;
import java.util.stream.Collectors;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.lang3.ArrayUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
@@ -31,6 +15,16 @@ import com.ruoyi.system.service.ISysDeptService;
import com.ruoyi.system.service.ISysPostService;
import com.ruoyi.system.service.ISysRoleService;
import com.ruoyi.system.service.ISysUserService;
import org.apache.commons.lang3.ArrayUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 用户信息
@@ -242,7 +236,7 @@ public class SysUserController extends BaseController
    /**
     * 获取部门树列表
     */
    @PreAuthorize("@ss.hasPermi('system:user:list')")
    //@PreAuthorize("@ss.hasPermi('system:user:list')")
    @GetMapping("/deptTree")
    public AjaxResult deptTree(SysDept dept)
    {
+4 −1
Original line number Diff line number Diff line
@@ -16,7 +16,10 @@
    </description>

    <dependencies>

        <dependency>
            <groupId>com.github.yulichang</groupId>
            <artifactId>mybatis-plus-join-boot-starter</artifactId>
        </dependency>
        <!-- Spring框架基本的核心工具 -->
        <dependency>
            <groupId>org.springframework</groupId>
Loading