增加公司接口和公司表sql
This commit is contained in:
parent
0c8dd1d0a1
commit
650f347ab6
|
@ -5,7 +5,7 @@ public class UserConstant {
|
||||||
public static final String MENU_LIST_PREFIX = "gwwMenuList:";
|
public static final String MENU_LIST_PREFIX = "gwwMenuList:";
|
||||||
public static final String DEFAULT_PASSWORD = "123456";
|
public static final String DEFAULT_PASSWORD = "123456";
|
||||||
public static final String NORMAL = "1";
|
public static final String NORMAL = "1";
|
||||||
public static final String FORBIDDEN = "2";
|
public static final String FORBIDDEN = "0";
|
||||||
public static final Long MENU_ROOT_ID = 0L;
|
public static final Long MENU_ROOT_ID = 0L;
|
||||||
public static final Long SUPER_ADMIN_ID = 1L;
|
public static final Long SUPER_ADMIN_ID = 1L;
|
||||||
public static final String HEADER_TOKEN_NAME = "gwwToken";
|
public static final String HEADER_TOKEN_NAME = "gwwToken";
|
||||||
|
|
|
@ -0,0 +1,55 @@
|
||||||
|
package com.isu.gaswellwatch.controller;
|
||||||
|
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import com.isu.gaswellwatch.annotation.OperationLog;
|
||||||
|
import com.isu.gaswellwatch.dto.CompanyDTO;
|
||||||
|
import com.isu.gaswellwatch.dto.CompanyEditDTO;
|
||||||
|
import com.isu.gaswellwatch.entity.Response;
|
||||||
|
import com.isu.gaswellwatch.enums.LogType;
|
||||||
|
import com.isu.gaswellwatch.service.CompanyService;
|
||||||
|
import com.isu.gaswellwatch.vo.CompanyVO;
|
||||||
|
import jakarta.annotation.Resource;
|
||||||
|
import jakarta.validation.Valid;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("company")
|
||||||
|
public class CompanyController {
|
||||||
|
/**
|
||||||
|
* 服务对象
|
||||||
|
*/
|
||||||
|
@Resource
|
||||||
|
private CompanyService companyService;
|
||||||
|
|
||||||
|
@GetMapping("/page")
|
||||||
|
public Response<Page<CompanyVO>> page(@RequestParam(defaultValue = "1") Integer currentPage,
|
||||||
|
@RequestParam(defaultValue = "10") Integer pageSize,
|
||||||
|
@RequestParam(required = false) String name,
|
||||||
|
@RequestParam(required = false) String code){
|
||||||
|
return Response.succeed(companyService.page(currentPage,pageSize,name,code));
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/add")
|
||||||
|
@OperationLog(description = "新增公司",type = LogType.ADD)
|
||||||
|
public Response<String> add(@RequestBody @Valid CompanyDTO companyDTO){
|
||||||
|
companyService.add(companyDTO);
|
||||||
|
return Response.succeed();
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/edit")
|
||||||
|
@OperationLog(description = "修改公司",type = LogType.UPDATE)
|
||||||
|
public Response<String> edit(@RequestBody @Valid CompanyEditDTO companyEditDTO){
|
||||||
|
companyService.edit(companyEditDTO);
|
||||||
|
return Response.succeed();
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/delete")
|
||||||
|
@OperationLog(description = "删除公司",type = LogType.DELETE)
|
||||||
|
public Response<String> delete(@RequestParam Long id){
|
||||||
|
companyService.delete(id);
|
||||||
|
return Response.succeed();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,22 @@
|
||||||
|
package com.isu.gaswellwatch.dao;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import com.isu.gaswellwatch.entity.Company;
|
||||||
|
import com.isu.gaswellwatch.vo.CompanyVO;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Mapper
|
||||||
|
@Repository
|
||||||
|
public interface CompanyDao extends BaseMapper<Company> {
|
||||||
|
|
||||||
|
Page<CompanyVO> page(Page<Object> page,
|
||||||
|
@Param("name") String name,
|
||||||
|
@Param("code") String code
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,23 @@
|
||||||
|
package com.isu.gaswellwatch.dto;
|
||||||
|
|
||||||
|
import jakarta.validation.constraints.NotBlank;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class CompanyDTO {
|
||||||
|
//公司名称
|
||||||
|
@NotBlank(message = "名称不能为空")
|
||||||
|
private String name;
|
||||||
|
//描述
|
||||||
|
private String description;
|
||||||
|
//公司编号
|
||||||
|
private String code;
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,25 @@
|
||||||
|
package com.isu.gaswellwatch.dto;
|
||||||
|
|
||||||
|
import jakarta.validation.constraints.NotBlank;
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class CompanyEditDTO {
|
||||||
|
@NotNull(message = "id不能为空")
|
||||||
|
private Long id;
|
||||||
|
//名称
|
||||||
|
@NotBlank(message = "名称不能为空")
|
||||||
|
private String name;
|
||||||
|
//描述
|
||||||
|
private String description;
|
||||||
|
//编号
|
||||||
|
private String code;
|
||||||
|
}
|
|
@ -0,0 +1,30 @@
|
||||||
|
package com.isu.gaswellwatch.entity;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.activerecord.Model;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
public class Company extends Model<Company> {
|
||||||
|
|
||||||
|
private Long id;
|
||||||
|
//名称
|
||||||
|
private String name;
|
||||||
|
//描述
|
||||||
|
private String description;
|
||||||
|
//公司编码
|
||||||
|
private String code;
|
||||||
|
//创建时间
|
||||||
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||||
|
private Date createTime;
|
||||||
|
//更新时间
|
||||||
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||||
|
private Date updateTime;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
package com.isu.gaswellwatch.service;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
import com.isu.gaswellwatch.dto.CompanyDTO;
|
||||||
|
import com.isu.gaswellwatch.dto.CompanyEditDTO;
|
||||||
|
import com.isu.gaswellwatch.entity.Company;
|
||||||
|
import com.isu.gaswellwatch.vo.CompanyVO;
|
||||||
|
|
||||||
|
public interface CompanyService extends IService<Company> {
|
||||||
|
|
||||||
|
Page<CompanyVO> page(Integer currentPage, Integer pageSize, String name,String code);
|
||||||
|
void add(CompanyDTO companyDTO);
|
||||||
|
void edit(CompanyEditDTO companyEditDTO);
|
||||||
|
void delete(Long id);
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,66 @@
|
||||||
|
package com.isu.gaswellwatch.service.impl;
|
||||||
|
|
||||||
|
import cn.hutool.core.collection.CollectionUtil;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.isu.gaswellwatch.config.SnowflakeConfig;
|
||||||
|
import com.isu.gaswellwatch.service.CompanyService;
|
||||||
|
import com.isu.gaswellwatch.dao.CompanyDao;
|
||||||
|
import com.isu.gaswellwatch.dto.*;
|
||||||
|
import com.isu.gaswellwatch.entity.Company;
|
||||||
|
import com.isu.gaswellwatch.exception.BusinessException;
|
||||||
|
import com.isu.gaswellwatch.utils.ConverterUtil;
|
||||||
|
import com.isu.gaswellwatch.vo.CompanyVO;
|
||||||
|
import jakarta.annotation.Resource;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Service("companyService")
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public class CompanyServiceImpl extends ServiceImpl<CompanyDao, Company> implements CompanyService {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private SnowflakeConfig snowflakeConfig;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private CompanyDao companyDao;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Page<CompanyVO> page(Integer currentPage, Integer pageSize, String name,String code){
|
||||||
|
Page<CompanyVO> page = companyDao.page(new Page<>(currentPage, pageSize),name,code);
|
||||||
|
return ConverterUtil.convertPage(page,CompanyVO.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void add(CompanyDTO companyDTO){
|
||||||
|
//查重
|
||||||
|
List<Company> list = list(new LambdaQueryWrapper<Company>().eq(Company::getName, companyDTO.getName()));
|
||||||
|
if(CollectionUtil.isNotEmpty(list)) {
|
||||||
|
throw new BusinessException("已有相同名称,请重新输入");
|
||||||
|
}
|
||||||
|
Long companyId = snowflakeConfig.snowflakeId();
|
||||||
|
save(Company.builder().id(companyId).name(companyDTO.getName()).description(companyDTO.getDescription()).code(companyDTO.getCode()).build());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void edit(CompanyEditDTO companyEditDTO){
|
||||||
|
List<Company> list = list(new LambdaQueryWrapper<Company>().eq(Company::getName, companyEditDTO.getName()).ne(Company::getId, companyEditDTO.getId()));
|
||||||
|
if(CollectionUtil.isNotEmpty(list)) {
|
||||||
|
throw new BusinessException("公司名称已存在,请重新输入");
|
||||||
|
}
|
||||||
|
updateById(ConverterUtil.convert(companyEditDTO, Company.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void delete(Long id){
|
||||||
|
//TODO 如果公司绑定了气井 不能删除
|
||||||
|
|
||||||
|
//删除
|
||||||
|
removeById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,27 @@
|
||||||
|
package com.isu.gaswellwatch.vo;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class CompanyVO implements Serializable {
|
||||||
|
private Long id;
|
||||||
|
//名称
|
||||||
|
private String name;
|
||||||
|
//描述
|
||||||
|
private String description;
|
||||||
|
//编号
|
||||||
|
private String code;
|
||||||
|
//创建时间
|
||||||
|
private String createTime;
|
||||||
|
//更新时间
|
||||||
|
private String updateTime;
|
||||||
|
}
|
|
@ -11,12 +11,32 @@
|
||||||
Target Server Version : 80034
|
Target Server Version : 80034
|
||||||
File Encoding : 65001
|
File Encoding : 65001
|
||||||
|
|
||||||
Date: 30/10/2024 11:13:08
|
Date: 01/11/2024 16:44:33
|
||||||
*/
|
*/
|
||||||
|
|
||||||
SET NAMES utf8mb4;
|
SET NAMES utf8mb4;
|
||||||
SET FOREIGN_KEY_CHECKS = 0;
|
SET FOREIGN_KEY_CHECKS = 0;
|
||||||
|
|
||||||
|
-- ----------------------------
|
||||||
|
-- Table structure for company
|
||||||
|
-- ----------------------------
|
||||||
|
DROP TABLE IF EXISTS `company`;
|
||||||
|
CREATE TABLE `company` (
|
||||||
|
`id` bigint NOT NULL,
|
||||||
|
`name` varchar(255) DEFAULT NULL COMMENT '公司名称',
|
||||||
|
`description` varchar(500) DEFAULT NULL COMMENT '描述',
|
||||||
|
`create_time` timestamp NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||||
|
`update_time` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||||
|
`code` varchar(100) DEFAULT NULL COMMENT '公司编号',
|
||||||
|
PRIMARY KEY (`id`)
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
|
||||||
|
|
||||||
|
-- ----------------------------
|
||||||
|
-- Records of company
|
||||||
|
-- ----------------------------
|
||||||
|
BEGIN;
|
||||||
|
COMMIT;
|
||||||
|
|
||||||
-- ----------------------------
|
-- ----------------------------
|
||||||
-- Table structure for menu
|
-- Table structure for menu
|
||||||
-- ----------------------------
|
-- ----------------------------
|
||||||
|
@ -111,7 +131,7 @@ CREATE TABLE `user` (
|
||||||
`nickname` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '昵称',
|
`nickname` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '昵称',
|
||||||
`phone` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '手机号',
|
`phone` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '手机号',
|
||||||
`picture` text CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci COMMENT '头像',
|
`picture` text CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci COMMENT '头像',
|
||||||
`is_enable` char(1) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '是否启用(1启用,2冻结)',
|
`is_enable` char(1) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '是否启用(1启用,0冻结)',
|
||||||
`create_time` timestamp NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
`create_time` timestamp NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||||
`update_time` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
`update_time` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||||
PRIMARY KEY (`id`) USING BTREE
|
PRIMARY KEY (`id`) USING BTREE
|
||||||
|
|
|
@ -0,0 +1,20 @@
|
||||||
|
<?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">
|
||||||
|
<mapper namespace="com.isu.gaswellwatch.dao.CompanyDao">
|
||||||
|
|
||||||
|
<select id="page" resultType="com.isu.gaswellwatch.vo.CompanyVO">
|
||||||
|
select u.id, u.name, u.description, u.code, u.create_time, u.update_time
|
||||||
|
from company u
|
||||||
|
<where>
|
||||||
|
<if test="name!=null and name!='' ">
|
||||||
|
and u.name LIKE CONCAT('%',#{name},'%')
|
||||||
|
</if>
|
||||||
|
<if test="code!=null and code!='' ">
|
||||||
|
and u.code LIKE CONCAT('%',#{code},'%')
|
||||||
|
</if>
|
||||||
|
</where>
|
||||||
|
order by u.create_time desc
|
||||||
|
</select>
|
||||||
|
|
||||||
|
</mapper>
|
||||||
|
|
Loading…
Reference in New Issue