设备、组织、标准分类完善

This commit is contained in:
lhx
2025-11-17 17:18:41 +08:00
parent 433654ad28
commit fc9594c771
16 changed files with 549 additions and 56 deletions

View File

@@ -0,0 +1,32 @@
package com.dc.dc_project.controller;
import com.dc.dc_project.common.ResponseResult;
import com.dc.dc_project.model.dto.EquipmentAddDto;
import com.dc.dc_project.service.EquipmentService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
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;
@RestController
@RequestMapping("/equipment")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class EquipmentController {
private final EquipmentService equipmentService;
@PostMapping("/list")
public String list() {
return equipmentService.list().toString();
}
@PostMapping("/add")
public ResponseResult add(@RequestBody @Validated EquipmentAddDto equipmentDto) {
Long userId = 1L;
return equipmentService.add(equipmentDto, userId);
}
}

View File

@@ -0,0 +1,31 @@
package com.dc.dc_project.controller;
import com.dc.dc_project.common.ResponseResult;
import com.dc.dc_project.model.dto.OrgDto;
import com.dc.dc_project.model.pojo.Org;
import com.dc.dc_project.service.OrgService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
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;
@RestController
@RequestMapping("/org")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class OrgController {
private final OrgService orgService;
@RequestMapping("/list")
public String list() {
return orgService.list().toString();
}
@PostMapping("/add")
public ResponseResult add(@RequestBody OrgDto orgDto) {
return orgService.newOrg(orgDto);
}
}

View File

@@ -0,0 +1,31 @@
package com.dc.dc_project.controller;
import com.dc.dc_project.common.ResponseResult;
import com.dc.dc_project.model.dto.StandardCategoryDto;
import com.dc.dc_project.service.StandardCategoryService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
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;
@RestController
@RequestMapping("/standardCategory")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class StandardCategoryController {
private final StandardCategoryService standardCategoryService;
@PostMapping("/list")
public String list() {
return standardCategoryService.list().toString();
}
@PostMapping("/add")
public ResponseResult add(@RequestBody @Validated StandardCategoryDto standardCategoryDto) {
return standardCategoryService.add(standardCategoryDto);
}
}

View File

@@ -0,0 +1,43 @@
package com.dc.dc_project.enums.laboratory.Equipment;
import lombok.Getter;
@Getter
public enum EStatus{
Unused(0, "未使用"),
Using(1, "使用中"),
Fault(2, "故障"),
Repairing(3, "维修中"),
Destroyed(4, "已销毁"),
Good(5, "良好");
EStatus(Integer code, String name){
this.code = code;
this.name = name;
}
private final Integer code;
private final String name;
public static EStatus getEStatus(Integer code){
for (EStatus value : EStatus.values()) {
if(value.getCode().equals(code)){
return value;
}
}
return null;
}
public EStatus getEStatus(String name){
for (EStatus value : EStatus.values()) {
if(value.getName().equals(name)){
return value;
}
}
return null;
}
}

View File

@@ -0,0 +1,38 @@
package com.dc.dc_project.enums.laboratory;
import lombok.Data;
import lombok.Getter;
@Getter
public enum OrgType {
COMPANY(1, "公司"),
DEPARTMENT(2, "部门"),
LABORATORY(3, "实验室");
private final Integer code;
private final String name;
OrgType(Integer code, String name) {
this.code = code;
this.name = name;
}
public static String getName(Integer code) {
for (OrgType value : OrgType.values()) {
if (value.getCode().equals(code)) {
return value.name;
}
}
return "";
}
public static Integer getCode(String message) {
for (OrgType value : OrgType.values()) {
if (value.getName().equals(message)) {
return value.code;
}
}
return null;
}
}

View File

@@ -0,0 +1,123 @@
package com.dc.dc_project.model.dto;
import com.baomidou.mybatisplus.annotation.TableField;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class EquipmentAddDto {
/**
* 所属组织ID试验室
*/
private Long orgId;
/**
* 设备名称
*/
private String name;
/**
* 设备型号
*/
private String model;
/**
* 生产厂家
*/
private String manufacturer;
/**
* 出厂编号
*/
private String serialNo;
/**
* 购置日期
*/
private LocalDate purchaseDate;
/**
* 单价
*/
private BigDecimal price;
/**
* 量程范围
*/
private String rangeValue;
/**
* 精度等级
*/
private String accuracy;
/**
* 设备状态1=在用2=停用3=报废)
*/
private Integer status;
/**
* 检校单位
*/
private String calibrationOrg;
/**
* 最近检校日期
*/
private LocalDate calibrationDate;
/**
* 检校有效期
*/
private LocalDate validUntil;
/**
* 存放位置
*/
private String location;
/**
* 责任人user_id
*/
private Long responsibleUser;
/**
* 备注说明
*/
private String remark;
/**
* 创建人
*/
private Long createdBy;
/**
* 更新人ID
*/
private Long updatedBy;
/**
* 出厂日期
*/
private LocalDate serialData;
/**
* 朔源方式
*/
private Long traceabilityMethod;
/**
* 检测证书编号
*/
private String calibrationCertificate;
}

View File

@@ -0,0 +1,59 @@
package com.dc.dc_project.model.dto;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.time.LocalDateTime;
@Data
@NoArgsConstructor
@AllArgsConstructor
public class OrgDto {
/**
* 上级组织ID
*/
private Long parentId;
/**
* 组织名称
*/
private String name;
/**
* 组织类型1=公司2=项目部3=试验室)
*/
private Integer type;
/**
* 组织编码
*/
private String code;
/**
* 排序号
*/
private Integer sortOrder;
/**
* 备注
*/
private String remark;
/**
* 负责人id
*/
private Long leaderId;
/**
* 试验室类型(1工地2中心3未知)
*/
private Integer lTtype;
private String coordinateA;
private String coordinateB;
}

View File

@@ -0,0 +1,38 @@
package com.dc.dc_project.model.dto;
import com.baomidou.mybatisplus.annotation.TableField;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class StandardCategoryDto {
/**
* 上级分类ID
*/
private Long parentId = 0L;
/**
* 分类名称(如水利、电力、公路等)
*/
private String name;
/**
* 分类编码(可用于同步外部标准库)
*/
private String code;
/**
* 排序号
*/
private Integer sortOrder;
/**
* 备注
*/
private String remark;
}

View File

@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.dc.dc_project.model.dto.EquipmentAddDto;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;
@@ -181,5 +182,31 @@ public class Equipment {
@TableField(value = "calibration_certificate")
private String calibrationCertificate;
public static Equipment DtoToEquipment(EquipmentAddDto equipmentDto) {
Equipment equipment = new Equipment();
equipment.setOrgId(equipmentDto.getOrgId());
equipment.setName(equipmentDto.getName());
equipment.setModel(equipmentDto.getModel());
equipment.setManufacturer(equipmentDto.getManufacturer());
equipment.setSerialNo(equipmentDto.getSerialNo());
equipment.setPurchaseDate(equipmentDto.getPurchaseDate());
equipment.setPrice(equipmentDto.getPrice());
equipment.setRangeValue(equipmentDto.getRangeValue());
equipment.setAccuracy(equipmentDto.getAccuracy());
equipment.setStatus(equipmentDto.getStatus());
equipment.setCalibrationOrg(equipmentDto.getCalibrationOrg());
equipment.setCalibrationDate(equipmentDto.getCalibrationDate());
equipment.setValidUntil(equipmentDto.getValidUntil());
equipment.setLocation(equipmentDto.getLocation());
equipment.setResponsibleUser(equipmentDto.getResponsibleUser());
equipment.setRemark(equipmentDto.getRemark());
equipment.setCreatedBy(equipmentDto.getCreatedBy());
equipment.setUpdatedBy(equipmentDto.getUpdatedBy());
equipment.setSerialData(equipmentDto.getSerialData());
equipment.setTraceabilityMethod(equipmentDto.getTraceabilityMethod());
equipment.setCalibrationCertificate(equipmentDto.getCalibrationCertificate());
return equipment;
}
}

View File

@@ -69,61 +69,5 @@ public class StandardCategory {
@TableField(value = "is_deleted")
private Integer isDeleted;
@Override
public boolean equals(Object that) {
if (this == that) {
return true;
}
if (that == null) {
return false;
}
if (getClass() != that.getClass()) {
return false;
}
StandardCategory other = (StandardCategory) that;
return (this.getId() == null ? other.getId() == null : this.getId().equals(other.getId()))
&& (this.getParentId() == null ? other.getParentId() == null : this.getParentId().equals(other.getParentId()))
&& (this.getName() == null ? other.getName() == null : this.getName().equals(other.getName()))
&& (this.getCode() == null ? other.getCode() == null : this.getCode().equals(other.getCode()))
&& (this.getSortOrder() == null ? other.getSortOrder() == null : this.getSortOrder().equals(other.getSortOrder()))
&& (this.getRemark() == null ? other.getRemark() == null : this.getRemark().equals(other.getRemark()))
&& (this.getCreatedAt() == null ? other.getCreatedAt() == null : this.getCreatedAt().equals(other.getCreatedAt()))
&& (this.getUpdatedAt() == null ? other.getUpdatedAt() == null : this.getUpdatedAt().equals(other.getUpdatedAt()))
&& (this.getIsDeleted() == null ? other.getIsDeleted() == null : this.getIsDeleted().equals(other.getIsDeleted()));
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((getId() == null) ? 0 : getId().hashCode());
result = prime * result + ((getParentId() == null) ? 0 : getParentId().hashCode());
result = prime * result + ((getName() == null) ? 0 : getName().hashCode());
result = prime * result + ((getCode() == null) ? 0 : getCode().hashCode());
result = prime * result + ((getSortOrder() == null) ? 0 : getSortOrder().hashCode());
result = prime * result + ((getRemark() == null) ? 0 : getRemark().hashCode());
result = prime * result + ((getCreatedAt() == null) ? 0 : getCreatedAt().hashCode());
result = prime * result + ((getUpdatedAt() == null) ? 0 : getUpdatedAt().hashCode());
result = prime * result + ((getIsDeleted() == null) ? 0 : getIsDeleted().hashCode());
return result;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(getClass().getSimpleName());
sb.append(" [");
sb.append("Hash = ").append(hashCode());
sb.append(", id=").append(id);
sb.append(", parentId=").append(parentId);
sb.append(", name=").append(name);
sb.append(", code=").append(code);
sb.append(", sortOrder=").append(sortOrder);
sb.append(", remark=").append(remark);
sb.append(", createdAt=").append(createdAt);
sb.append(", updatedAt=").append(updatedAt);
sb.append(", isDeleted=").append(isDeleted);
sb.append("]");
return sb.toString();
}
}

View File

@@ -1,5 +1,7 @@
package com.dc.dc_project.service;
import com.dc.dc_project.common.ResponseResult;
import com.dc.dc_project.model.dto.EquipmentAddDto;
import com.dc.dc_project.model.pojo.Equipment;
import com.baomidou.mybatisplus.extension.service.IService;
@@ -10,4 +12,10 @@ import com.baomidou.mybatisplus.extension.service.IService;
*/
public interface EquipmentService extends IService<Equipment> {
/**
* 新增设备
* @param equipmentDto
* @return
*/
ResponseResult add(EquipmentAddDto equipmentDto, Long userId);
}

View File

@@ -1,5 +1,7 @@
package com.dc.dc_project.service;
import com.dc.dc_project.common.ResponseResult;
import com.dc.dc_project.model.dto.OrgDto;
import com.dc.dc_project.model.pojo.Org;
import com.baomidou.mybatisplus.extension.service.IService;
@@ -10,4 +12,10 @@ import com.baomidou.mybatisplus.extension.service.IService;
*/
public interface OrgService extends IService<Org> {
/**
* 新增组织
* @param orgDto
* @return
*/
ResponseResult newOrg(OrgDto orgDto);
}

View File

@@ -1,5 +1,7 @@
package com.dc.dc_project.service;
import com.dc.dc_project.common.ResponseResult;
import com.dc.dc_project.model.dto.StandardCategoryDto;
import com.dc.dc_project.model.pojo.StandardCategory;
import com.baomidou.mybatisplus.extension.service.IService;
@@ -10,4 +12,11 @@ import com.baomidou.mybatisplus.extension.service.IService;
*/
public interface StandardCategoryService extends IService<StandardCategory> {
/**
* 新增标准分类
* @param standardCategoryDto
* @
* @return
**/
ResponseResult add(StandardCategoryDto standardCategoryDto);
}

View File

@@ -1,12 +1,21 @@
package com.dc.dc_project.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dc.dc_project.common.ResponseResult;
import com.dc.dc_project.mapper.PersonnelMapper;
import com.dc.dc_project.model.dto.EquipmentAddDto;
import com.dc.dc_project.model.pojo.Equipment;
import com.dc.dc_project.model.pojo.Personnel;
import com.dc.dc_project.service.EquipmentService;
import com.dc.dc_project.mapper.EquipmentMapper;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import lombok.extern.slf4j.Slf4j;
import static com.dc.dc_project.model.pojo.Equipment.DtoToEquipment;
/**
* @author ADMIN
* @description 针对表【sys_equipment(设备台账表)】的数据库操作Service实现
@@ -14,9 +23,32 @@ import lombok.extern.slf4j.Slf4j;
*/
@Service
@Slf4j
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class EquipmentServiceImpl extends ServiceImpl<EquipmentMapper, Equipment>
implements EquipmentService{
private final PersonnelMapper personnelMapper;
@Override
public ResponseResult add(EquipmentAddDto equipmentDto, Long userId) {
LambdaQueryWrapper<Equipment> queryWrapper = new LambdaQueryWrapper<Equipment>()
.eq(Equipment::getSerialNo, equipmentDto.getSerialNo())
.eq(Equipment::getIsDeleted, 0);
if(this.count(queryWrapper) > 0){
return ResponseResult.error("出厂编号已存在");
}
LambdaQueryWrapper<Personnel> queryWrapper1 = new LambdaQueryWrapper<Personnel>()
.eq(Personnel::getUserId, userId)
.eq(Personnel::getIsDeleted, 0);
Personnel personnel = personnelMapper.selectOne(queryWrapper1);
equipmentDto.setCreatedBy(personnel.getId());
equipmentDto.setUpdatedBy(personnel.getId());
Equipment equipment = DtoToEquipment(equipmentDto);
return this.save(equipment) ? ResponseResult.success() : ResponseResult.error();
}
}

View File

@@ -1,12 +1,20 @@
package com.dc.dc_project.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dc.dc_project.common.ResponseResult;
import com.dc.dc_project.common.ResultCode;
import com.dc.dc_project.enums.laboratory.OrgType;
import com.dc.dc_project.model.dto.OrgDto;
import com.dc.dc_project.model.pojo.Laboratory;
import com.dc.dc_project.model.pojo.Org;
import com.dc.dc_project.service.OrgService;
import com.dc.dc_project.mapper.OrgMapper;
import org.springframework.stereotype.Service;
import lombok.extern.slf4j.Slf4j;
import java.util.Objects;
/**
* @author ADMIN
* @description 针对表【sys_org(组织架构表(公司/项目部/试验室))】的数据库操作Service实现
@@ -17,6 +25,42 @@ import lombok.extern.slf4j.Slf4j;
public class OrgServiceImpl extends ServiceImpl<OrgMapper, Org>
implements OrgService{
@Override
public ResponseResult newOrg(OrgDto orgDto) {
// 检验参数
LambdaQueryWrapper<Org> queryWrapper = new LambdaQueryWrapper<Org>()
.eq(Org::getIsDeleted, 0)
.eq(Org::getName, orgDto.getName())
.or()
.eq(Org::getCode, orgDto.getCode());
if(this.count(queryWrapper) > 0){
return ResponseResult.error("名称或编码重复");
}
// 上级组织ID检查
Org org = new Org();
org.setName(orgDto.getName());
org.setCode(orgDto.getCode());
org.setType(orgDto.getType());
org.setSortOrder(orgDto.getSortOrder());
org.setRemark(orgDto.getRemark());
org.setLeaderId(orgDto.getLeaderId());
if(!this.save(org)){
return ResponseResult.error(ResultCode.ERROR) ;
}
if(Objects.equals(orgDto.getType(), OrgType.LABORATORY.getCode())){
Laboratory laboratory = new Laboratory();
laboratory.setName(orgDto.getName());
laboratory.setCoordinateA(orgDto.getCoordinateA());
laboratory.setCoordinateB(orgDto.getCoordinateB());
laboratory.setType(orgDto.getLTtype());
laboratory.setOrgId(org.getId());
}
return ResponseResult.success("添加成功");
}
}

View File

@@ -1,6 +1,9 @@
package com.dc.dc_project.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dc.dc_project.common.ResponseResult;
import com.dc.dc_project.model.dto.StandardCategoryDto;
import com.dc.dc_project.model.pojo.StandardCategory;
import com.dc.dc_project.service.StandardCategoryService;
import com.dc.dc_project.mapper.StandardCategoryMapper;
@@ -17,6 +20,29 @@ import lombok.extern.slf4j.Slf4j;
public class StandardCategoryServiceImpl extends ServiceImpl<StandardCategoryMapper, StandardCategory>
implements StandardCategoryService{
@Override
public ResponseResult add(StandardCategoryDto standardCategoryDto) {
LambdaQueryWrapper<StandardCategory> queryWrapper = new LambdaQueryWrapper<StandardCategory>()
.eq(StandardCategory::getName, standardCategoryDto.getName())
.eq(StandardCategory::getParentId, standardCategoryDto.getParentId())
.eq(StandardCategory::getIsDeleted, 0);
if(this.count(queryWrapper) > 0){
return ResponseResult.error("该分类已存在");
}
StandardCategory standardCategory = new StandardCategory();
standardCategory.setName(standardCategoryDto.getName());
standardCategory.setParentId(standardCategoryDto.getParentId());
standardCategory.setCode(standardCategoryDto.getCode());
standardCategory.setSortOrder(standardCategoryDto.getSortOrder());
standardCategory.setRemark(standardCategoryDto.getRemark());
if(!this.save(standardCategory)){
return ResponseResult.error("添加失败");
}
return ResponseResult.success("添加成功");
}
}