修改项目以及材料模块相关逻辑
This commit is contained in:
@ -1,13 +1,14 @@
|
||||
package org.dromara.materials.domain;
|
||||
|
||||
import org.dromara.common.mybatis.core.domain.BaseEntity;
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableLogic;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import java.util.Date;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import org.dromara.common.mybatis.core.domain.BaseEntity;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 公司对象 bus_company
|
||||
@ -42,7 +43,7 @@ public class BusCompany extends BaseEntity {
|
||||
/**
|
||||
* 帐号状态(0正常 1停用)
|
||||
*/
|
||||
private String status;
|
||||
private Long status;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
|
@ -4,7 +4,9 @@ import org.dromara.common.mybatis.core.domain.BaseEntity;
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
|
||||
import java.io.Serial;
|
||||
@ -117,7 +119,7 @@ public class BusMaterials extends BaseEntity {
|
||||
/**
|
||||
* 状态(0正常 1停用)
|
||||
*/
|
||||
private String status;
|
||||
private Long status;
|
||||
|
||||
/**
|
||||
* 删除时间
|
||||
|
@ -4,7 +4,9 @@ import org.dromara.common.mybatis.core.domain.BaseEntity;
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
|
||||
import java.io.Serial;
|
||||
@ -42,7 +44,7 @@ public class BusMaterialsInventory extends BaseEntity {
|
||||
/**
|
||||
* 出入库状态
|
||||
*/
|
||||
private String outPut;
|
||||
private Long outPut;
|
||||
|
||||
/**
|
||||
* 出/入库的数量
|
||||
|
@ -6,7 +6,7 @@ import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author lilemy
|
||||
* @author lcj
|
||||
* @date 2025/3/5 14:05
|
||||
*/
|
||||
@Data
|
||||
|
@ -8,7 +8,7 @@ import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author lilemy
|
||||
* @author lcj
|
||||
* @date 2025/3/5 14:31
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ -36,7 +36,7 @@ public class CompanyQueryReq extends PageRequest implements Serializable {
|
||||
/**
|
||||
* 帐号状态(0正常 1停用)
|
||||
*/
|
||||
private String status;
|
||||
private Long status;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
|
@ -6,7 +6,7 @@ import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author lilemy
|
||||
* @author lcj
|
||||
* @date 2025/3/5 15:04
|
||||
*/
|
||||
@Data
|
||||
@ -33,7 +33,7 @@ public class CompanyUpdateReq implements Serializable {
|
||||
/**
|
||||
* 帐号状态(0正常 1停用)
|
||||
*/
|
||||
private String status;
|
||||
private Long status;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
|
@ -6,7 +6,7 @@ import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author lilemy
|
||||
* @author lcj
|
||||
* @date 2025/3/5 14:05
|
||||
*/
|
||||
@Data
|
||||
|
@ -8,7 +8,7 @@ import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author lilemy
|
||||
* @author lcj
|
||||
* @date 2025/3/5 14:31
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ -61,6 +61,6 @@ public class MaterialsQueryReq extends PageRequest implements Serializable {
|
||||
/**
|
||||
* 状态(0正常 1停用)
|
||||
*/
|
||||
private String status;
|
||||
private Long status;
|
||||
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author lilemy
|
||||
* @author lcj
|
||||
* @date 2025/3/5 15:04
|
||||
*/
|
||||
@Data
|
||||
@ -108,6 +108,6 @@ public class MaterialsUpdateReq implements Serializable {
|
||||
/**
|
||||
* 状态(0正常 1停用)
|
||||
*/
|
||||
private String status;
|
||||
private Long status;
|
||||
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @author lilemy
|
||||
* @author lcj
|
||||
* @date 2025/3/5 14:05
|
||||
*/
|
||||
@Data
|
||||
@ -29,7 +29,7 @@ public class MaterialsInventoryCreateReq implements Serializable {
|
||||
/**
|
||||
* 出入库状态
|
||||
*/
|
||||
private String outPut;
|
||||
private Long outPut;
|
||||
|
||||
/**
|
||||
* 出/入库的数量
|
||||
@ -46,6 +46,11 @@ public class MaterialsInventoryCreateReq implements Serializable {
|
||||
*/
|
||||
private Long residue;
|
||||
|
||||
/**
|
||||
* 操作人(入库人、领料人)
|
||||
*/
|
||||
private String operator;
|
||||
|
||||
/**
|
||||
* 材料出入证明
|
||||
*/
|
||||
|
@ -9,7 +9,7 @@ import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @author lilemy
|
||||
* @author lcj
|
||||
* @date 2025/3/5 14:31
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ -37,7 +37,7 @@ public class MaterialsInventoryQueryReq extends PageRequest implements Serializa
|
||||
/**
|
||||
* 出入库状态
|
||||
*/
|
||||
private String outPut;
|
||||
private Long outPut;
|
||||
|
||||
/**
|
||||
* 出/入库的数量
|
||||
|
@ -7,7 +7,7 @@ import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @author lilemy
|
||||
* @author lcj
|
||||
* @date 2025/3/5 15:04
|
||||
*/
|
||||
@Data
|
||||
@ -34,7 +34,7 @@ public class MaterialsInventoryUpdateReq implements Serializable {
|
||||
/**
|
||||
* 出入库状态
|
||||
*/
|
||||
private String outPut;
|
||||
private Long outPut;
|
||||
|
||||
/**
|
||||
* 出/入库的数量
|
||||
|
@ -53,7 +53,7 @@ public class BusCompanyVo implements Serializable {
|
||||
*/
|
||||
@ExcelProperty(value = "帐号状态", converter = ExcelDictConvert.class)
|
||||
@ExcelDictFormat(readConverterExp = "0=正常,1=停用")
|
||||
private String status;
|
||||
private Long status;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
|
@ -1,6 +1,7 @@
|
||||
package org.dromara.materials.domain.vo;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import org.dromara.materials.domain.BusMaterialsInventory;
|
||||
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
|
||||
@ -15,7 +16,6 @@ import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 材料出/入库视图对象 bus_materials_inventory
|
||||
*
|
||||
@ -42,6 +42,12 @@ public class BusMaterialsInventoryVo implements Serializable {
|
||||
@ExcelProperty(value = "材料id")
|
||||
private Long materialsId;
|
||||
|
||||
/**
|
||||
* 材料信息
|
||||
*/
|
||||
@ExcelProperty(value = "材料信息")
|
||||
private BusMaterialsVo materialsVo;
|
||||
|
||||
/**
|
||||
* 项目id
|
||||
*/
|
||||
@ -52,7 +58,7 @@ public class BusMaterialsInventoryVo implements Serializable {
|
||||
* 出入库状态
|
||||
*/
|
||||
@ExcelProperty(value = "出入库状态")
|
||||
private String outPut;
|
||||
private Long outPut;
|
||||
|
||||
/**
|
||||
* 出/入库的数量
|
||||
|
@ -145,7 +145,7 @@ public class BusMaterialsVo implements Serializable {
|
||||
*/
|
||||
@ExcelProperty(value = "状态", converter = ExcelDictConvert.class)
|
||||
@ExcelDictFormat(readConverterExp = "0=正常,1=停用")
|
||||
private String status;
|
||||
private Long status;
|
||||
|
||||
|
||||
}
|
||||
|
@ -69,6 +69,14 @@ public interface IBusMaterialsInventoryService extends IService<BusMaterialsInve
|
||||
*/
|
||||
Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid);
|
||||
|
||||
/**
|
||||
* 获取材料出/入库视图对象
|
||||
*
|
||||
* @param MaterialsInventory 材料出/入库对象
|
||||
* @return 材料出/入库视图对象
|
||||
*/
|
||||
BusMaterialsInventoryVo getMaterialsInventoryVo(BusMaterialsInventory MaterialsInventory);
|
||||
|
||||
/**
|
||||
* 构建查询条件封装
|
||||
*
|
||||
|
@ -2,6 +2,7 @@ package org.dromara.materials.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
@ -19,6 +20,7 @@ import org.dromara.materials.domain.req.company.CompanyUpdateReq;
|
||||
import org.dromara.materials.domain.vo.BusCompanyVo;
|
||||
import org.dromara.materials.mapper.BusCompanyMapper;
|
||||
import org.dromara.materials.service.IBusCompanyService;
|
||||
import org.dromara.project.service.IProjectService;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@ -38,6 +40,9 @@ public class BusCompanyServiceImpl extends ServiceImpl<BusCompanyMapper, BusComp
|
||||
@Resource
|
||||
private BusCompanyMapper baseMapper;
|
||||
|
||||
@Resource
|
||||
private IProjectService projectService;
|
||||
|
||||
/**
|
||||
* 查询公司
|
||||
*
|
||||
@ -129,9 +134,20 @@ public class BusCompanyServiceImpl extends ServiceImpl<BusCompanyMapper, BusComp
|
||||
if (StringUtils.isBlank(companyName)) {
|
||||
throw new ServiceException("公司名称不能为空", HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
// 公司名不能重复
|
||||
LambdaQueryWrapper<BusCompany> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(BusCompany::getCompanyName, companyName);
|
||||
long count = this.count(queryWrapper);
|
||||
if (count > 0) {
|
||||
throw new ServiceException("项目名重复", HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
if (projectId == null) {
|
||||
throw new ServiceException("项目 id 不能为空", HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
// 查询项目是否存在
|
||||
if (projectService.getById(projectId) == null) {
|
||||
throw new ServiceException("对应项目不存在", HttpStatus.NOT_FOUND);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -165,7 +181,7 @@ public class BusCompanyServiceImpl extends ServiceImpl<BusCompanyMapper, BusComp
|
||||
Long id = req.getId();
|
||||
String companyName = req.getCompanyName();
|
||||
Long projectId = req.getProjectId();
|
||||
String status = req.getStatus();
|
||||
Long status = req.getStatus();
|
||||
String remark = req.getRemark();
|
||||
String qualification = req.getQualification();
|
||||
String sortField = req.getSortField();
|
||||
|
@ -19,6 +19,8 @@ import org.dromara.materials.domain.req.materialsinventory.MaterialsInventoryUpd
|
||||
import org.dromara.materials.domain.vo.BusMaterialsInventoryVo;
|
||||
import org.dromara.materials.mapper.BusMaterialsInventoryMapper;
|
||||
import org.dromara.materials.service.IBusMaterialsInventoryService;
|
||||
import org.dromara.materials.service.IBusMaterialsService;
|
||||
import org.dromara.project.service.IProjectService;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@ -39,6 +41,12 @@ public class BusMaterialsInventoryServiceImpl extends ServiceImpl<BusMaterialsIn
|
||||
@Resource
|
||||
private BusMaterialsInventoryMapper baseMapper;
|
||||
|
||||
@Resource
|
||||
private IBusMaterialsService materialsService;
|
||||
|
||||
@Resource
|
||||
private IProjectService projectService;
|
||||
|
||||
/**
|
||||
* 查询材料出/入库
|
||||
*
|
||||
@ -47,7 +55,11 @@ public class BusMaterialsInventoryServiceImpl extends ServiceImpl<BusMaterialsIn
|
||||
*/
|
||||
@Override
|
||||
public BusMaterialsInventoryVo queryById(Long id) {
|
||||
return baseMapper.selectVoById(id);
|
||||
BusMaterialsInventory materialsInventory = this.getById(id);
|
||||
if (materialsInventory == null) {
|
||||
throw new ServiceException("材料出/入库信息不存在", HttpStatus.NOT_FOUND);
|
||||
}
|
||||
return this.getMaterialsInventoryVo(materialsInventory);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -74,7 +86,8 @@ public class BusMaterialsInventoryServiceImpl extends ServiceImpl<BusMaterialsIn
|
||||
@Override
|
||||
public List<BusMaterialsInventoryVo> queryList(MaterialsInventoryQueryReq req) {
|
||||
QueryWrapper<BusMaterialsInventory> queryWrapper = this.getQueryWrapper(req);
|
||||
return baseMapper.selectVoList(queryWrapper);
|
||||
List<BusMaterialsInventory> list = this.list(queryWrapper);
|
||||
return list.stream().map(this::getMaterialsInventoryVo).toList();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -124,7 +137,25 @@ public class BusMaterialsInventoryServiceImpl extends ServiceImpl<BusMaterialsIn
|
||||
* 保存前的数据校验
|
||||
*/
|
||||
private void validEntityBeforeSave(BusMaterialsInventory entity) {
|
||||
//TODO 做一些数据校验,如唯一约束
|
||||
// TODO 做一些数据校验,如唯一约束
|
||||
Long materialsId = entity.getMaterialsId();
|
||||
Long projectId = entity.getProjectId();
|
||||
Long outPut = entity.getOutPut();
|
||||
if (materialsId == null) {
|
||||
throw new ServiceException("材料信息 id 不能为空", HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
if (materialsService.getById(materialsId) == null) {
|
||||
throw new ServiceException("对应材料信息不存在", HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
if (projectId == null) {
|
||||
throw new ServiceException("项目 id 不能为空", HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
if (projectService.getById(projectId) == null) {
|
||||
throw new ServiceException("对应项目不存在", HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
if (outPut == null) {
|
||||
throw new ServiceException("出入库状态不能为空", HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -142,6 +173,28 @@ public class BusMaterialsInventoryServiceImpl extends ServiceImpl<BusMaterialsIn
|
||||
return baseMapper.deleteByIds(ids) > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取材料出/入库视图对象
|
||||
*
|
||||
* @param MaterialsInventory 材料出/入库对象
|
||||
* @return 材料出/入库视图对象
|
||||
*/
|
||||
@Override
|
||||
public BusMaterialsInventoryVo getMaterialsInventoryVo(BusMaterialsInventory MaterialsInventory) {
|
||||
// 对象转封装类
|
||||
BusMaterialsInventoryVo materialsInventoryVo = new BusMaterialsInventoryVo();
|
||||
if (MaterialsInventory == null) {
|
||||
return materialsInventoryVo;
|
||||
}
|
||||
BeanUtils.copyProperties(MaterialsInventory, materialsInventoryVo);
|
||||
// 关联查询项目信息
|
||||
Long materialsId = MaterialsInventory.getMaterialsId();
|
||||
if (materialsId != null) {
|
||||
materialsInventoryVo.setMaterialsVo(materialsService.queryById(materialsId));
|
||||
}
|
||||
return materialsInventoryVo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建查询条件封装
|
||||
*
|
||||
@ -158,7 +211,7 @@ public class BusMaterialsInventoryServiceImpl extends ServiceImpl<BusMaterialsIn
|
||||
Long id = req.getId();
|
||||
Long materialsId = req.getMaterialsId();
|
||||
Long projectId = req.getProjectId();
|
||||
String outPut = req.getOutPut();
|
||||
Long outPut = req.getOutPut();
|
||||
Long number = req.getNumber();
|
||||
Date outPutTime = req.getOutPutTime();
|
||||
Long residue = req.getResidue();
|
||||
@ -171,7 +224,6 @@ public class BusMaterialsInventoryServiceImpl extends ServiceImpl<BusMaterialsIn
|
||||
String sortOrder = req.getSortOrder();
|
||||
String underlineSortField = StrUtil.toUnderlineCase(sortField);
|
||||
// 模糊查询
|
||||
queryWrapper.like(StringUtils.isNotBlank(outPut), "out_put", outPut);
|
||||
queryWrapper.like(StringUtils.isNotBlank(operator), "operator", operator);
|
||||
queryWrapper.like(StringUtils.isNotBlank(remark), "remark", remark);
|
||||
queryWrapper.like(StringUtils.isNotBlank(disposition), "disposition", disposition);
|
||||
@ -184,6 +236,7 @@ public class BusMaterialsInventoryServiceImpl extends ServiceImpl<BusMaterialsIn
|
||||
queryWrapper.eq(ObjectUtils.isNotEmpty(number), "number", number);
|
||||
queryWrapper.eq(ObjectUtils.isNotEmpty(outPutTime), "out_put_time", outPutTime);
|
||||
queryWrapper.eq(ObjectUtils.isNotEmpty(residue), "residue", residue);
|
||||
queryWrapper.eq(ObjectUtils.isNotEmpty(outPut), "out_put", outPut);
|
||||
// 排序规则
|
||||
queryWrapper.orderBy(SqlUtil.validSortField(sortField),
|
||||
sortOrder.equals(CommonConstant.SORT_ORDER_ASC),
|
||||
@ -208,11 +261,7 @@ public class BusMaterialsInventoryServiceImpl extends ServiceImpl<BusMaterialsIn
|
||||
return materialsInventoryVoPage;
|
||||
}
|
||||
// 对象列表 => 封装对象列表
|
||||
List<BusMaterialsInventoryVo> materialsInventoryVoList = materialsInventoryList.stream().map(materialsInventory -> {
|
||||
BusMaterialsInventoryVo materialsInventoryVo = new BusMaterialsInventoryVo();
|
||||
BeanUtils.copyProperties(materialsInventory, materialsInventoryVo);
|
||||
return materialsInventoryVo;
|
||||
}).toList();
|
||||
List<BusMaterialsInventoryVo> materialsInventoryVoList = materialsInventoryList.stream().map(this::getMaterialsInventoryVo).toList();
|
||||
materialsInventoryVoPage.setRecords(materialsInventoryVoList);
|
||||
return materialsInventoryVoPage;
|
||||
}
|
||||
|
@ -21,6 +21,7 @@ import org.dromara.materials.domain.vo.BusMaterialsVo;
|
||||
import org.dromara.materials.mapper.BusMaterialsMapper;
|
||||
import org.dromara.materials.service.IBusCompanyService;
|
||||
import org.dromara.materials.service.IBusMaterialsService;
|
||||
import org.dromara.project.service.IProjectService;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@ -44,6 +45,9 @@ public class BusMaterialsServiceImpl extends ServiceImpl<BusMaterialsMapper, Bus
|
||||
@Resource
|
||||
private IBusCompanyService companyService;
|
||||
|
||||
@Resource
|
||||
private IProjectService projectService;
|
||||
|
||||
/**
|
||||
* 查询材料名称
|
||||
*
|
||||
@ -140,9 +144,15 @@ public class BusMaterialsServiceImpl extends ServiceImpl<BusMaterialsMapper, Bus
|
||||
if (companyId == null) {
|
||||
throw new ServiceException("请填写公司ID", HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
if (companyService.getById(companyId) == null) {
|
||||
throw new ServiceException("对应公司不存在", HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
if (projectId == null) {
|
||||
throw new ServiceException("请填写项目ID", HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
if (projectService.getById(projectId) == null) {
|
||||
throw new ServiceException("对应项目不存在", HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -203,7 +213,7 @@ public class BusMaterialsServiceImpl extends ServiceImpl<BusMaterialsMapper, Bus
|
||||
String weightId = req.getWeightId();
|
||||
String remark = req.getRemark();
|
||||
String quantityCount = req.getQuantityCount();
|
||||
String status = req.getStatus();
|
||||
Long status = req.getStatus();
|
||||
String sortField = req.getSortField();
|
||||
String sortOrder = req.getSortOrder();
|
||||
String underlineSortField = StrUtil.toUnderlineCase(sortField);
|
||||
|
@ -6,7 +6,7 @@ import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author lilemy
|
||||
* @author lcj
|
||||
* @date 2025/3/5 17:16
|
||||
*/
|
||||
@Data
|
||||
|
@ -6,7 +6,7 @@ import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author lilemy
|
||||
* @author lcj
|
||||
* @date 2025/3/5 14:05
|
||||
*/
|
||||
@Data
|
||||
|
@ -8,7 +8,7 @@ import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author lilemy
|
||||
* @author lcj
|
||||
* @date 2025/3/5 14:31
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
|
@ -6,7 +6,7 @@ import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author lilemy
|
||||
* @author lcj
|
||||
* @date 2025/3/5 15:04
|
||||
*/
|
||||
@Data
|
||||
|
@ -6,7 +6,7 @@ import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author lilemy
|
||||
* @author lcj
|
||||
* @date 2025/3/5 14:05
|
||||
*/
|
||||
@Data
|
||||
|
@ -8,7 +8,7 @@ import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author lilemy
|
||||
* @author lcj
|
||||
* @date 2025/3/5 14:31
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
|
@ -6,7 +6,7 @@ import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author lilemy
|
||||
* @author lcj
|
||||
* @date 2025/3/5 15:04
|
||||
*/
|
||||
@Data
|
||||
|
@ -6,7 +6,7 @@ import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author lilemy
|
||||
* @author lcj
|
||||
* @date 2025/3/5 15:30
|
||||
*/
|
||||
@Data
|
||||
|
@ -36,14 +36,6 @@ public interface IProjectService extends IService<Project> {
|
||||
*/
|
||||
ProjectVo getProjectVo(Project project);
|
||||
|
||||
/**
|
||||
* 获取项目查询条件封装
|
||||
*
|
||||
* @param req 查询条件
|
||||
* @return 查询条件封装
|
||||
*/
|
||||
QueryWrapper<Project> getQueryWrapper(ProjectQueryReq req);
|
||||
|
||||
/**
|
||||
* 分页查询项目列表
|
||||
*
|
||||
@ -60,14 +52,6 @@ public interface IProjectService extends IService<Project> {
|
||||
*/
|
||||
List<ProjectVo> queryList(ProjectQueryReq req);
|
||||
|
||||
/**
|
||||
* 获取项目分页对象视图
|
||||
*
|
||||
* @param projectPage 项目分页对象
|
||||
* @return 项目分页对象视图
|
||||
*/
|
||||
Page<ProjectVo> getProjectVoPage(Page<Project> projectPage);
|
||||
|
||||
/**
|
||||
* 新增项目
|
||||
*
|
||||
@ -92,4 +76,21 @@ public interface IProjectService extends IService<Project> {
|
||||
* @return 是否删除成功
|
||||
*/
|
||||
Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid);
|
||||
|
||||
/**
|
||||
* 获取项目查询条件封装
|
||||
*
|
||||
* @param req 查询条件
|
||||
* @return 查询条件封装
|
||||
*/
|
||||
QueryWrapper<Project> getQueryWrapper(ProjectQueryReq req);
|
||||
|
||||
/**
|
||||
* 获取项目分页对象视图
|
||||
*
|
||||
* @param projectPage 项目分页对象
|
||||
* @return 项目分页对象视图
|
||||
*/
|
||||
Page<ProjectVo> getProjectVoPage(Page<Project> projectPage);
|
||||
|
||||
}
|
||||
|
@ -68,6 +68,132 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project>
|
||||
return projectVo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询项目列表
|
||||
*
|
||||
* @param req 查询条件
|
||||
* @return 项目分页列表
|
||||
*/
|
||||
@Override
|
||||
public Page<ProjectVo> queryPageList(ProjectQueryReq req) {
|
||||
long current = req.getCurrent();
|
||||
long size = req.getPageSize();
|
||||
// 查询数据库
|
||||
Page<Project> result = this.page(new Page<>(current, size), this.getQueryWrapper(req));
|
||||
return this.getProjectVoPage(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询符合条件的项目列表
|
||||
*
|
||||
* @param req 查询条件
|
||||
* @return 项目列表
|
||||
*/
|
||||
@Override
|
||||
public List<ProjectVo> queryList(ProjectQueryReq req) {
|
||||
QueryWrapper<Project> queryWrapper = this.getQueryWrapper(req);
|
||||
return baseMapper.selectVoList(queryWrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增项目
|
||||
*
|
||||
* @param dto 项目
|
||||
* @return 新项目 id
|
||||
*/
|
||||
@Override
|
||||
public Long insertByBo(ProjectCreateReq dto) {
|
||||
// 将实体类和 DTO 进行转换
|
||||
Project project = new Project();
|
||||
BeanUtils.copyProperties(dto, project);
|
||||
// 数据校验
|
||||
validEntityBeforeSave(project);
|
||||
// 写入数据库
|
||||
boolean save = this.save(project);
|
||||
if (!save) {
|
||||
throw new ServiceException("新增项目失败,数据库异常", HttpStatus.ERROR);
|
||||
}
|
||||
Long projectId = project.getId();
|
||||
Long userId = LoginHelper.getUserId();
|
||||
// 同步保存用户与项目关联
|
||||
UserProjectRelevancy userProjectRelevancy = new UserProjectRelevancy();
|
||||
userProjectRelevancy.setUserId(userId);
|
||||
userProjectRelevancy.setProjectId(projectId);
|
||||
boolean saveRelevancy = userProjectRelevancyService.save(userProjectRelevancy);
|
||||
if (!saveRelevancy) {
|
||||
throw new ServiceException("新增用户与项目关联失败,数据库异常", HttpStatus.ERROR);
|
||||
}
|
||||
// 返回新写入的数据 projectId
|
||||
return projectId;
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改项目
|
||||
*
|
||||
* @param req 项目
|
||||
* @return 是否修改成功
|
||||
*/
|
||||
@Override
|
||||
public Boolean updateByBo(ProjectUpdateReq req) {
|
||||
// 将实体类和 DTO 进行转换
|
||||
Project project = new Project();
|
||||
BeanUtils.copyProperties(req, project);
|
||||
// 数据校验
|
||||
validEntityBeforeSave(project);
|
||||
// 权限校验
|
||||
validPermission(project);
|
||||
// 判断是否存在
|
||||
Project oldProject = this.getById(project.getId());
|
||||
if (oldProject == null) {
|
||||
throw new ServiceException("修改项目失败,数据不存在", HttpStatus.NOT_FOUND);
|
||||
}
|
||||
// 操作数据库
|
||||
return this.updateById(project);
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存前的数据校验
|
||||
*/
|
||||
private void validEntityBeforeSave(Project entity) {
|
||||
// TODO 做一些数据校验,如唯一约束
|
||||
String projectName = entity.getProjectName();
|
||||
if (StringUtils.isBlank(projectName)) {
|
||||
throw new ServiceException("项目名称不能为空", HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 权限判断
|
||||
*/
|
||||
private void validPermission(Project entity) {
|
||||
Long entityId = entity.getId();
|
||||
// 获取当前登录用户
|
||||
Long userId = LoginHelper.getUserId();
|
||||
// 判断是否存在项目与登录用户关联
|
||||
QueryWrapper<UserProjectRelevancy> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("project_id", entityId);
|
||||
queryWrapper.eq("user_id", userId);
|
||||
if (userProjectRelevancyService.count(queryWrapper) <= 0) {
|
||||
throw new ServiceException("当前用户无权限操作", HttpStatus.FORBIDDEN);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验并批量删除项目信息
|
||||
*
|
||||
* @param ids 待删除的主键集合
|
||||
* @param isValid 是否进行有效性校验
|
||||
* @return 是否删除成功
|
||||
*/
|
||||
@Override
|
||||
public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
|
||||
if (isValid) {
|
||||
//TODO 做一些业务上的校验,判断是否需要校验
|
||||
|
||||
}
|
||||
return baseMapper.deleteByIds(ids) > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取项目查询条件封装
|
||||
*
|
||||
@ -127,32 +253,6 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project>
|
||||
return queryWrapper;
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询项目列表
|
||||
*
|
||||
* @param req 查询条件
|
||||
* @return 项目分页列表
|
||||
*/
|
||||
@Override
|
||||
public Page<ProjectVo> queryPageList(ProjectQueryReq req) {
|
||||
long current = req.getCurrent();
|
||||
long size = req.getPageSize();
|
||||
// 查询数据库
|
||||
Page<Project> result = this.page(new Page<>(current, size), this.getQueryWrapper(req));
|
||||
return this.getProjectVoPage(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询符合条件的项目列表
|
||||
*
|
||||
* @param req 查询条件
|
||||
* @return 项目列表
|
||||
*/
|
||||
@Override
|
||||
public List<ProjectVo> queryList(ProjectQueryReq req) {
|
||||
QueryWrapper<Project> queryWrapper = this.getQueryWrapper(req);
|
||||
return baseMapper.selectVoList(queryWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<ProjectVo> getProjectVoPage(Page<Project> projectPage) {
|
||||
@ -167,80 +267,4 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project>
|
||||
return projectVoPage;
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增项目
|
||||
*
|
||||
* @param dto 项目
|
||||
* @return 新项目 id
|
||||
*/
|
||||
@Override
|
||||
public Long insertByBo(ProjectCreateReq dto) {
|
||||
// 将实体类和 DTO 进行转换
|
||||
Project project = new Project();
|
||||
BeanUtils.copyProperties(dto, project);
|
||||
// 数据校验
|
||||
validEntityBeforeSave(project);
|
||||
// 写入数据库
|
||||
boolean save = this.save(project);
|
||||
if (!save) {
|
||||
throw new ServiceException("新增项目失败,数据库异常", HttpStatus.ERROR);
|
||||
}
|
||||
Long projectId = project.getId();
|
||||
Long userId = LoginHelper.getUserId();
|
||||
// 同步保存用户与项目关联
|
||||
UserProjectRelevancy userProjectRelevancy = new UserProjectRelevancy();
|
||||
userProjectRelevancy.setUserId(userId);
|
||||
userProjectRelevancy.setProjectId(projectId);
|
||||
boolean saveRelevancy = userProjectRelevancyService.save(userProjectRelevancy);
|
||||
if (!saveRelevancy) {
|
||||
throw new ServiceException("新增用户与项目关联失败,数据库异常", HttpStatus.ERROR);
|
||||
}
|
||||
// 返回新写入的数据 projectId
|
||||
return projectId;
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改项目
|
||||
*
|
||||
* @param req 项目
|
||||
* @return 是否修改成功
|
||||
*/
|
||||
@Override
|
||||
public Boolean updateByBo(ProjectUpdateReq req) {
|
||||
// 将实体类和 DTO 进行转换
|
||||
Project project = new Project();
|
||||
BeanUtils.copyProperties(req, project);
|
||||
// 数据校验
|
||||
validEntityBeforeSave(project);
|
||||
// 判断是否存在
|
||||
Project oldProject = this.getById(project.getId());
|
||||
if (oldProject == null) {
|
||||
throw new ServiceException("修改项目失败,数据不存在", HttpStatus.NOT_FOUND);
|
||||
}
|
||||
// 操作数据库
|
||||
return this.updateById(project);
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存前的数据校验
|
||||
*/
|
||||
private void validEntityBeforeSave(Project entity) {
|
||||
//TODO 做一些数据校验,如唯一约束
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验并批量删除项目信息
|
||||
*
|
||||
* @param ids 待删除的主键集合
|
||||
* @param isValid 是否进行有效性校验
|
||||
* @return 是否删除成功
|
||||
*/
|
||||
@Override
|
||||
public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
|
||||
if (isValid) {
|
||||
//TODO 做一些业务上的校验,判断是否需要校验
|
||||
|
||||
}
|
||||
return baseMapper.deleteByIds(ids) > 0;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user