实训项目-人力资源管理系统-1Company子模块

news2024/12/26 9:23:00

目录

前言:

用例图设计:

 系统设计

开发方式:

 技术架构

系统结构:

API文档:

工程搭建:

搭建父项目

pom:

 创建公共子模块:

返回实体:

 分布式id生成器:

 创建实体类模块:

pom:

 创建company子模块:

pom:

CompanyApplication:

 Company类:

department类:

deplistResult类(封装部门列表) 

Controller:

CompanyController:

DepartmentController:

Dao: 

CompanyDao: 

Service:

CompanyService: 

DepartmentService:

Application:

 

此时子模块目录如下:

 


前言:

等实训周一到,哥们就把名字改过来,不然要被真实,此外,本项目除了SSM外以外,会用到其他刚学的插件,这下不得狠狠地在别人面前装一把,由于刚新建文件夹,请容我分成好几个博客来放出

用例图设计:

简单画一下,后面应该会扩展或者大改

 

 系统设计

开发方式:

 采用前后端分离(前端用啥还没想好,想好了我就把这里改了)

 技术架构

 前端:还没想好用啥

后端:spring全家桶(SpringBoot+SpringCloud+SpringMVC+SpringData)

ps:要是来不及我就改了

系统结构:

 后面画

API文档:

 没有

工程搭建:

搭建父项目

 

pom:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>org.flowerfog</groupId>
  <artifactId>staff_parent</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>staff_parent</name>
  <url>http://maven.apache.org</url>


  <description>staff-flowerfog</description>

  <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.0.5.RELEASE</version>
    <relativePath/>
  </parent>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <java.version>17</java.version>
    <fastjson.version>1.2.47</fastjson.version>
  </properties>

  <dependencies>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-logging</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-test</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>com.alibaba</groupId>
      <artifactId>fastjson</artifactId>
      <version>${fastjson.version}</version>
    </dependency>
    <dependency>
      <groupId>org.projectlombok</groupId>
      <artifactId>lombok</artifactId>
      <version>1.16.16</version>
    </dependency>
  </dependencies>

  <repositories>
    <repository>
      <id>spring-snapshots</id>
      <name>Spring Snapshots</name>
      <url>https://repo.spring.io/snapshot</url>
      <snapshots>
        <enabled>true</enabled>
      </snapshots>
    </repository>
    <repository>
      <id>spring-milestones</id>
      <name>Spring Milestones</name>
      <url>https://repo.spring.io/milestone</url>
      <snapshots>
        <enabled>false</enabled>
      </snapshots>
    </repository>
  </repositories>

  <pluginRepositories>
    <pluginRepository>
      <id>spring-snapshots</id>
      <name>Spring Snapshots</name>
      <url>https://repo.spring.io/snapshot</url>
      <snapshots>
        <enabled>true</enabled>
      </snapshots>
    </pluginRepository>
    <pluginRepository>
      <id>spring-milestones</id>
      <name>Spring Milestones</name>
      <url>https://repo.spring.io/milestone</url>
      <snapshots>
        <enabled>false</enabled>
      </snapshots>
    </pluginRepository>
  </pluginRepositories>
  <build>
    <plugins>
      <!--编译插件-->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.1</version>
        <configuration>
          <source>${java.version}</source>
          <target>${java.version}</target>
        </configuration>
      </plugin>

      <!--单元测试插件-->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.12.4</version>
        <configuration>
          <skipTests>true</skipTests>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>



 创建公共子模块:

返回实体:

 resultCode:

package org.flowerfog.entity;

/**
 * 全局返回码
 */
public enum ResultCode {

    SUCCESS(true,10000,"操作成功!"),
    //---系统错误返回码-----
    FAIL(false,10001,"操作失败"),
    UNAUTHENTICATED(false,10002,"您还未登录"),
    UNAUTHORISE(false,10003,"权限不足"),
    SERVER_ERROR(false,99999,"抱歉,系统繁忙,请稍后重试!");

    //其他操作码暂定

    //操作是否成功
    boolean success;
    //操作代码
    int code;
    //提示信息
    String message;

    ResultCode(boolean success,int code, String message){
        this.success = success;
        this.code = code;
        this.message = message;
    }

    public boolean success() {
        return success;
    }

    public int code() {
        return code;
    }

    public String message() {
        return message;
    }

}

 其他code暂定

result:

package org.flowerfog.entity;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 响应对象
 *
 */

@Data
@NoArgsConstructor
public class Result {

    private boolean success;//是否成功
    private Integer code;//返回码
    private String message;//返回信息
    private Object data;//返回数据

    public Result(ResultCode code) {
        this.success = code.success;
        this.code = code.code;
        this.message = code.message;
    }

    public Result(ResultCode code,Object data) {
        this.success = code.success;
        this.code = code.code;
        this.message = code.message;
        this.data = data;
    }

    public Result(Integer code,String message,boolean success) {
        this.code = code;
        this.message = message;
        this.success = success;
    }

    public static Result SUCCESS(){
        return new Result(ResultCode.SUCCESS);
    }

    public static Result ERROR(){
        return new Result(ResultCode.SERVER_ERROR);
    }

    public static Result FAIL(){
        return new Result(ResultCode.FAIL);
    }
}

 分布式id生成器:

雪花算法:

package org.flowerfog.utils;

import java.lang.management.ManagementFactory;
import java.net.InetAddress;
import java.net.NetworkInterface;

//雪花算法代码实现
public class IdWorker {
    // 时间起始标记点,作为基准,一般取系统的最近时间(一旦确定不能变动)
    private final static long twepoch = 1288834974657L;
    // 机器标识位数
    private final static long workerIdBits = 5L;
    // 数据中心标识位数
    private final static long datacenterIdBits = 5L;
    // 机器ID最大值
    private final static long maxWorkerId = -1L ^ (-1L << workerIdBits);
    // 数据中心ID最大值
    private final static long maxDatacenterId = -1L ^ (-1L << datacenterIdBits);
    // 毫秒内自增位
    private final static long sequenceBits = 12L;
    // 机器ID偏左移12位
    private final static long workerIdShift = sequenceBits;
    // 数据中心ID左移17位
    private final static long datacenterIdShift = sequenceBits + workerIdBits;
    // 时间毫秒左移22位
    private final static long timestampLeftShift = sequenceBits + workerIdBits + datacenterIdBits;

    private final static long sequenceMask = -1L ^ (-1L << sequenceBits);
    /* 上次生产id时间戳 */
    private static long lastTimestamp = -1L;
    // 0,并发控制
    private long sequence = 0L;

    private final long workerId;
    // 数据标识id部分
    private final long datacenterId;

    public IdWorker(){
        this.datacenterId = getDatacenterId(maxDatacenterId);
        this.workerId = getMaxWorkerId(datacenterId, maxWorkerId);
    }
    /**
     * @param workerId
     *            工作机器ID
     * @param datacenterId
     *            序列号
     */
    public IdWorker(long workerId, long datacenterId) {
        if (workerId > maxWorkerId || workerId < 0) {
            throw new IllegalArgumentException(String.format("worker Id can't be greater than %d or less than 0", maxWorkerId));
        }
        if (datacenterId > maxDatacenterId || datacenterId < 0) {
            throw new IllegalArgumentException(String.format("datacenter Id can't be greater than %d or less than 0", maxDatacenterId));
        }
        this.workerId = workerId;
        this.datacenterId = datacenterId;
    }
    /**
     * 获取下一个ID
     *
     * @return
     */
    public synchronized long nextId() {
        long timestamp = timeGen();
        if (timestamp < lastTimestamp) {
            throw new RuntimeException(String.format("Clock moved backwards.  Refusing to generate id for %d milliseconds", lastTimestamp - timestamp));
        }

        if (lastTimestamp == timestamp) {
            // 当前毫秒内,则+1
            sequence = (sequence + 1) & sequenceMask;
            if (sequence == 0) {
                // 当前毫秒内计数满了,则等待下一秒
                timestamp = tilNextMillis(lastTimestamp);
            }
        } else {
            sequence = 0L;
        }
        lastTimestamp = timestamp;
        // ID偏移组合生成最终的ID,并返回ID
        long nextId = ((timestamp - twepoch) << timestampLeftShift)
                | (datacenterId << datacenterIdShift)
                | (workerId << workerIdShift) | sequence;

        return nextId;
    }

    private long tilNextMillis(final long lastTimestamp) {
        long timestamp = this.timeGen();
        while (timestamp <= lastTimestamp) {
            timestamp = this.timeGen();
        }
        return timestamp;
    }

    private long timeGen() {
        return System.currentTimeMillis();
    }

    /**
     * <p>
     * 获取 maxWorkerId
     * </p>
     */
    protected static long getMaxWorkerId(long datacenterId, long maxWorkerId) {
        StringBuffer mpid = new StringBuffer();
        mpid.append(datacenterId);
        String name = ManagementFactory.getRuntimeMXBean().getName();
        if (!name.isEmpty()) {
            /*
             * GET jvmPid
             */
            mpid.append(name.split("@")[0]);
        }
        /*
         * MAC + PID 的 hashcode 获取16个低位
         */
        return (mpid.toString().hashCode() & 0xffff) % (maxWorkerId + 1);
    }

    /**
     * <p>
     * 数据标识id部分
     * </p>
     */
    protected static long getDatacenterId(long maxDatacenterId) {
        long id = 0L;
        try {
            InetAddress ip = InetAddress.getLocalHost();
            NetworkInterface network = NetworkInterface.getByInetAddress(ip);
            if (network == null) {
                id = 1L;
            } else {
                byte[] mac = network.getHardwareAddress();
                id = ((0x000000FF & (long) mac[mac.length - 1])
                        | (0x0000FF00 & (((long) mac[mac.length - 2]) << 8))) >> 6;
                id = id % (maxDatacenterId + 1);
            }
        } catch (Exception e) {
            System.out.println(" getDatacenterId: " + e.getMessage());
        }
        return id;
    }
}

 创建实体类模块:

 跟上面一样的步骤

pom:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.flowerfog</groupId>
        <artifactId>staff_parent</artifactId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <artifactId>staff-common-model</artifactId>
    <packaging>war</packaging>
    <name>staff-common-model Maven Webapp</name>
    <url>http://maven.apache.org</url>
    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.flowerfog</groupId>
            <artifactId>staff-common</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>
    </dependencies>
    <build>
        <finalName>staff-common-model</finalName>
    </build>
</project>

 创建company子模块:

pom:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.flowerfog</groupId>
        <artifactId>staff_parent</artifactId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <artifactId>staff-company</artifactId>
    <packaging>war</packaging>
    <name>staff-company Maven Webapp</name>
    <url>http://maven.apache.org</url>
    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
        </dependency>
        <dependency>
            <groupId>org.flowerfog</groupId>
            <artifactId>staff-common</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>org.flowerfog</groupId>
            <artifactId>staff-common-model</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>
    </dependencies>
    <build>
        <finalName>staff-company</finalName>
    </build>
</project>

CompanyApplication:

package org.flowerfog.company;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan;

//1.扫描包
@SpringBootApplication(scanBasePackages = "org.flowerfog.company")
//2.jap注解扫描
@EntityScan(value = "org.flowerfog.domain.company")
public class CompanyApplication {

    /**
     * 启动方法
     */
    public static void main(String[] args) {
        SpringApplication.run(CompanyApplication.class,args);
    }

}

 Company类:

package org.flowerfog.domain.company;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import java.io.Serializable;
import java.util.Date;

@Data
@AllArgsConstructor
public class Company implements Serializable {
    private static final long serialVersionUID = 594829320797158219L;
    //ID
    @Id
    private String id;
    /**
     * 公司名称
     */
    private String name;
    /**
     * 企业登录账号ID
     */
    private String managerId;
    /**
     * 当前版本
     */
    private String version;
    /**
     * 续期时间
     */
    private Date renewalDate;
    /**
     * 到期时间
     */
    private Date expirationDate;
    /**
     * 公司地区
     */
    private String companyArea;
    /**
     * 公司地址
     */
    private String companyAddress;
    /**
     * 营业执照-图片ID
     */
    private String businessLicenseId;
    /**
     * 法人代表
     */
    private String legalRepresentative;
    /**
     * 公司电话
     */
    private String companyPhone;
    /**
     * 邮箱
     */
    private String mailbox;
    /**
     * 公司规模
     */
    private String companySize;
    /**
     * 所属行业
     */
    private String industry;
    /**
     * 备注
     */
    private String remarks;
    /**
     * 审核状态
     */
    private String auditState;
    /**
     * 状态
     */
    private Integer state;
    /**
     * 当前余额
     */
    private Double balance;
    /**
     * 创建时间
     */
    private Date createTime;
}

department类:

package org.flowerfog.domain.company;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;
import java.io.Serializable;
import java.util.Date;
import java.util.List;

/**
 * (Department)实体类
 */
@Entity
@Table(name = "co_department")
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Department implements Serializable {
    private static final long serialVersionUID = -9084332495284489553L;
    //ID
    @Id
    private String id;
    /**
     * 父级ID
     */
    private String pid;
    /**
     * 企业ID
     */
    private String companyId;
    /**
     * 部门名称
     */
    private String name;
    /**
     * 部门编码,同级部门不可重复
     */
    private String code;

    /**
     * 负责人ID
     */
    private String managerId;
    /**
	*  负责人名称
	*/
    private String manager;

    /**
     * 介绍
     */
    private String introduce;
    /**
     * 创建时间
     */
    private Date createTime;
}

deplistResult类(封装部门列表) 

package org.flowerfog.domain.company.response;

import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.flowerfog.domain.company.Company;
import org.flowerfog.domain.company.Department;

import java.util.List;

@Getter
@Setter
@NoArgsConstructor
public class DeptListResult {

    private String companyId;
    private String companyName;
    private String companyManage;
    private List<Department> depts;

    public DeptListResult(Company company,List depts){
        this.companyId = company.getId();
        this.companyName = company.getName();
        this.companyManage = company.getLegalRepresentative();//公司联系人
        this.depts = depts;
    }

}

Controller:

CompanyController:

package org.flowerfog.company.controller;

import org.flowerfog.company.service.CompanyService;
import org.flowerfog.domain.company.Company;
import org.flowerfog.entity.Result;
import org.flowerfog.entity.ResultCode;
import org.flowerfog.exception.CommonException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

//解决跨域
@CrossOrigin
@RestController
@RequestMapping(value = "/company")
public class CompanyController {

    @Autowired
    private CompanyService companyService;

    //保存企业
    @RequestMapping(value = "",method = RequestMethod.POST)
    public Result save(@RequestBody Company company){
        //业务
        companyService.add(company);
        return new Result(ResultCode.SUCCESS);

    }
    //根据id更新企业
    @RequestMapping(value = "/{id}",method = RequestMethod.PUT)
    public Result update(@PathVariable(value = "id") String id,@RequestBody Company company){

        //业务
        company.setId(id);
        companyService.update(company);
        return new Result(ResultCode.SUCCESS);
    }
    //删除企业
    @RequestMapping(value = "/{id}",method = RequestMethod.DELETE)
    public Result delete(@PathVariable(value = "id") String id){
        companyService.deleteById(id);
        return new Result(ResultCode.SUCCESS);
    }
    //查询
    @RequestMapping(value = "/{id}",method = RequestMethod.GET)
    public Result findById(@PathVariable(value = "id") String id) throws CommonException {

        Company company = companyService.findById(id);
        Result result = new Result((ResultCode.SUCCESS));
        result.setData(company);
        return result;
    }
    //查询列表
    @RequestMapping(value = "",method = RequestMethod.GET)
    public Result findAll(){

//        int i = 1/0;
        List<Company> List = companyService.findAll();
        Result result = new Result(ResultCode.SUCCESS);
        result.setData(List);
        return result;
    }
}

DepartmentController:

 

package org.flowerfog.company.controller;

import com.sun.xml.internal.bind.v2.TODO;
import org.flowerfog.company.service.CompanyService;
import org.flowerfog.company.service.DepartmentService;
import org.flowerfog.controller.BaseController;
import org.flowerfog.domain.company.Company;
import org.flowerfog.domain.company.Department;
import org.flowerfog.domain.company.response.DeptListResult;
import org.flowerfog.entity.Result;
import org.flowerfog.entity.ResultCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin
@RequestMapping(value = "/company")
@RestController
public class DepartmentController extends BaseController {
    @Autowired
    private DepartmentService departmentService;

    @Autowired
    private CompanyService companyService;

    /**
     * 保存
     * @param department
     * @return
     */
    @RequestMapping(value = "/department",method = RequestMethod.POST)
    public Result save(@RequestBody Department department){

        //设置id
        /**
         * 企业id:使用固定值
         */
        department.setCompanyId(companyId);

        //调用service
        departmentService.save(department);

        return new Result(ResultCode.SUCCESS);

    }

    /**
     * 查询部门列表
     * @return
     */
    @RequestMapping(value = "/department",method = RequestMethod.GET)
    public Result findAll(){
        // id
        Company company = companyService.findById(companyId);
        List<Department> list = departmentService.findAll(companyId);
        //返回
        DeptListResult deptListResult = new DeptListResult(company,list);

        return new Result(ResultCode.SUCCESS,deptListResult);
    }


    @RequestMapping(value = "/department/{id}",method = RequestMethod.GET)
    public Result findById(@PathVariable(value = "id") String id){
        Department department = departmentService.findById(id);
        return new Result(ResultCode.SUCCESS,department);
    }

    @RequestMapping(value = "/department/{id}",method = RequestMethod.POST)
    public Result update(@PathVariable(value = "id") String id,@RequestBody Department department){
        Department dep = departmentService.findById(id);
        dep.setId(department.getId());

        departmentService.update(dep);

        return new Result(ResultCode.SUCCESS);
    }

    @RequestMapping(value = "/department/{id}",method = RequestMethod.DELETE)
    public Result delete(@PathVariable(value = "id") String id){
        departmentService.deleteById(id);

        return new Result(ResultCode.SUCCESS);

    }
}

Dao: 

CompanyDao: 

package org.flowerfog.company.dao;

import org.flowerfog.domain.company.Company;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;

/**
 * 自定义dao接口继承
 *      JpaRepository<实体类,主键>
 *      JpaSpecificationExecutor<实体类>
 */
public interface CompanyDao extends JpaRepository<Company,String> ,JpaSpecificationExecutor<Company> {
}

DepartmentDao就不放了,跟上面同理

Service:

CompanyService: 

package org.flowerfog.company.service;

import org.flowerfog.company.dao.CompanyDao;
import org.flowerfog.domain.company.Company;
import org.flowerfog.utils.IdWorker;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CompanyService {
    @Autowired
    private CompanyDao companyDao;

    @Autowired
    private IdWorker idWorker;
    /**
     * 保存企业
     *  1.配置idwork到工程
     *  2.在service中注入idwork
     *  3.通过idwork生成id
     *  4.保存企业
     */
    public void add(Company company) {
        //基本属性的设置
        String id = idWorker.nextId()+"";
        company.setId(id);
        //默认的状态
        company.setAuditState("0");//0:未审核,1:已审核
        company.setState(1); //0.未激活,1:已激活
        companyDao.save(company);
    }

    /**
     * 更新企业
     *  1.参数:Company
     *  2.根据id查询企业对象
     *  3.设置修改的属性
     *  4.调用dao完成更新
     */
    public void update(Company company) {
        Company temp = companyDao.findById(company.getId()).get();
        temp.setName(company.getName());
        temp.setCompanyPhone(company.getCompanyPhone());
        companyDao.save(temp);
    }


    /**
     * 删除企业
     */
    public void deleteById(String id) {
        companyDao.deleteById(id);
    }

    /**
     * 根据id查询企业
     */
    public Company findById(String id) {
        return companyDao.findById(id).get();
    }

    /**
     * 查询企业列表
     */
    public List<Company> findAll() {
        return companyDao.findAll();
    }
}

DepartmentService:

package org.flowerfog.company.service;

import org.flowerfog.company.dao.DepartmentDao;
import org.flowerfog.domain.company.Department;
import org.flowerfog.service.BaseService;
import org.flowerfog.utils.IdWorker;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;

import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import java.util.List;

@Service
public class DepartmentService extends BaseService {

    @Autowired
    private DepartmentDao departmentDao;
    @Autowired
    private IdWorker idWorker;
    /**
     * 保存部门
     */
    public void save(Department department){
        //设置主键值
        String id =idWorker.nextId()+"";
        department.setId(id);
        //调用dao保存
        departmentDao.save(department);
    }

    /**
     * 更新部门
     */
    public void update(Department department){
        //查询
        Department dept = departmentDao.findById(department.getId()).get();
        //设置修改属性
        dept.setCode(department.getCode());
        dept.setIntroduce(department.getIntroduce());
        dept.setName(department.getName());


        //更新部门
        departmentDao.save(dept);
    }
    /**
     * 根据id查询
     */
    public Department findById(String id){
        return departmentDao.findById(id).get();
    }
    /**
     * 查询全部
     */
    //TODO
    public List<Department> findAll(String companyId){
//        Specification<Department> spec = new Specification<Department>() {
//
//            @Override
//            public Predicate toPredicate(Root<Department> root, CriteriaQuery<?> cq, CriteriaBuilder cb) {
//                //根据id查询
//                return cb.equal(root.get("companyId").as(String.class),id);
//            }
//        };
        return departmentDao.findAll(getSpec(companyId));
    }

    /**
     * id删除部门
     */
    public void deleteById(String id){
        departmentDao.deleteById(id);



    }
}

Application:

 

package org.flowerfog.company;

import org.flowerfog.utils.IdWorker;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.context.annotation.Bean;



//1.配置springboot的包扫描
@SpringBootApplication(scanBasePackages = "org.flowerfog")
//2.配置jpa注解的扫描
@EntityScan(value="org.flowerfog.domain.company")
public class CompanyApplication {

    /**
     * 启动方法
     */
    public static void main(String[] args) {
        SpringApplication.run(CompanyApplication.class,args);
    }

    @Bean
    public IdWorker idWorker() {
        return new IdWorker();
    }
}

此时子模块目录如下:

 

至此,Company子模块构建成功 

 

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2265771.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

前端bug调试

报错和Bug&#xff0c;是贯穿程序员整个编程生涯中&#xff0c;无法回避的问题。而调试&#xff0c;就是帮助程序员定位问题、解决问题的重要手段&#xff0c;因此&#xff0c;调试是每个程序员必备技能。 调试基本流程 核心原则&#xff1a;最重要的就是不断地缩小范围&…

【落羽的落羽 C语言篇】自定义类型——联合体、枚举

文章目录 一、联合体1. 联合体类型的声明2. 联合体的特点3. 联合体的大小4. 联合体和结构体的对比 二、枚举1. 枚举类型的声明2. 枚举类型的优点 一、联合体 1. 联合体类型的声明 联合体像结构体一样&#xff0c;也是由一个或多个成员构成&#xff0c;这些成员可以是不同的类…

大数据技术-Hadoop(二)HDFS的介绍与使用

目录 1、HDFS简介 1.1 什么是HDFS 1.2 HDFS的优点 1.3、HDFS的架构 1.3.1、 NameNode 1.3.2、 NameNode的职责 1.3.3、DataNode 1.3.4、 DataNode的职责 1.3.5、Secondary NameNode 1.3.6、Secondary NameNode的职责 2、HDFS的工作原理 2.1、文件存储 2.2 、数据写…

学习threejs,THREE.CircleGeometry 二维平面圆形几何体

&#x1f468;‍⚕️ 主页&#xff1a; gis分享者 &#x1f468;‍⚕️ 感谢各位大佬 点赞&#x1f44d; 收藏⭐ 留言&#x1f4dd; 加关注✅! &#x1f468;‍⚕️ 收录于专栏&#xff1a;threejs gis工程师 文章目录 一、&#x1f340;前言1.1 ☘️THREE.CircleGeometry 圆形…

替换 Docker.io 的 Harbor 安全部署指南:域名与 IP 双支持的镜像管理解决方案

经过验证 替换 Docker.io 的方式失败了, 以下的过程中还是需要设置 registry-mirrors 才行 以下是一篇详细教程&#xff0c;展示如何基于 openssl.conf 配置生成域名为 registry-1.docker.io 和 IP 地址为 172.16.20.20 的证书&#xff0c;构建 Harbor 服务。 环境准备 系统环境…

【源码编译】windows下mingw64安装以及cmake调用

最近因为安装MIRTK库&#xff0c;太多第三方依赖了&#xff0c;太折磨了&#xff0c;学习了使用Cmake&#xff0c;有些库又需要Fortran编译器&#xff0c;VS2022里面装了但又调用不了&#xff0c;也不知道为什么&#xff0c;最后装的mingw64&#xff0c;记录一下。 1、mingw64安…

【机器学习(九)】分类和回归任务-多层感知机(Multilayer Perceptron,MLP)算法-Sentosa_DSML社区版 (1)111

文章目录 一、算法概念111二、算法原理&#xff08;一&#xff09;感知机&#xff08;二&#xff09;多层感知机1、隐藏层2、激活函数sigma函数tanh函数ReLU函数 3、反向传播算法 三、算法优缺点&#xff08;一&#xff09;优点&#xff08;二&#xff09;缺点 四、MLP分类任务…

基于AI IDE 打造快速化的游戏LUA脚本的生成系统

前面写了一篇关于使用AI IDE进行C安全开发的博客《使用AI IDE 助力 C 高性能安全开发&#xff01;》&#xff0c; 得到许多同学们的喜欢&#xff0c;今天我们来继续在游戏开发中扩展一下AI的能力&#xff0c;看看能不能给游戏研发团队一些启发。 在游戏研发中&#xff0c;Lua曾…

系统思考VS过度管理

业绩没起来&#xff0c;领导者最容易做的就是抓管理。这样的“抓管理”真的有效吗&#xff1f;当业务还没起飞的时候&#xff0c;过度管理其实是一种伤害。就像一条呼啸而过的鞭子&#xff0c;看起来让团队更“整齐”&#xff0c;但实际上可能打散了协作的节奏。管理的本质是支…

IT运维的365天--021 服务器上的dns设置后不起作用

之前在内网搭建了一个和外网同域名的网站&#xff0c;开发同事今天告诉我&#xff0c;程序调试发现可能服务器不能正常访问自己内网的网站内容。于是&#xff0c;今天的故事开始了。 前面的文章在下面列出&#xff0c;当然不看也问题不大&#xff0c;今天的主题是&#xff1a;…

机器人C++开源库The Robotics Library (RL)使用手册(二)

由于RL库采用跨平台CMake源码,可以轻松在win、ubantu等平台部署、编译,win通常用VS编译器,为了便于使用、阅读,需要将CMake编译成VS工程。 1、准备三个工具:CMake、VS、QT 为了在Windows上编译RL和依赖项,您需要安装一个编译器(例如。,Visual Studio 2017)和跨平台构…

ShaderJoy ——一种可交互的翻页效果【GLSL】

效果视频 Shader 特效——可与鼠标交互的翻页效果 效果图 完整代码 #define pi 3.14159265359 #define radius .1#iChannel0 "file://./images/Woolly_3.png" #iChannel1 "file://./images/Woolly_4.png"void mainImage( out vec4 fragColor, in vec2 fra…

oracle怎样使用logmnr恢复误删除的数据

如果有同事误删除数据了&#xff0c;可以用logmnr挖掘归档日志&#xff0c;生成回滚sql&#xff0c;快速恢复数据&#xff0c;比用整个库的备份恢复要快得多。 一 操作步骤 1.1 创建目录 su - oracle mkdir logmnr create directory logmnr_dir as /home/oracle/logmnr; …

LeetCode:3218. 切蛋糕的最小总开销 I(贪心 Java)

目录 3218. 切蛋糕的最小总开销 I 题目描述&#xff1a; 实现代码与解析&#xff1a; 贪心 原理思路&#xff1a; 3218. 切蛋糕的最小总开销 I 题目描述&#xff1a; 有一个 m x n 大小的矩形蛋糕&#xff0c;需要切成 1 x 1 的小块。 给你整数 m &#xff0c;n 和两个数…

系统架构师考试 常错题记录 01

1.按照《中华人民共和国著作权法》的权利保护期&#xff08; &#xff09;受到永久保护。 A.发表权 B.修改权 C.复制权 D.发行权 正确答案&#xff1a;B 解析&#xff1a;本题考查知识产权法中的《中华人民共和著作权法》保护期限知识点。 《中华人民共和著作权法》中约定署名权…

实战分享:生产Java服务容器占用内存高问题排查与解决

总框架 一、问题描述 生产上有一个Java应用&#xff0c;在发版后一周内&#xff0c;容器内存指标缓慢上升&#xff0c;最终超过60%触发内存使用告警 二、思路&解决方案 1、日志占用容器内存 &#xff08;1&#xff09;排查JVM占用了多少内存 一般我们惯性思维默认是J…

OpenAI叩响AGI之门: 12天直播精华大放送

01.OpenAI新篇章: 12天直播精华放送 当地时间12月5日-20日&#xff0c;人工智能巨头OpenAI完成了连续12个工作日的12场直播&#xff0c;虽然周末短暂休息了两天&#xff0c;但圣诞节的技术盛宴依然引发了广泛关注。内容密集、干货充足&#xff0c;许多小伙伴们可能感到信息有点…

神经网络-AlexNet

AlexNet是在2012年的ImageNet竞赛后&#xff0c;整理发表的文章&#xff0c;也是对CNN网络的衍生。 网络结构 AlexNet网络结构如下图所示&#xff0c;网络分为了上下两部分&#xff0c;对应两个不同的GPU训练&#xff0c;可以更好的利用GPU算力。只有在特殊的网络层后&#x…

【Beats01】企业级日志分析系统ELK之Metricbeat与Heartbeat 监控

Beats 收集数据 Beats 是一个免费且开放的平台&#xff0c;集合了多种单一用途数据采集器。它们从成百上千或成千上万台机器 和系统向 Logstash 或 Elasticsearch 发送数据。 虽然利用 logstash 就可以收集日志&#xff0c;功能强大&#xff0c;但由于 Logtash 是基于Java实现…

目标检测——基于yolov8和pyqt的螺栓松动检测系统

目录 1.项目克隆和环境配置1.1 我这里使用的是v8.0.6版本1.2 项目代码结构介绍 2.数据集介绍2.1 数据集采集2.2采集结果介绍 3.模型训练4.pyqt界面设计4.1 界面内容介绍4.2 界面实现 5.操作中的逻辑实现5.1 图片检测5.2 文件夹检测5.3 视频检测和摄像头检测 6. 效果展示 1.项目…