|
@@ -0,0 +1,283 @@
|
|
|
+/*
|
|
|
+ * Copyright [2022] [https://www.xiaonuo.vip]
|
|
|
+ *
|
|
|
+ * Snowy采用APACHE LICENSE 2.0开源协议,您在使用过程中,需要注意以下几点:
|
|
|
+ *
|
|
|
+ * 1.请不要删除和修改根目录下的LICENSE文件。
|
|
|
+ * 2.请不要删除和修改Snowy源码头部的版权声明。
|
|
|
+ * 3.本项目代码可免费商业使用,商业使用请保留源码和相关描述文件的项目出处,作者声明等。
|
|
|
+ * 4.分发源码时候,请注明软件出处 https://www.xiaonuo.vip
|
|
|
+ * 5.不可二次分发开源参与同类竞品,如有想法可联系团队xiaonuobase@qq.com商议合作。
|
|
|
+ * 6.若您的项目无法满足以上几点,需要更多功能代码,获取Snowy商业授权许可,请在官网购买授权,地址为 https://www.xiaonuo.vip
|
|
|
+ */
|
|
|
+package vip.xiaonuo.biz.modular.bizship.service.impl;
|
|
|
+
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
+import cn.hutool.core.collection.CollStreamUtil;
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
+import cn.hutool.core.util.PhoneUtil;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import jakarta.annotation.Resource;
|
|
|
+import org.apache.commons.compress.utils.Lists;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+import vip.xiaonuo.auth.core.util.StpLoginUserUtil;
|
|
|
+import vip.xiaonuo.biz.modular.bizship.param.*;
|
|
|
+import vip.xiaonuo.biz.modular.user.entity.BizUser;
|
|
|
+import vip.xiaonuo.biz.modular.user.service.BizUserService;
|
|
|
+import vip.xiaonuo.common.exception.CommonException;
|
|
|
+import vip.xiaonuo.common.page.CommonPageRequest;
|
|
|
+import vip.xiaonuo.biz.modular.bizship.entity.BizShip;
|
|
|
+import vip.xiaonuo.biz.modular.bizship.mapper.BizShipMapper;
|
|
|
+import vip.xiaonuo.biz.modular.bizship.service.BizShipService;
|
|
|
+import vip.xiaonuo.dev.modular.dict.entity.DevDict;
|
|
|
+import vip.xiaonuo.dev.modular.dict.service.DevDictService;
|
|
|
+
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 船舶管理Service接口实现类
|
|
|
+ *
|
|
|
+ * @author fanzherong
|
|
|
+ * @date 2025/07/12 15:32
|
|
|
+ **/
|
|
|
+@Service
|
|
|
+public class BizShipServiceImpl extends ServiceImpl<BizShipMapper, BizShip> implements BizShipService {
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private BizUserService bizUserService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private DevDictService devDictService;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Page<BizShip> page(BizShipPageParam bizShipPageParam) {
|
|
|
+ QueryWrapper<BizShip> queryWrapper = new QueryWrapper<BizShip>().checkSqlInjection();
|
|
|
+ //船舶号
|
|
|
+ if(ObjectUtil.isNotEmpty(bizShipPageParam.getShipNumber())){
|
|
|
+ queryWrapper.like("bs.ship_number",bizShipPageParam.getShipNumber());
|
|
|
+ }
|
|
|
+ //船型
|
|
|
+ if(ObjectUtil.isNotEmpty(bizShipPageParam.getShipType())){
|
|
|
+ queryWrapper.eq("bs.ship_type",bizShipPageParam.getShipType());
|
|
|
+ }
|
|
|
+ //船舶所有人
|
|
|
+ if(ObjectUtil.isNotEmpty(bizShipPageParam.getShipOwner())){
|
|
|
+ queryWrapper.like("su.name",bizShipPageParam.getShipOwner());
|
|
|
+ }
|
|
|
+ //联系人姓名
|
|
|
+ if(ObjectUtil.isNotEmpty(bizShipPageParam.getContactName())){
|
|
|
+ queryWrapper.like("bs.contact_name",bizShipPageParam.getContactName());
|
|
|
+ }
|
|
|
+ //联系人电话
|
|
|
+ if(ObjectUtil.isNotEmpty(bizShipPageParam.getContactPhone())){
|
|
|
+ queryWrapper.like("bs.contact_name",bizShipPageParam.getContactPhone());
|
|
|
+ }
|
|
|
+ // 校验数据范围
|
|
|
+ List<String> loginUserDataScope = StpLoginUserUtil.getLoginUserDataScope();
|
|
|
+ if(ObjectUtil.isEmpty(loginUserDataScope)) {
|
|
|
+ queryWrapper.eq("bs.ship_id",StpLoginUserUtil.getLoginUser().getId());
|
|
|
+ }
|
|
|
+ queryWrapper.eq("bs.delete_flag","NOT_DELETE");
|
|
|
+ queryWrapper.lambda().orderByDesc(BizShip::getCreateTime);
|
|
|
+ Page<BizShip> page = this.getBaseMapper().getPage(CommonPageRequest.defaultPage(), queryWrapper);
|
|
|
+ return page;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ @Override
|
|
|
+ public void add(BizShipAddParam bizShipAddParam) {
|
|
|
+ checkParam(bizShipAddParam);
|
|
|
+ BizShip bizShip = BeanUtil.toBean(bizShipAddParam, BizShip.class);
|
|
|
+ if(ObjectUtil.isNotEmpty(bizShipAddParam.getCertificateNameList())){
|
|
|
+ StringBuffer buffer = new StringBuffer();
|
|
|
+ for(String name : bizShipAddParam.getCertificateNameList()){
|
|
|
+ buffer.append(name+",");
|
|
|
+ }
|
|
|
+ bizShip.setShipCertificateName(buffer.substring(0,buffer.length()-1));
|
|
|
+ }
|
|
|
+ if(ObjectUtil.isNotEmpty(bizShipAddParam.getCertificatePathList())){
|
|
|
+ StringBuffer buffer = new StringBuffer();
|
|
|
+ for(String path : bizShipAddParam.getCertificatePathList()){
|
|
|
+ buffer.append(path+",");
|
|
|
+ }
|
|
|
+ bizShip.setShipCertificatePath(buffer.substring(0,buffer.length()-1));
|
|
|
+ }
|
|
|
+ if(ObjectUtil.isNotEmpty(bizShipAddParam.getContractNameList())){
|
|
|
+ StringBuffer buffer = new StringBuffer();
|
|
|
+ for(String name : bizShipAddParam.getContractNameList()){
|
|
|
+ buffer.append(name+",");
|
|
|
+ }
|
|
|
+ bizShip.setContractName(buffer.substring(0,buffer.length()-1));
|
|
|
+ }
|
|
|
+ if(ObjectUtil.isNotEmpty(bizShipAddParam.getContractPathList())){
|
|
|
+ StringBuffer buffer = new StringBuffer();
|
|
|
+ for(String path : bizShipAddParam.getContractPathList()){
|
|
|
+ buffer.append(path+",");
|
|
|
+ }
|
|
|
+ bizShip.setContractPath(buffer.substring(0,buffer.length()-1));
|
|
|
+ }
|
|
|
+ if(ObjectUtil.isNotEmpty(bizShip.getShipId())){
|
|
|
+ BizUser bizUser = bizUserService.getById(bizShip.getShipId());
|
|
|
+ if(ObjectUtil.isNotNull(bizUser)){
|
|
|
+ if(ObjectUtil.isEmpty(bizShip.getContactName())){
|
|
|
+ bizShip.setContactName(bizUser.getName());
|
|
|
+ }
|
|
|
+ if(ObjectUtil.isEmpty(bizShip.getContactPhone())){
|
|
|
+ bizShip.setContactPhone(bizUser.getPhone());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ this.save(bizShip);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void checkParam(BizShipAddParam bizShipAddParam){
|
|
|
+ if(ObjectUtil.isNotEmpty(bizShipAddParam.getContactPhone())){
|
|
|
+ if (!PhoneUtil.isMobile(bizShipAddParam.getContactPhone())) {
|
|
|
+ throw new CommonException("联系人电话:{}格式错误", bizShipAddParam.getContactPhone());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(ObjectUtil.isNotEmpty(bizShipAddParam.getShipNumber())){
|
|
|
+ //判断船舶号是否添加过
|
|
|
+ long count = this.count(new QueryWrapper<BizShip>().lambda().
|
|
|
+ eq(BizShip::getShipNumber, bizShipAddParam.getShipNumber()).
|
|
|
+ eq(BizShip::getStatus, "1"));
|
|
|
+ if(count>0){
|
|
|
+ throw new CommonException("船舶号已经添加过!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if(ObjectUtil.isNotEmpty(bizShipAddParam.getShipId())){
|
|
|
+ //判断船主是否添加过船舶
|
|
|
+ long count = this.count(new QueryWrapper<BizShip>().lambda().
|
|
|
+ eq(BizShip::getShipId, bizShipAddParam.getShipId()).
|
|
|
+ eq(BizShip::getStatus, "1"));
|
|
|
+ if(count>0){
|
|
|
+ throw new CommonException("船主存在启用的船舶!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ @Override
|
|
|
+ public void edit(BizShipEditParam bizShipEditParam) {
|
|
|
+ BizShip bizShip = this.queryEntity(bizShipEditParam.getId());
|
|
|
+ if(ObjectUtil.isNotEmpty(bizShip.getShipId())){
|
|
|
+ if(!StringUtils.equals(bizShipEditParam.getShipId(),bizShip.getShipId())){
|
|
|
+ BizUser bizUser = bizUserService.getById(bizShipEditParam.getShipId());
|
|
|
+ if(ObjectUtil.isNotNull(bizUser)){
|
|
|
+ bizShip.setContactName(bizUser.getName());
|
|
|
+ bizShip.setContactPhone(bizUser.getPhone());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ BeanUtil.copyProperties(bizShipEditParam, bizShip);
|
|
|
+ if(ObjectUtil.isNotEmpty(bizShipEditParam.getCertificateNameList())){
|
|
|
+ StringBuffer buffer = new StringBuffer();
|
|
|
+ for(String name : bizShipEditParam.getCertificateNameList()){
|
|
|
+ buffer.append(name+",");
|
|
|
+ }
|
|
|
+ bizShip.setShipCertificateName(buffer.substring(0,buffer.length()-1));
|
|
|
+ }
|
|
|
+ if(ObjectUtil.isNotEmpty(bizShipEditParam.getCertificatePathList())){
|
|
|
+ StringBuffer buffer = new StringBuffer();
|
|
|
+ for(String path : bizShipEditParam.getCertificatePathList()){
|
|
|
+ buffer.append(path+",");
|
|
|
+ }
|
|
|
+ bizShip.setShipCertificatePath(buffer.substring(0,buffer.length()-1));
|
|
|
+ }
|
|
|
+ if(ObjectUtil.isNotEmpty(bizShipEditParam.getContractNameList())){
|
|
|
+ StringBuffer buffer = new StringBuffer();
|
|
|
+ for(String name : bizShipEditParam.getContractNameList()){
|
|
|
+ buffer.append(name+",");
|
|
|
+ }
|
|
|
+ bizShip.setContractName(buffer.substring(0,buffer.length()-1));
|
|
|
+ }
|
|
|
+ if(ObjectUtil.isNotEmpty(bizShipEditParam.getContractPathList())){
|
|
|
+ StringBuffer buffer = new StringBuffer();
|
|
|
+ for(String path : bizShipEditParam.getContractPathList()){
|
|
|
+ buffer.append(path+",");
|
|
|
+ }
|
|
|
+ bizShip.setContractPath(buffer.substring(0,buffer.length()-1));
|
|
|
+ }
|
|
|
+ this.updateById(bizShip);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void checkParam(BizShip bizShip,BizShipEditParam bizShipEditParam){
|
|
|
+ if(ObjectUtil.isNotEmpty(bizShipEditParam.getContactPhone())){
|
|
|
+ if (!PhoneUtil.isMobile(bizShipEditParam.getContactPhone())) {
|
|
|
+ throw new CommonException("联系人电话:{}格式错误", bizShipEditParam.getContactPhone());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(!StringUtils.equals(bizShip.getShipNumber(),bizShipEditParam.getShipNumber())){
|
|
|
+ if(ObjectUtil.isNotEmpty(bizShipEditParam.getShipNumber())){
|
|
|
+ //判断船舶号是否添加过
|
|
|
+ long count = this.count(new QueryWrapper<BizShip>().lambda().
|
|
|
+ eq(BizShip::getShipNumber, bizShipEditParam.getShipNumber()).
|
|
|
+ eq(BizShip::getStatus, "1"));
|
|
|
+ if(count>0){
|
|
|
+ throw new CommonException("船舶号已经添加过!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if(!StringUtils.equals(bizShip.getShipId(),bizShipEditParam.getShipId())){
|
|
|
+ if(ObjectUtil.isNotEmpty(bizShipEditParam.getShipId())){
|
|
|
+ //判断船主是否添加过船舶
|
|
|
+ long count = this.count(new QueryWrapper<BizShip>().lambda().
|
|
|
+ eq(BizShip::getShipId, bizShipEditParam.getShipId()).
|
|
|
+ eq(BizShip::getStatus, "1"));
|
|
|
+ if(count>0){
|
|
|
+ throw new CommonException("船主存在启用的船舶!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ @Override
|
|
|
+ public void delete(List<BizShipIdParam> bizShipIdParamList) {
|
|
|
+ // 执行删除
|
|
|
+ this.removeByIds(CollStreamUtil.toList(bizShipIdParamList, BizShipIdParam::getId));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public BizShip detail(BizShipIdParam bizShipIdParam) {
|
|
|
+ return this.queryEntity(bizShipIdParam.getId());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public BizShip queryEntity(String id) {
|
|
|
+ BizShip bizShip = this.getById(id);
|
|
|
+ if(ObjectUtil.isEmpty(bizShip)) {
|
|
|
+ throw new CommonException("船舶管理不存在,id值为:{}", id);
|
|
|
+ }
|
|
|
+ return bizShip;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<BizShipValue> getShipTypeList() {
|
|
|
+ List<BizShipValue> list = Lists.newArrayList();
|
|
|
+ DevDict devDict = devDictService.getOne(new QueryWrapper<DevDict>().lambda().
|
|
|
+ eq(DevDict::getDictValue, "ship_type").
|
|
|
+ last("limit 1"));
|
|
|
+ if(ObjectUtil.isNotNull(devDict)){
|
|
|
+ List<DevDict> dictList = devDictService.list(new QueryWrapper<DevDict>().lambda().
|
|
|
+ eq(DevDict::getParentId, devDict.getId()));
|
|
|
+ for(DevDict dict : dictList){
|
|
|
+ BizShipValue bizShipValue = new BizShipValue();
|
|
|
+ bizShipValue.setLabel(dict.getDictLabel());
|
|
|
+ bizShipValue.setValue(dict.getDictValue());
|
|
|
+ list.add(bizShipValue);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|