From a0645f08a583e75b556c4f00c5a481f1d326a3b7 Mon Sep 17 00:00:00 2001 From: liwen Date: Thu, 30 May 2024 13:53:09 +0800 Subject: [PATCH] =?UTF-8?q?add:=20=E8=BD=A6=E6=A3=80=E8=AE=B0=E5=BD=95?= =?UTF-8?q?=E6=A8=A1=E6=9D=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hzims/safeproduct/dto/CarCheckTemplateDTO.java | 25 ++++ .../entity/CarCheckTemplateDetailEntity.java | 39 +++++ .../safeproduct/entity/CarCheckTemplateEntity.java | 26 ++++ .../safeproduct/vo/CarCheckTemplateDetailVO.java | 25 ++++ .../feedback/mapper/UserFeedbackMapper.xml | 13 ++ .../safeproduct/controller/CarController.java | 69 +++++---- .../mapper/CarCheckTemplateDetailMapper.java | 15 ++ .../mapper/CarCheckTemplateDetailMapper.xml | 5 + .../safeproduct/mapper/CarCheckTemplateMapper.java | 20 +++ .../service/ICarCheckTemplateService.java | 61 ++++++++ .../service/impl/CarCheckRecordServiceImpl.java | 67 +++++---- .../impl/CarCheckTemplateDetailServiceImpl.java | 37 +++++ .../service/impl/CarCheckTemplateServiceImpl.java | 161 +++++++++++++++++++++ .../impl/ICarCheckTemplateDetailService.java | 28 ++++ .../safeproduct/src/main/resources/db/2.0.1.sql | 32 +++- 15 files changed, 572 insertions(+), 51 deletions(-) create mode 100644 hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/dto/CarCheckTemplateDTO.java create mode 100644 hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/entity/CarCheckTemplateDetailEntity.java create mode 100644 hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/entity/CarCheckTemplateEntity.java create mode 100644 hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/vo/CarCheckTemplateDetailVO.java create mode 100644 hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/mapper/CarCheckTemplateDetailMapper.java create mode 100644 hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/mapper/CarCheckTemplateDetailMapper.xml create mode 100644 hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/mapper/CarCheckTemplateMapper.java create mode 100644 hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/ICarCheckTemplateService.java create mode 100644 hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/CarCheckTemplateDetailServiceImpl.java create mode 100644 hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/CarCheckTemplateServiceImpl.java create mode 100644 hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/ICarCheckTemplateDetailService.java diff --git a/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/dto/CarCheckTemplateDTO.java b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/dto/CarCheckTemplateDTO.java new file mode 100644 index 0000000..6e3dbff --- /dev/null +++ b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/dto/CarCheckTemplateDTO.java @@ -0,0 +1,25 @@ +package com.hnac.hzims.safeproduct.dto; + +import com.hnac.hzims.safeproduct.entity.CarCheckTemplateDetailEntity; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.util.List; + +/** + * @date 2024-05-30 + */ +@Data +@ApiModel(value = "车检记录模板DTO类") +public class CarCheckTemplateDTO { + + @ApiModelProperty("模板id") + private Long id; + + @ApiModelProperty("模板名称") + private String templateName; + + @ApiModelProperty("模板详情列表") + private List detailList; +} diff --git a/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/entity/CarCheckTemplateDetailEntity.java b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/entity/CarCheckTemplateDetailEntity.java new file mode 100644 index 0000000..97c666c --- /dev/null +++ b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/entity/CarCheckTemplateDetailEntity.java @@ -0,0 +1,39 @@ +package com.hnac.hzims.safeproduct.entity; + +import com.baomidou.mybatisplus.annotation.TableName; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import org.springblade.core.mp.base.BaseEntity; + +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; + +/** + * 车检模板详情服务类 + * + * @date 2024-05-30 + */ +@Data +@EqualsAndHashCode(callSuper = true) +@TableName("hzims_car_check_template_detail") +@ApiModel(value = "车检模板详情实体类") +public class CarCheckTemplateDetailEntity extends BaseEntity { + + @ApiModelProperty("车检记录id") + private Long templateId; + + @NotNull + @Size(max = 500, message = "检查项目长度不能超过50") + @ApiModelProperty("检查项目") + private String checkItem; + + @NotNull + @ApiModelProperty("检查内容") + private String checkContent; + + @NotNull + @ApiModelProperty("检查结果") + private String checkResult; +} diff --git a/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/entity/CarCheckTemplateEntity.java b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/entity/CarCheckTemplateEntity.java new file mode 100644 index 0000000..f761d43 --- /dev/null +++ b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/entity/CarCheckTemplateEntity.java @@ -0,0 +1,26 @@ +package com.hnac.hzims.safeproduct.entity; + +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableName; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import org.springblade.core.mp.base.BaseEntity; + +/** + * @date 2024-05-28 + */ +@Data +@EqualsAndHashCode(callSuper = true) +@TableName("hzims_car_check_template") +@ApiModel(value = "车检模板实体类") +public class CarCheckTemplateEntity extends BaseEntity { + + @ApiModelProperty("模板名称") + private String templateName; + + @TableField(exist = false) + @ApiModelProperty("创建机构名称") + private String createDeptName; +} diff --git a/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/vo/CarCheckTemplateDetailVO.java b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/vo/CarCheckTemplateDetailVO.java new file mode 100644 index 0000000..ef217f4 --- /dev/null +++ b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/vo/CarCheckTemplateDetailVO.java @@ -0,0 +1,25 @@ +package com.hnac.hzims.safeproduct.vo; + +import com.hnac.hzims.safeproduct.entity.CarCheckTemplateDetailEntity; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.util.List; + +/** + * @date 2024-05-30 + */ +@Data +@ApiModel(value = "车检模板详情VO类") +public class CarCheckTemplateDetailVO { + + @ApiModelProperty("模板id") + private Long id; + + @ApiModelProperty("模板名称") + private String templateName; + + @ApiModelProperty("模板详情列表") + private List templateDetailList; +} diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/feedback/mapper/UserFeedbackMapper.xml b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/feedback/mapper/UserFeedbackMapper.xml index 31cee66..418022c 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/feedback/mapper/UserFeedbackMapper.xml +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/feedback/mapper/UserFeedbackMapper.xml @@ -2,4 +2,17 @@ + \ No newline at end of file diff --git a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/controller/CarController.java b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/controller/CarController.java index 2f1c8c8..d88ca90 100644 --- a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/controller/CarController.java +++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/controller/CarController.java @@ -5,6 +5,7 @@ import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; import com.hnac.hzims.common.utils.Condition; import com.hnac.hzims.safeproduct.Constants; import com.hnac.hzims.safeproduct.dto.CarCheckRecordDTO; +import com.hnac.hzims.safeproduct.dto.CarCheckTemplateDTO; import com.hnac.hzims.safeproduct.dto.CarMaintenanceConfirmationDTO; import com.hnac.hzims.safeproduct.dto.CarUsedRecordConfirmationDTO; import com.hnac.hzims.safeproduct.entity.*; @@ -54,6 +55,8 @@ public class CarController extends BladeController { private final ICarInsuranceService carInsuranceService; + private final ICarCheckTemplateService carCheckTemplateService; + @PostMapping("/saveCar") @ApiOperation(value = "新增车辆") @ApiOperationSupport(order = 1) @@ -269,31 +272,47 @@ public class CarController extends BladeController { return R.data(page); } -// @ApiOperation(value = "新增车检记录模板") -// @ApiOperationSupport(order = 39) -// public R saveCarCheckRecordTemplate() { -// -// } -// -// @ApiOperationSupport(order = 40) -// public R updateCarCheckRecordTemplate() { -// -// } -// -// @ApiOperationSupport(order = 41) -// public R removeCarCheckRecordTemplate() { -// -// } -// -// @ApiOperationSupport(order = 42) -// public R carCheckRecordTemplateDetail() { -// -// } -// -// @ApiOperationSupport(order = 43) -// public R carCheckRecordTemplatePage() { -// -// } + @PostMapping("/saveCarCheckTemplate") + @ApiOperation(value = "新增车检模板") + @ApiOperationSupport(order = 39) + @Operate(label = "新增车检模板", type = BusinessType.INSERT, ignore = false) + public R saveCarCheckTemplate(@RequestBody CarCheckTemplateDTO dto) { + return R.status(carCheckTemplateService.saveCarCheckTemplate(dto)); + } + + @PostMapping("/updateCarCheckTemplate") + @ApiOperation(value = "修改车检模板") + @ApiOperationSupport(order = 40) + @Operate(label = "修改车检模板", type = BusinessType.UPDATE, ignore = false) + public R updateCarCheckTemplate(@RequestBody CarCheckTemplateDTO dto) { + return R.status(carCheckTemplateService.updateCarCheckTemplate(dto)); + } + + @GetMapping("/removeCarCheckTemplate") + @ApiOperation(value = "删除车检模板") + @ApiOperationSupport(order = 41) + @Operate(label = "删除车检模板", type = BusinessType.DELETE, ignore = false) + public R removeCarCheckTemplate(@RequestParam Long id) { + return R.status(carCheckTemplateService.removeCarCheckTemplate(id)); + } + + @GetMapping("/carCheckTemplateDetail") + @ApiOperation(value = "车检模板详情") + @ApiOperationSupport(order = 42) + @Operate(label = "车检模板详情", type = BusinessType.QUERY, ignore = false) + public R carCheckTemplateDetail(@RequestParam Long id) { + CarCheckTemplateDetailVO vo = carCheckTemplateService.getCarCheckTemplateDetail(id); + return R.data(vo); + } + + @GetMapping("/carCheckTemplatePage") + @ApiOperation(value = "车检模板分页") + @ApiOperationSupport(order = 43) + @Operate(label = "车检模板分页", type = BusinessType.QUERY, ignore = false) + public R> carCheckTemplatePage(@ApiIgnore @RequestParam Map param, Query query) { + IPage page = carCheckTemplateService.getCarCheckTemplatePage(query, param); + return R.data(page); + } @GetMapping("/exportCarMaintenanceData") @ApiOperation(value = "导出车辆维保记录单") diff --git a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/mapper/CarCheckTemplateDetailMapper.java b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/mapper/CarCheckTemplateDetailMapper.java new file mode 100644 index 0000000..5c01a05 --- /dev/null +++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/mapper/CarCheckTemplateDetailMapper.java @@ -0,0 +1,15 @@ +package com.hnac.hzims.safeproduct.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.hnac.hzims.safeproduct.entity.CarCheckTemplateDetailEntity; +import org.apache.ibatis.annotations.Mapper; + +/** + * 车检模板详情Mapper类 + * + * @date 2024-05-30 + */ +@Mapper +public interface CarCheckTemplateDetailMapper extends BaseMapper { + +} diff --git a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/mapper/CarCheckTemplateDetailMapper.xml b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/mapper/CarCheckTemplateDetailMapper.xml new file mode 100644 index 0000000..1c367c4 --- /dev/null +++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/mapper/CarCheckTemplateDetailMapper.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/mapper/CarCheckTemplateMapper.java b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/mapper/CarCheckTemplateMapper.java new file mode 100644 index 0000000..ccf72f9 --- /dev/null +++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/mapper/CarCheckTemplateMapper.java @@ -0,0 +1,20 @@ +package com.hnac.hzims.safeproduct.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.hnac.hzims.safeproduct.entity.CarCheckTemplateEntity; +import org.apache.ibatis.annotations.Mapper; + +import java.util.Map; + +@Mapper +public interface CarCheckTemplateMapper extends BaseMapper { + + /** + * 车检分页 + * @param page 分页类 + * @param param 参数 + * @return 分页 + */ + IPage getCarCheckTemplatePage(IPage page, Map param); +} diff --git a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/ICarCheckTemplateService.java b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/ICarCheckTemplateService.java new file mode 100644 index 0000000..58dc07e --- /dev/null +++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/ICarCheckTemplateService.java @@ -0,0 +1,61 @@ +package com.hnac.hzims.safeproduct.service; + +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.service.IService; +import com.hnac.hzims.safeproduct.dto.CarCheckTemplateDTO; +import com.hnac.hzims.safeproduct.entity.CarCheckTemplateEntity; +import com.hnac.hzims.safeproduct.vo.CarCheckTemplateDetailVO; +import org.springblade.core.mp.support.Query; + +import java.util.Map; + +/** + * 车检模板服务类 + * + * @date 2024-05-28 + */ +public interface ICarCheckTemplateService extends IService { + + /** + * 新增车检模板 + * @param dto 车检模板dto类 + * @return true-成功,false-失败 + */ + boolean saveCarCheckTemplate(CarCheckTemplateDTO dto); + + /** + * 根据名称获取车检模板 + * @param name 模板名称 + * @return 车检模板实体类 + */ + CarCheckTemplateEntity getCarCheckTemplateByName(String name); + + /** + * 修改车检模板 + * @param dto 车检模板dto类 + * @return true-成功,false-失败 + */ + boolean updateCarCheckTemplate(CarCheckTemplateDTO dto); + + /** + * 删除车检模板 + * @param id 模板id + * @return true-成功,false-失败 + */ + boolean removeCarCheckTemplate(Long id); + + /** + * 车检模板详情 + * @param id 模板id + * @return 模板详情VO类 + */ + CarCheckTemplateDetailVO getCarCheckTemplateDetail(Long id); + + /** + * 车检分页 + * @param query 分页类 + * @param param 参数 + * @return 分页 + */ + IPage getCarCheckTemplatePage(Query query, Map param); +} diff --git a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/CarCheckRecordServiceImpl.java b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/CarCheckRecordServiceImpl.java index 864dd53..69ae394 100644 --- a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/CarCheckRecordServiceImpl.java +++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/CarCheckRecordServiceImpl.java @@ -18,6 +18,7 @@ import com.hnac.hzims.safeproduct.service.ICarCheckRecordService; import com.hnac.hzims.safeproduct.utils.BaseUtil; import com.hnac.hzims.safeproduct.vo.CarCheckRecordDetailVO; import com.hnac.hzims.safeproduct.vo.CarCheckRecordPageVO; +import org.springblade.core.log.exception.ServiceException; import org.springblade.core.mp.support.Query; import org.springblade.core.tool.utils.BeanUtil; import org.springframework.beans.factory.annotation.Autowired; @@ -68,15 +69,16 @@ public class CarCheckRecordServiceImpl extends ServiceImpl itemList = carCheckRecordDTO.getItemList(); - itemList.forEach(x -> x.setCarCheckRecordId(recordEntity.getId())); - return carCheckItemService.saveBatch(itemList); + if (!saveRecord) { + throw new ServiceException("车检记录新增失败"); } - return false; + // 新增车检项 + CarCheckRecordEntity recordEntity = getCarCheckRecordByCode(code); + List itemList = carCheckRecordDTO.getItemList(); + itemList.forEach(x -> x.setCarCheckRecordId(recordEntity.getId())); + return carCheckItemService.saveBatch(itemList); } /** @@ -104,7 +106,19 @@ public class CarCheckRecordServiceImpl extends ServiceImpl itemList = carCheckItemService.getListByCarCheckRecordId(id); - carCheckRecordDetailVO.setCheckItemList(itemList); + List checkItemList = new ArrayList<>(); + itemList.forEach(item -> { + String[] contents = item.getCheckContent().split(",|,"); + String[] results = item.getCheckResult().split(",|,"); + for (int i = 0; i < contents.length; i++) { + CarCheckItemEntity carCheckItemEntity = new CarCheckItemEntity(); + carCheckItemEntity.setCheckItem(item.getCheckItem()); + carCheckItemEntity.setCheckContent(contents[i]); + carCheckItemEntity.setCheckResult(results[i]); + checkItemList.add(carCheckItemEntity); + } + }); + carCheckRecordDetailVO.setCheckItemList(checkItemList); return carCheckRecordDetailVO; } return null; @@ -157,22 +171,25 @@ public class CarCheckRecordServiceImpl extends ServiceImpl itemList = carCheckRecordDTO.getItemList(); - itemList.forEach(x -> {x.setCarCheckRecordId(carCheckRecordDTO.getId()); - x.setId(null);}); - boolean b = carCheckItemService.saveBatch(itemList); - if (b) { - // 若更新检查项成功,则更新车检记录 - CarCheckRecordEntity carCheckRecordEntity = new CarCheckRecordEntity(); - BeanUtil.copyProperties(carCheckRecordDTO, carCheckRecordEntity); - return this.updateById(carCheckRecordEntity); + // 删除旧的检查项 + boolean deleteItem = carCheckItemService.removeRelativeCarCheckItem(carCheckRecordDTO.getId()); + if (!deleteItem) { + throw new ServiceException("旧的车检记录检查项删除失败"); } - return false; + // 新增新的检查项 + List itemList = carCheckRecordDTO.getItemList(); + itemList.forEach(x -> { + x.setCarCheckRecordId(carCheckRecordDTO.getId()); +// x.setId(null); + }); + return carCheckItemService.saveBatch(itemList); } /** @@ -182,10 +199,10 @@ public class CarCheckRecordServiceImpl extends ServiceImpl + implements ICarCheckTemplateDetailService { + + /** + * 删除关联的模板详情数据 + */ + @Override + public boolean removeReferenceDetail(Long templateId) { + List list = this.getReferenceDetail(templateId); + List ids = list.stream().map(CarCheckTemplateDetailEntity::getId).collect(Collectors.toList()); + return this.removeByIds(ids); + } + + @Override + public List getReferenceDetail(Long templateId) { + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.lambda().eq(CarCheckTemplateDetailEntity::getTemplateId, templateId); + return this.list(queryWrapper); + } +} diff --git a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/CarCheckTemplateServiceImpl.java b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/CarCheckTemplateServiceImpl.java new file mode 100644 index 0000000..fe2c069 --- /dev/null +++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/CarCheckTemplateServiceImpl.java @@ -0,0 +1,161 @@ +package com.hnac.hzims.safeproduct.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.hnac.hzims.safeproduct.dto.CarCheckTemplateDTO; +import com.hnac.hzims.safeproduct.entity.*; +import com.hnac.hzims.safeproduct.mapper.CarCheckTemplateMapper; +import com.hnac.hzims.safeproduct.service.ICarCheckTemplateService; +import com.hnac.hzims.safeproduct.vo.CarCheckTemplateDetailVO; +import org.springblade.core.log.exception.ServiceException; +import org.springblade.core.mp.support.Query; +import org.springblade.core.tool.api.R; +import org.springblade.system.feign.ISysClient; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import javax.annotation.Resource; +import java.util.List; +import java.util.Map; + +/** + * 车检模板服务实现类 + * + * @date 2024-05-28 + */ +@Service +public class CarCheckTemplateServiceImpl extends ServiceImpl implements ICarCheckTemplateService { + + @Autowired + ICarCheckTemplateDetailService carCheckTemplateDetailService; + + @Resource + CarCheckTemplateMapper carCheckTemplateMapper; + + @Autowired + ISysClient sysClient; + + /** + * 新增车检模板 + */ + @Override + @Transactional(rollbackFor = Exception.class) + public boolean saveCarCheckTemplate(CarCheckTemplateDTO dto) { + String templateName = dto.getTemplateName(); + // 重名校验 + CarCheckTemplateEntity template = getCarCheckTemplateByName(templateName); + if (template != null) { + throw new ServiceException("模板名不可重复"); + } + // 新增车检模板 + CarCheckTemplateEntity templateEntity = new CarCheckTemplateEntity(); + templateEntity.setTemplateName(templateName); + boolean saveTemplate = this.save(templateEntity); + if (!saveTemplate) { + throw new ServiceException("车检模板新增失败"); + } + // 新增模板详情 + template = getCarCheckTemplateByName(templateName); + List details = dto.getDetailList(); + for (CarCheckTemplateDetailEntity detail : details) { + detail.setTemplateId(template.getId()); + } + return carCheckTemplateDetailService.saveBatch(details); + } + + /** + * 根据名称获取车检模板 + */ + public CarCheckTemplateEntity getCarCheckTemplateByName(String name) { + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.lambda().eq(CarCheckTemplateEntity::getTemplateName, name); + return this.getOne(queryWrapper); + } + + /** + * 修改车检模板 + */ + @Override + @Transactional(rollbackFor = Exception.class) + public boolean updateCarCheckTemplate(CarCheckTemplateDTO dto) { + String templateName = dto.getTemplateName(); + Long templateId = dto.getId(); + // 重名校验 + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.lambda().eq(CarCheckTemplateEntity::getTemplateName, templateName); + queryWrapper.lambda().ne(CarCheckTemplateEntity::getId, templateId); + CarCheckTemplateEntity template = this.getOne(queryWrapper); + if (template != null) { + throw new ServiceException("模板名不可重复"); + } + // 更新模板 + CarCheckTemplateEntity templateEntity = new CarCheckTemplateEntity(); + templateEntity.setId(templateId); + templateEntity.setTemplateName(templateName); + boolean updateTemplate = this.updateById(templateEntity); + if (!updateTemplate) { + throw new ServiceException("车检模板更新失败"); + } + // 更新模板详情 + // 删除旧的模板详情数据 + boolean removeDetail = carCheckTemplateDetailService.removeReferenceDetail(templateId); + if (!removeDetail) { + throw new ServiceException("车检模板详情数据删除失败"); + } + // 新增新的模板详情数据 + List detailList = dto.getDetailList(); + for (CarCheckTemplateDetailEntity detail : detailList) { + detail.setTemplateId(templateId); + } + return carCheckTemplateDetailService.saveBatch(detailList); + } + + /** + * 删除车检模板 + */ + @Override + @Transactional(rollbackFor = Exception.class) + public boolean removeCarCheckTemplate(Long id) { + boolean removeTemplate = this.removeById(id); + if (!removeTemplate) { + throw new ServiceException("车检模板删除失败"); + } + return carCheckTemplateDetailService.removeReferenceDetail(id); + } + + /** + * 车检模板详情 + */ + @Override + public CarCheckTemplateDetailVO getCarCheckTemplateDetail(Long id) { + CarCheckTemplateEntity templateEntity = this.getById(id); + CarCheckTemplateDetailVO vo = new CarCheckTemplateDetailVO(); + vo.setId(templateEntity.getId()); + vo.setTemplateName(templateEntity.getTemplateName()); + List list = carCheckTemplateDetailService.getReferenceDetail(id); + vo.setTemplateDetailList(list); + return vo; + } + + /** + * 车检分页 + */ + @Override + public IPage getCarCheckTemplatePage(Query query, Map param) { + IPage page = new Page<>(query.getCurrent(), query.getSize()); + IPage templatePage = carCheckTemplateMapper.getCarCheckTemplatePage(page, param); + List templateList = templatePage.getRecords(); + // 获取机构名 + templateList.forEach(template -> { + R deptName = sysClient.getDeptName(template.getCreateDept()); + if (deptName.isSuccess()) { + template.setCreateDeptName(deptName.getData()); + } + }); + templatePage.setRecords(templateList); + return templatePage; + } +} diff --git a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/ICarCheckTemplateDetailService.java b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/ICarCheckTemplateDetailService.java new file mode 100644 index 0000000..3a7315a --- /dev/null +++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/ICarCheckTemplateDetailService.java @@ -0,0 +1,28 @@ +package com.hnac.hzims.safeproduct.service.impl; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.hnac.hzims.safeproduct.entity.CarCheckTemplateDetailEntity; + +import java.util.List; + +/** + * 车检模板详情服务类 + * + * @date 2024-05-30 + */ +public interface ICarCheckTemplateDetailService extends IService { + + /** + * 删除关联的模板详情数据 + * @param templateId 模板id + * @return true-成功,false-失败 + */ + boolean removeReferenceDetail(Long templateId); + + /** + * 查询关联的模板详情列表 + * @param templateId 模板id + * @return 模板详情列表 + */ + List getReferenceDetail(Long templateId); +} diff --git a/hzims-service/safeproduct/src/main/resources/db/2.0.1.sql b/hzims-service/safeproduct/src/main/resources/db/2.0.1.sql index 516bede..733ffca 100644 --- a/hzims-service/safeproduct/src/main/resources/db/2.0.1.sql +++ b/hzims-service/safeproduct/src/main/resources/db/2.0.1.sql @@ -46,4 +46,34 @@ CREATE TABLE IF NOT EXISTS `hzims_hygiene_template_detail` ( -- 添加考试及格分字段 ALTER TABLE hzims_test - ADD COLUMN passing_score int(10) NOT NULL DEFAULT 60 COMMENT '考试及格分'; \ No newline at end of file + ADD COLUMN passing_score int(10) NOT NULL DEFAULT 60 COMMENT '考试及格分'; + +-- 新增车检模板表 +CREATE TABLE IF NOT EXISTS `hzims_hygiene_template` ( + `id` bigint(20) NOT NULL COMMENT '主键ID', + `template_name` varchar(50) NOT NULL COMMENT '模板名称', + `create_user` bigint(20) NOT NULL DEFAULT '-1' COMMENT '创建人', + `create_dept` bigint(20) NOT NULL DEFAULT '-1' COMMENT '创建部门', + `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `update_user` bigint(20) DEFAULT '-1' COMMENT '更新人', + `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后更新时间', + `status` int(2) NOT NULL DEFAULT '1' COMMENT '状态', + `is_deleted` int(2) NOT NULL DEFAULT '0' COMMENT '逻辑删除状态:0-未删除,1-删除', + PRIMARY KEY (`id`) USING BTREE + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC COMMENT='车检模板表'; + +-- 新增车检模板详情表 +CREATE TABLE IF NOT EXISTS `hzims_hygiene_template_detail` ( + `id` bigint(20) NOT NULL COMMENT '主键ID', + `template_id` bigint(20) NOT NULL COMMENT '模板id', + `check_item` varchar(500) NOT NULL COMMENT '检查项目', + `check_content` mediumtext NOT NULL COMMENT '检查内容', + `create_user` bigint(20) NOT NULL DEFAULT '-1' COMMENT '创建人', + `create_dept` bigint(20) NOT NULL DEFAULT '-1' COMMENT '创建部门', + `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `update_user` bigint(20) DEFAULT '-1' COMMENT '更新人', + `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后更新时间', + `status` int(2) NOT NULL DEFAULT '1' COMMENT '状态', + `is_deleted` int(2) NOT NULL DEFAULT '0' COMMENT '逻辑删除状态:0-未删除,1-删除', + PRIMARY KEY (`id`) USING BTREE + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC COMMENT='车检模板详情表'; \ No newline at end of file