mitao
2025-01-20 73e54a23d1e5dec148741af321282a93a82bb02d
管理端:企业列表相关接口
2个文件已添加
11个文件已修改
369 ■■■■■ 已修改文件
pom.xml 7 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-api/ruoyi-api-company/pom.xml 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-api/ruoyi-api-company/src/main/java/com/ruoyi/company/api/domain/Company.java 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-api/ruoyi-api-company/src/main/java/com/ruoyi/company/api/domain/User.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-api/ruoyi-api-company/src/main/java/com/ruoyi/company/api/domain/dto/MgtCompanyDTO.java 114 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-api/ruoyi-api-company/src/main/java/com/ruoyi/company/api/domain/excel/MgtCompanyExcel.java 39 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-api/ruoyi-api-company/src/main/java/com/ruoyi/company/api/domain/vo/MgtCompanyVO.java 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/page/BeanUtils.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-common/ruoyi-common-security/src/main/java/com/ruoyi/common/security/config/ApplicationConfig.java 11 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-modules/ruoyi-company/pom.xml 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-modules/ruoyi-company/src/main/java/com/ruoyi/company/controller/management/MgtCompanyController.java 33 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-modules/ruoyi-company/src/main/java/com/ruoyi/company/service/CompanyService.java 29 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-modules/ruoyi-company/src/main/java/com/ruoyi/company/service/impl/CompanyServiceImpl.java 117 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pom.xml
@@ -41,6 +41,7 @@
        <tomcat.version>9.0.96</tomcat.version>
        <logback.version>1.2.13</logback.version>
        <spring-framework.version>5.3.39</spring-framework.version>
        <fastexcel.version>1.0.0</fastexcel.version>
    </properties>
    <!-- 依赖声明 -->
@@ -305,7 +306,11 @@
                <artifactId>aliyun-java-sdk-dysmsapi</artifactId>
                <version>2.1.0</version>
            </dependency>
            <dependency>
                <groupId>cn.idev.excel</groupId>
                <artifactId>fastexcel</artifactId>
                <version>${fastexcel.version}</version>
            </dependency>
        </dependencies>
    </dependencyManagement>
ruoyi-api/ruoyi-api-company/pom.xml
@@ -31,6 +31,10 @@
            <groupId>com.ruoyi</groupId>
            <artifactId>ruoyi-common-swagger</artifactId>
        </dependency>
        <dependency>
            <groupId>cn.idev.excel</groupId>
            <artifactId>fastexcel</artifactId>
        </dependency>
    </dependencies>
</project>
ruoyi-api/ruoyi-api-company/src/main/java/com/ruoyi/company/api/domain/Company.java
@@ -32,6 +32,9 @@
    /** 区域代码 */
    private String districtCode;
    /**所在区域(省市区)*/
    private String area;
    /** 经营地址 */
    private String businessAddress;
ruoyi-api/ruoyi-api-company/src/main/java/com/ruoyi/company/api/domain/User.java
@@ -31,6 +31,10 @@
    /** 更新时间 */
    private LocalDateTime updateTime;
    /** 创建人 */
    private Long createBy;
    /** 更新人 */
    private Long updateBy;
    /** 是否删除 */
    @TableLogic
ruoyi-api/ruoyi-api-company/src/main/java/com/ruoyi/company/api/domain/dto/MgtCompanyDTO.java
New file
@@ -0,0 +1,114 @@
package com.ruoyi.company.api.domain.dto;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import javax.validation.constraints.NotBlank;
/**
 * @author mitao
 * @date 2025/1/20
 */
@Data
@Schema(name = "企业数据传输对象")
public class MgtCompanyDTO {
    /** 主键 */
    @Schema(description = "主键", example = "1")
    private Long id;
    /** 公司名称 */
    @Schema(description = "公司名称", example = "某某科技有限公司")
    @NotBlank(message = "公司名称不能为空")
    private String companyName;
    /** 统一社会信用代码 */
    @Schema(description = "统一社会信用代码", example = "913100000000123")
    @NotBlank(message = "统一社会信用代码不能为空")
    private String socialCode;
    /** 省份代码 */
    @Schema(description = "省份代码", example = "01")
    @NotBlank(message = "省份代码不能为空")
    private String provinceCode;
    /** 城市代码 */
    @Schema(description = "城市代码", example = "020")
    @NotBlank(message = "城市代码不能为空")
    private String cityCode;
    /** 区域代码 */
    @Schema(description = "区域代码", example = "003")
    private String districtCode;
    @Schema(description = "所在区域(省市区)")
    @NotBlank(message = "所在区域(省市区)不能为空")
    private String area;
    /** 经营地址 */
    @Schema(description = "经营地址", example = "北京市海淀区")
    @NotBlank(message = "经营地址不能为空")
    private String businessAddress;
    /** 身份证正面照片 */
    @Schema(description = "身份证正面照片 URL", example = "https://example.com/idcard-front.jpg")
    @NotBlank(message = "身份证正面照片不能为空")
    private String idCardFrontUrl;
    /** 身份证反面照片 */
    @Schema(description = "身份证反面照片 URL", example = "https://example.com/idcard-back.jpg")
    @NotBlank(message = "身份证反面照片不能为空")
    private String idCardBackUrl;
    /** 法人姓名 */
    @Schema(description = "法人姓名", example = "张三")
    @NotBlank(message = "法人姓名不能为空")
    private String legalPersonName;
    /** 身份证号码 */
    @Schema(description = "身份证号码", example = "110101199001012345")
    @NotBlank(message = "身份证号码不能为空")
    private String idCardNumber;
    /** 营业执照照片 */
    @Schema(description = "营业执照照片 URL", example = "https://example.com/business-license.jpg")
    @NotBlank(message = "营业执照照片不能为空")
    private String businessLicenseUrl;
    /** 资质类目:1-再生资源回收备案资质 2-家电拆解资质 3-报废机动车回收拆解资质 4-危险废物经营许可证 0-其他证书 */
    @Schema(description = "资质类目", example = "1", allowableValues = {"0", "1", "2", "3", "4"})
    private Integer category;
    /** 拆解企业资质证书图片地址 */
    @Schema(description = "拆解企业资质证书图片地址 URL", example = "https://example.com/certificate.jpg")
    private String certificateUrl;
    /** 联系人姓名 */
    @Schema(description = "联系人姓名", example = "李四")
    @NotBlank(message = "联系人姓名不能为空")
    private String contactName;
    /** 联系人手机号 */
    @Schema(description = "联系人手机号", example = "13800138000")
    @NotBlank(message = "联系人手机号不能为空")
    private String contactPhone;
    /** 联系人邮箱 */
    @Schema(description = "联系人邮箱", example = "example@example.com")
    @NotBlank(message = "联系人邮箱不能为空")
    private String email;
    /** 账号 */
    @Schema(description = "登录账号")
    @NotBlank(message = "账号不能为空")
    private String accountName;
    /** 手机号 */
    @Schema(description = "绑定手机号")
    @NotBlank(message = "手机号不能为空")
    private String phone;
    @Schema(description = "登录密码")
    @NotBlank(message = "登录密码不能为空")
    private String password;
}
ruoyi-api/ruoyi-api-company/src/main/java/com/ruoyi/company/api/domain/excel/MgtCompanyExcel.java
New file
@@ -0,0 +1,39 @@
package com.ruoyi.company.api.domain.excel;
import cn.idev.excel.annotation.ExcelProperty;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import java.time.LocalDateTime;
/**
 * @author mitao
 * @date 2025/1/20
 */
@Data
public class MgtCompanyExcel {
    /** 公司名称 */
    @ExcelProperty(value = "公司名称")
    private String companyName;
    @ExcelProperty(value = "法人")
    private String legalPersonName;
    @ExcelProperty(value = "统一社会信用代码")
    private String socialCode;
    @ExcelProperty(value = "经营地址")
    private String businessAddress;
    @ExcelProperty(value = "联系人")
    private String contactName;
    @ExcelProperty(value = "联系人方式")
    private String contactPhone;
    @ExcelProperty(value = "注册时间")
    @JsonFormat(pattern = "yyyy-MM-dd")
    private LocalDateTime createTime;
}
ruoyi-api/ruoyi-api-company/src/main/java/com/ruoyi/company/api/domain/vo/MgtCompanyVO.java
@@ -1,6 +1,5 @@
package com.ruoyi.company.api.domain.vo;
import com.baomidou.mybatisplus.annotation.TableId;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
@@ -15,7 +14,6 @@
@Schema(name = "管理端企业信息",description = "管理端企业信息")
public class MgtCompanyVO {
    /** 主键 */
    @TableId
    @Schema(description = "主键", example = "1")
    private Long id;
ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/page/BeanUtils.java
@@ -47,7 +47,7 @@
        if (list == null || list.size() == 0) {
            return CollUtils.emptyList();
        }
        return copyToList(list, clazz);
        return copyList(list, clazz);
    }
    public static <R, T> List<T> copyList(List<R> list, Class<T> clazz, Convert<R, T> convert) {
ruoyi-common/ruoyi-common-security/src/main/java/com/ruoyi/common/security/config/ApplicationConfig.java
@@ -1,8 +1,10 @@
package com.ruoyi.common.security.config;
import java.util.TimeZone;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer;
import org.springframework.context.annotation.Bean;
import java.util.TimeZone;
/**
 * 系统配置
@@ -19,4 +21,11 @@
    {
        return jacksonObjectMapperBuilder -> jacksonObjectMapperBuilder.timeZone(TimeZone.getDefault());
    }
    @Bean
    public Jackson2ObjectMapperBuilderCustomizer jackson2ObjectMapperBuilderCustomizer() {
        return builder -> {
            // Long 会自动转换成 String
            builder.serializerByType(Long.class, ToStringSerializer.instance);
        };
    }
}
ruoyi-modules/ruoyi-company/pom.xml
@@ -88,6 +88,10 @@
      <artifactId>ruoyi-api-company</artifactId>
    </dependency>
    <dependency>
      <groupId>cn.idev.excel</groupId>
      <artifactId>fastexcel</artifactId>
    </dependency>
  </dependencies>
  <build>
ruoyi-modules/ruoyi-company/src/main/java/com/ruoyi/company/controller/management/MgtCompanyController.java
@@ -2,6 +2,7 @@
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.PageDTO;
import com.ruoyi.company.api.domain.dto.MgtCompanyDTO;
import com.ruoyi.company.api.domain.query.MgtCompanyQuery;
import com.ruoyi.company.api.domain.vo.MgtCompanyVO;
import com.ruoyi.company.service.CompanyService;
@@ -10,11 +11,16 @@
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
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.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.validation.Valid;
import java.io.IOException;
/**
 * @author mitao
@@ -38,5 +44,32 @@
    public R<MgtCompanyVO> queryCompanyDetail(@Parameter(name = "id",description = "企业id",required = true) @PathVariable Long id) {
        return R.ok(companyService.queryCompanyDetail(id));
    }
    @Operation(summary = "新增企业")
    @PostMapping("/save")
    public R<?> saveCompany(@Valid @RequestBody MgtCompanyDTO dto) {
        companyService.saveCompany(dto);
        return R.ok();
    }
    @Operation(summary = "编辑企业")
    @PostMapping("/edit")
    public R<?> editCompany(@Valid @RequestBody MgtCompanyDTO dto) {
        companyService.editCompany(dto);
        return R.ok();
    }
    @Operation(summary = "删除企业")
    @DeleteMapping("/{id}")
    public R<?> deleteCompany(@Parameter(name = "id",description = "企业id",required = true) @PathVariable Long id) {
        companyService.deleteCompany(id);
        return R.ok();
    }
    @Operation(summary = "导出")
    @PostMapping("/export")
    public void export(@RequestBody MgtCompanyQuery query){
        try {
            companyService.export(query);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
ruoyi-modules/ruoyi-company/src/main/java/com/ruoyi/company/service/CompanyService.java
@@ -3,8 +3,12 @@
import com.baomidou.mybatisplus.extension.service.IService;
import com.ruoyi.common.core.page.PageDTO;
import com.ruoyi.company.api.domain.Company;
import com.ruoyi.company.api.domain.dto.MgtCompanyDTO;
import com.ruoyi.company.api.domain.query.MgtCompanyQuery;
import com.ruoyi.company.api.domain.vo.MgtCompanyVO;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
public interface CompanyService extends IService<Company> {
    /**
@@ -20,4 +24,29 @@
     * @return
     */
    MgtCompanyVO queryCompanyDetail(Long id);
    /**
     * 新增企业
     * @param dto
     * @return
     */
    void saveCompany(MgtCompanyDTO dto);
    /**
     * 编辑企业
     * @param dto
     */
    void editCompany(MgtCompanyDTO dto);
    /**
     * 删除企业
     * @param id
     */
    void deleteCompany(Long id);
    /**
     * 导出
     * @param query
     */
    void export(MgtCompanyQuery query) throws IOException;
}
ruoyi-modules/ruoyi-company/src/main/java/com/ruoyi/company/service/impl/CompanyServiceImpl.java
@@ -1,12 +1,17 @@
package com.ruoyi.company.service.impl;
import cn.idev.excel.FastExcel;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.core.exception.ServiceException;
import com.ruoyi.common.core.page.BeanUtils;
import com.ruoyi.common.core.page.PageDTO;
import com.ruoyi.common.core.utils.StringUtils;
import com.ruoyi.common.security.utils.SecurityUtils;
import com.ruoyi.company.api.domain.Company;
import com.ruoyi.company.api.domain.User;
import com.ruoyi.company.api.domain.dto.MgtCompanyDTO;
import com.ruoyi.company.api.domain.excel.MgtCompanyExcel;
import com.ruoyi.company.api.domain.query.MgtCompanyQuery;
import com.ruoyi.company.api.domain.vo.MgtCompanyVO;
import com.ruoyi.company.mapper.CompanyMapper;
@@ -14,13 +19,19 @@
import com.ruoyi.company.service.UserService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URLEncoder;
import java.util.List;
import java.util.Objects;
@Service
@RequiredArgsConstructor
public class CompanyServiceImpl extends ServiceImpl<CompanyMapper, Company> implements CompanyService {
    private final UserService userService;
    private final HttpServletResponse response;
    /**
     * 获取企业列表
     * @param query
@@ -59,4 +70,110 @@
        }
        return mgtCompanyVO;
    }
    /**
     * 新增企业
     * @param dto
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
    @Override
    public void saveCompany(MgtCompanyDTO dto) {
        Long accountCount = userService.lambdaQuery().eq(User::getAccountName, dto.getAccountName()).count();
        if (accountCount > 0) {
            throw new ServiceException("账户名重复");
        }
        //添加用户信息
        User user = BeanUtils.copyBean(dto, User.class);
        user.setPassword(SecurityUtils.encryptPassword(dto.getPassword()));
        userService.save(user);
        // TODO 校验身份证信息
        Company company = BeanUtils.copyBean(dto, Company.class);
        company.setUserId(user.getUserId());
        //根据公司名称查询数据库
        Long count = this.lambdaQuery().eq(Company::getCompanyName, company.getCompanyName()).count();
        if (count > 0) {
            throw new ServiceException("该公司账号已存在");
        }
        this.save(company);
    }
    /**
     * 编辑企业
     * @param dto
     */
    @Override
    public void editCompany(MgtCompanyDTO dto) {
        if (Objects.isNull(dto.getId())){
            throw new ServiceException("企业id不能为空");
        }
        //查询企业
        Company company = this.getById(dto.getId());
        if (Objects.isNull(company)) {
            throw new ServiceException("该企业不存在");
        }
        //查询企业账号
        User user = userService.getById(company.getUserId());
        if (Objects.isNull(user)) {
            throw new ServiceException("该企业账号不存在");
        }
        Long accountCount = userService.lambdaQuery().ne(User::getUserId, user.getUserId()).eq(User::getAccountName, dto.getAccountName()).count();
        if (accountCount > 0) {
            throw new ServiceException("账户名重复");
        }
        //用户信息
        User userUpd = BeanUtils.copyBean(dto, User.class);
        userUpd.setPassword(SecurityUtils.encryptPassword(dto.getPassword()));
        userUpd.setUserId(user.getUserId());
        userUpd.setUpdateBy(SecurityUtils.getUserId());
        userService.updateById(userUpd);
        //根据公司名称查询数据库
        Long count = this.lambdaQuery().ne(Company::getId,dto.getId()).eq(Company::getCompanyName, company.getCompanyName()).count();
        if (count > 0) {
            throw new ServiceException("该公司账号已存在");
        }
        Company companyUpd = BeanUtils.copyBean(dto, Company.class);
        companyUpd.setId(company.getId());
        this.updateById(companyUpd);
    }
    /**
     * 删除企业
     * @param id
     */
    @Override
    public void deleteCompany(Long id) {
        //查询企业
        Company company = this.getById(id);
        if (Objects.isNull(company)) {
            throw new ServiceException("删除失败,该企业不存在");
        }
        //删除企业账号
         userService.removeById(company.getUserId());
        //删除企业信息
        this.removeById(id);
    }
    @Override
    public void export(MgtCompanyQuery query) throws IOException {
        List<Company> list = this.lambdaQuery()
                .like(StringUtils.isNotBlank(query.getCompanyInfo()), Company::getCompanyName, query.getCompanyInfo())
                .like(StringUtils.isNotBlank(query.getCompanyInfo()), Company::getSocialCode, query.getCompanyInfo())
                .like(StringUtils.isNotBlank(query.getLegalPersonInfo()), Company::getLegalPersonName, query.getLegalPersonInfo())
                .like(StringUtils.isNotBlank(query.getLegalPersonInfo()), Company::getIdCardNumber, query.getLegalPersonInfo())
                .like(StringUtils.isNotBlank(query.getContactInfo()), Company::getContactName, query.getContactInfo())
                .like(StringUtils.isNotBlank(query.getContactInfo()), Company::getContactPhone, query.getContactInfo()).list();
        response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
        response.setCharacterEncoding
                ("utf-8");
        String fileName = URLEncoder.encode("企业信息导出数据", "UTF-8").replaceAll("\\+", "%20");
        response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx");
        FastExcel.write(response.getOutputStream(), MgtCompanyExcel.class)
                .sheet("企业信息导出数据")
                .doWrite(BeanUtils.copyList(list, MgtCompanyExcel.class));
    }
}