编程语言
首页 > 编程语言> > Java 关键词跟范围查询

Java 关键词跟范围查询

作者:互联网

1、页面功能实现,只看 实体类、基类、跟mapper.xml 就可以了

 

 

 

二、实体类 (该实体用继承关系  QwBaseEntity类)

package com.ruoyi.enterprise.domain;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.ruoyi.common.annotation.Excel;
import lombok.Data;
import java.util.Date;

/**
 * 信息对象 qw_enterprise
 *
 * @author ruoyi
 * @date 2022-05-23
 */
@Data
public class QwEnterprise extends QwBaseEntity
{
    private static final long serialVersionUID = 1L;

    /** 企业信息ID */
    private Integer id;

    /** 地区ID */
    private String regionId;

    /** 企业名称 */
    private String enterpriseName;

    /** 登记状态 (0在业/存续 1清算 2迁入 3迁出 4停业 5撤销 6吊销 7注销 8歇业 9责令关闭) */
    private String status;

    /** 法定代表人 */
    private String legalName;

    /** 注册资金 */
    private Double money;

    /** 注册资本 */
    private String registeredCapital;

    /** 成立时间 */
    @JsonFormat(pattern = "yyyy-MM-dd")
    private Date establishTime;

    /** 参保人数 */
    private Integer insuredPeople;

    /** 经营范围 */
    private String articleContent;
}

 

基类:组装成前端所需要的格式(部分使用类部类)

package com.ruoyi.enterprise.domain;
import lombok.Data;
import java.io.Serializable;
import java.time.LocalDate;
import java.util.List;

/**
 * 基础信息Entity基类
 *
 * @author ruoyi
 */
@Data
public class QwBaseEntity implements Serializable
{
    private static final long serialVersionUID = 1L;

    /** 关键词 */
    private String keyword;

    /** 登记状态 */
    private List<Long> statusIds;

    /** 地区ID数组 */
    private List<Long> regionIds;

    /** (参保人数)最小值\最大值 */
    private List<InsuredPeople> personsList;

    /** (成立时间)开始日期 至 结束日期 */
    private List<EstablishTime> timeList;

    /** (注册资本)最小值\最大值 */
    private List<RegisteredCapital> moneyList;

    @Data
    public static class InsuredPeople{
        private Integer min;
        private Integer max;
    }
    @Data
    public static class EstablishTime{
        private LocalDate beginTime;
        private LocalDate endTime;
    }
    @Data
    public static class RegisteredCapital{
        private Integer min;
        private Integer max;
    }
}

 

三、Mapper接口

package com.ruoyi.enterprise.mapper;
import com.ruoyi.enterprise.domain.QwEnterprise;
import org.apache.ibatis.annotations.Param;
import java.util.List;

/**
 * Mapper接口
 *
 * @author ruoyi
 * @date 2022-05-23
 */
public interface QwEnterpriseMapper
{
    /**
     * 查询企业信息列表
     * @param qwEnterprise 企业信息
     * @return 企业信息集合
     */
    public List<QwEnterprise> selectQwEnterpriseList(@Param("param")QwEnterprise qwEnterprise, @Param("regionIds") Long regionIds);

}

 

四:Mapper.xml   SQL语句(关键),通过 foreach 实现范围检索

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<!-- 将下列SQL语句绑定 dao层对应接口 -->
<mapper namespace="com.ruoyi.enterprise.mapper.QwEnterpriseMapper">

    <resultMap type="QwEnterprise" id="QwEnterpriseResult">
        <result property="id"    column="id"    />
        <result property="region_id"    column="regionId"    />
        <result property="enterpriseName"    column="enterprise_name"    />
        <result property="status"    column="status"    />
        <result property="legalName"    column="legal_name"    />
        <result property="money"    column="money"    />
        <result property="registeredCapital"    column="registered_capital"    />
        <result property="establishTime"    column="establish_time"    />
        <result property="approvalTime"    column="approval_time"    />
        <result property="province"    column="province"    />
        <result property="city"    column="city"    />
        <result property="area"    column="area"    />
        <result property="phonenumber"    column="phonenumber"    />
        <result property="morePhonenumber"    column="more_phonenumber"    />
        <result property="email"    column="email"    />
        <result property="moreEmail"    column="more_email"    />
        <result property="creditCode"    column="credit_code"    />
        <result property="taxpayerNumber"    column="taxpayer_number"    />
        <result property="registrationNumber"    column="registration_number"    />
        <result property="organizationCode"    column="organization_code"    />
        <result property="insuredPeople"    column="insured_people"    />
        <result property="enterpriseType"    column="enterprise_type"    />
        <result property="industry"    column="industry"    />
        <result property="usedBeforeName"    column="used_before_name"    />
        <result property="englishName"    column="english_name"    />
        <result property="websiteUrl"    column="website_url"    />
        <result property="businessAddress"    column="business_address"    />
        <result property="reportAddress"    column="report_address"    />
        <result property="articleContent"    column="article_content"    />
    </resultMap>

    <sql id="selectQwEnterpriseVo">
        select id, region_id, enterprise_name, status, legal_name, money, registered_capital, establish_time, approval_time,
               province, city, area, phonenumber, more_phonenumber,email, more_email, credit_code, taxpayer_number,
               registration_number, organization_code, insured_people, enterprise_type,industry, used_before_name,
               english_name, website_url, business_address, report_address, article_content
        from qw_enterprise
    </sql>

    <select id="selectQwEnterpriseList" parameterType="QwEnterprise" resultMap="QwEnterpriseResult">
        <include refid="selectQwEnterpriseVo"/>
        <where>
            <if test="param.keyword != null and param.keyword != ''">  <!-- 关键词搜索 -->
                AND (enterprise_name like CONCAT('%',#{param.keyword},'%')
                    or legal_name = #{param.keyword}
                    or phonenumber = #{param.keyword}
                    or credit_code = #{param.keyword}
                    or taxpayer_number = #{param.keyword}
                    or registration_number = #{param.keyword}
                    or business_address like CONCAT('%',#{param.keyword},'%'))
            </if>
            <if test="param.statusIds != null">
                AND status in
                <foreach collection="param.statusIds" index="index" item="id" open="(" separator="," close=")"> <!-- 登记状态 -->
                    #{id}
                </foreach>
            </if>
            <if test="regionIds != null">  <!-- 地区ID集合 -->
                AND (region_id like CONCAT('%',#{regionIds},'%'))
            </if>
            <if test="param.personsList != null ">  <!-- 参保人数【范围】 -->
                AND
                <foreach collection="param.personsList" item="num" open="(" separator="or" close=")">
                    (insured_people &gt;= #{num.min} and insured_people &lt;= #{num.max})
                </foreach>
            </if>
            <if test="param.timeList != null ">  <!-- 成立时间【范围】 -->
                AND
                <foreach collection="param.timeList" item="time" open="(" separator="or" close=")">
                    (establish_time &gt;= #{time.beginTime} and establish_time &lt;= #{time.endTime})
                </foreach>
            </if>
            <if test="param.moneyList != null ">  <!-- 注册资本【范围】 -->
                AND
                <foreach collection="param.moneyList" item="num" open="(" separator="or" close=")">
                    (money &gt;= #{num.min} and money &lt;= #{num.max})
                </foreach>
            </if>
        </where>
    </select>
</mapper>                    

 

五:Service接口

package com.ruoyi.enterprise.service;
import com.ruoyi.enterprise.domain.QwEnterprise;
import java.util.List;

/**
 * Service接口
 *
 * @author ruoyi
 * @date 2022-05-23
 */
public interface IQwEnterpriseService {

    /**
     * 查询企业信息列表
     * @param qwEnterprise 企业信息
     * @return 企业信息集合
     */
    public List<QwEnterprise> selectQwEnterpriseList(QwEnterprise qwEnterprise);

}

 

六:Service业务层处理

package com.ruoyi.enterprise.service.impl;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.enterprise.domain.QwEnterprise;
import com.ruoyi.enterprise.mapper.QwEnterpriseMapper;
import com.ruoyi.enterprise.service.ITableAreaService;
import com.ruoyi.enterprise.service.IQwEnterpriseService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;

/**
 * Service业务层处理
 *
 * @author ruoyi
 * @date 2022-05-23
 */
@Service
public class QwEnterpriseServiceImpl implements IQwEnterpriseService {
    private static final Logger log = LoggerFactory.getLogger(QwEnterpriseServiceImpl.class);

    @Autowired
    private QwEnterpriseMapper qwEnterpriseMapper;

    @Autowired
    private ITableAreaService tableAreaService;

    /**
     * 查询企业信息列表
     *
     * @param qwEnterprise 企业信息
     * @return 企业信息
     */
    @Override
    public List<QwEnterprise> selectQwEnterpriseList(QwEnterprise qwEnterprise) {
        List<QwEnterprise> qwEnterprises = new ArrayList<>();
      //判断选择的地区ID数组不为空,就根据前端返回的参数查询 if (qwEnterprise.getRegionIds() != null) { qwEnterprise.getRegionIds().forEach(regionId -> { qwEnterprises.addAll(qwEnterpriseMapper.selectQwEnterpriseList(qwEnterprise, regionId)); }); } else { qwEnterprises.addAll(qwEnterpriseMapper.selectQwEnterpriseList(qwEnterprise, null)); } return qwEnterprises; } }

 

七:控制层处理 (返回的格式为 JSON格式,通过注解:@RequestBody)

package com.ruoyi.enterprise.controller;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.enterprise.domain.QwEnterprise;
import com.ruoyi.enterprise.service.IQwEnterpriseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 企业信息Controller
 *
 * @author ruoyi
 * @date 2022-05-23
 */
@Api(tags = "信息==》接口")
@RestController
@RequestMapping("/enterprise")
@Slf4j
public class QwEnterpriseController extends BaseController
{
    @Autowired
    private IQwEnterpriseService qwEnterpriseService;

    /**
     * 查询企业信息列表
     */
    @ApiOperation("信息查询接口")
    @PostMapping("/list")
    public TableDataInfo list(@RequestBody QwEnterprise qwEnterprise)
    {
        startPage();
        List<QwEnterprise> list = qwEnterpriseService.selectQwEnterpriseList(qwEnterprise);
        return getDataTable(list);
    }
}

 

注:TableDataInfo  表格分页数据对象  ;getDataTable   web层通用数据处理;参考【若依】封装类

若依官网地址:https://gitee.com/y_project/RuoYi-Vue

 

标签:Java,关键词,List,ruoyi,private,查询,enterprise,import,com
来源: https://www.cnblogs.com/springclout/p/16338492.html