|
|
@@ -16,13 +16,37 @@
|
|
|
*/
|
|
|
package com.gubersail.admin.imageStore.service.impl;
|
|
|
|
|
|
-import com.gubersail.dealer.admin.api.imageStore.entity.BladeImageStoreApply;
|
|
|
-import com.gubersail.dealer.admin.api.imageStore.vo.BladeImageStoreApplyVO;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.gubersail.admin.imageStore.mapper.BladeImageStoreApplyMapper;
|
|
|
+import com.gubersail.admin.imageStore.service.IBladeImageStoreApplyAttachmentService;
|
|
|
import com.gubersail.admin.imageStore.service.IBladeImageStoreApplyService;
|
|
|
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.gubersail.admin.util.BillCodeUtil;
|
|
|
+import com.gubersail.admin.wrapper.ImageStoreApplyWrapper;
|
|
|
+import com.gubersail.admin.zcrm.customer.service.IViewCustomerSelService;
|
|
|
+import com.gubersail.dealer.admin.api.imageStore.entity.BladeImageStoreApply;
|
|
|
+import com.gubersail.dealer.admin.api.imageStore.entity.BladeImageStoreApplyAttachment;
|
|
|
+import com.gubersail.dealer.admin.api.imageStore.vo.BladeImageStoreApplyVO;
|
|
|
+import com.gubersail.dealer.admin.api.zcrm.customer.entity.ViewCustomerSel;
|
|
|
+import lombok.AllArgsConstructor;
|
|
|
+import org.springblade.common.enums.NumberEnum;
|
|
|
+import org.springblade.core.secure.utils.AuthUtil;
|
|
|
+import org.springblade.core.secure.utils.SecureUtil;
|
|
|
+import org.springblade.core.tool.api.R;
|
|
|
+import org.springblade.core.tool.utils.BeanUtil;
|
|
|
+import org.springblade.system.user.entity.User;
|
|
|
+import org.springblade.system.user.feign.IUserClient;
|
|
|
+import org.springframework.http.HttpStatus;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
-import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.util.StringUtils;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* 形象店申请主表 服务实现类
|
|
|
@@ -31,11 +55,161 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
* @since 2025-09-15
|
|
|
*/
|
|
|
@Service
|
|
|
+@AllArgsConstructor
|
|
|
public class BladeImageStoreApplyServiceImpl extends ServiceImpl<BladeImageStoreApplyMapper, BladeImageStoreApply> implements IBladeImageStoreApplyService {
|
|
|
|
|
|
+ private final IUserClient userClient;
|
|
|
+
|
|
|
+ private final IBladeImageStoreApplyAttachmentService bladeImageStoreApplyAttachmentService;
|
|
|
+
|
|
|
+ private final IViewCustomerSelService viewCustomerSelService;
|
|
|
+
|
|
|
@Override
|
|
|
public IPage<BladeImageStoreApplyVO> selectBladeImageStoreApplyPage(IPage<BladeImageStoreApplyVO> page, BladeImageStoreApplyVO bladeImageStoreApply) {
|
|
|
return page.setRecords(baseMapper.selectBladeImageStoreApplyPage(page, bladeImageStoreApply));
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public BladeImageStoreApplyVO detail(BladeImageStoreApply bladeImageStoreApply) {
|
|
|
+ //通过id查询数据
|
|
|
+ BladeImageStoreApply imageStoreApply = this.getById(bladeImageStoreApply.getId());
|
|
|
+ //数据实体类转换
|
|
|
+ BladeImageStoreApplyVO vo = ImageStoreApplyWrapper.build().entityVO(imageStoreApply);
|
|
|
+ R<User> createUserR = userClient.userInfoById(imageStoreApply.getCreateUser());
|
|
|
+ if (createUserR.isSuccess() && ObjectUtils.isNotNull(createUserR.getData())) {
|
|
|
+ vo.setCreateUserName(createUserR.getData().getRealName());
|
|
|
+ }
|
|
|
+ R<User> updateUserR = userClient.userInfoById(imageStoreApply.getUpdateUser());
|
|
|
+ if (updateUserR.isSuccess() && ObjectUtils.isNotNull(updateUserR.getData())) {
|
|
|
+ vo.setUpdateUserName(updateUserR.getData().getRealName());
|
|
|
+ }
|
|
|
+ //查询附件数据
|
|
|
+ List<BladeImageStoreApplyAttachment> claimAttachmentList = bladeImageStoreApplyAttachmentService.list(new LambdaQueryWrapper<BladeImageStoreApplyAttachment>()
|
|
|
+ .eq(BladeImageStoreApplyAttachment::getApplyId, bladeImageStoreApply.getId())
|
|
|
+ .eq(BladeImageStoreApplyAttachment::getIsDeleted, 0));
|
|
|
+ vo.setImageStoreApplyAttachmentList(claimAttachmentList.isEmpty() ? new ArrayList<>() : claimAttachmentList);
|
|
|
+ return vo;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public R submit(BladeImageStoreApplyVO bladeImageStoreApply) {
|
|
|
+ BladeImageStoreApply imageStoreApply = new BladeImageStoreApply();
|
|
|
+ BeanUtil.copyProperties(bladeImageStoreApply, imageStoreApply);
|
|
|
+ //判断是否是第一次保存
|
|
|
+ if (imageStoreApply.getId() == null) {
|
|
|
+ // 获取 流水号
|
|
|
+ String billNo = BillCodeUtil.getBillCodeByType(SecureUtil.getTenantId(), "SQ");
|
|
|
+ if (!StringUtils.hasText(billNo) || billNo.length() < NumberEnum.FIFTEEN.number) {
|
|
|
+ return R.fail(HttpStatus.INTERNAL_SERVER_ERROR.value(), "生成系统编号失败");
|
|
|
+ }
|
|
|
+ imageStoreApply.setApplyNo(billNo);
|
|
|
+ imageStoreApply.setCreateTime(new Date());
|
|
|
+ imageStoreApply.setCreateUser(AuthUtil.getUserId());
|
|
|
+ imageStoreApply.setCreateDept(Long.valueOf(AuthUtil.getDeptId()));
|
|
|
+ imageStoreApply.setAuditStatus(0);
|
|
|
+ //查询当前登录人信息
|
|
|
+ R<User> userR = userClient.userInfoById(AuthUtil.getUserId());
|
|
|
+ if (!userR.isSuccess() || ObjectUtils.isNull(userR.getData())) {
|
|
|
+ throw new RuntimeException("未查到当前登录人用户信息");
|
|
|
+ }
|
|
|
+ if (1 == imageStoreApply.getApplicantType()) {
|
|
|
+ //判断当前登录人角色是否是管理员
|
|
|
+ if (AuthUtil.getUserRole().contains("admin")) {
|
|
|
+ imageStoreApply.setCustomerId(AuthUtil.getUserId());
|
|
|
+ imageStoreApply.setCustomerCode("");
|
|
|
+ imageStoreApply.setCustomerName(userR.getData().getRealName());
|
|
|
+ imageStoreApply.setContactName(userR.getData().getRealName());
|
|
|
+ imageStoreApply.setContactPhone(userR.getData().getPhone());
|
|
|
+ } else {
|
|
|
+ //不是管理员角色需要按照用户信息中客户id查询客户信息
|
|
|
+ ViewCustomerSel customerSel = viewCustomerSelService.getOne(new LambdaQueryWrapper<ViewCustomerSel>()
|
|
|
+ .eq(ViewCustomerSel::getIsDeleted, 0)
|
|
|
+ .eq(ViewCustomerSel::getCustomerId, userR.getData().getCustomerId())
|
|
|
+ .orderByDesc(ViewCustomerSel::getCreateTime).last("LIMIT 1"));
|
|
|
+ if (customerSel == null) {
|
|
|
+ throw new RuntimeException("未查到客户档案信息");
|
|
|
+ }
|
|
|
+ imageStoreApply.setCustomerId(customerSel.getCustomerId());
|
|
|
+ imageStoreApply.setCustomerCode(customerSel.getCustomerCode());
|
|
|
+ imageStoreApply.setCustomerName(customerSel.getCustomerName());
|
|
|
+ imageStoreApply.setContactName(customerSel.getDescflexfieldPrivatedescseg1());
|
|
|
+ imageStoreApply.setContactPhone(customerSel.getDescflexfieldPrivatedescseg2());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ imageStoreApply.setUpdateUser(AuthUtil.getUserId());
|
|
|
+ imageStoreApply.setUpdateTime(new Date());
|
|
|
+ }
|
|
|
+ //保存数据
|
|
|
+ this.saveOrUpdate(imageStoreApply);
|
|
|
+ //判断是否存在附件数据
|
|
|
+ if (ObjectUtils.isNotNull(bladeImageStoreApply.getImageStoreApplyAttachmentList()) && !bladeImageStoreApply.getImageStoreApplyAttachmentList().isEmpty()) {
|
|
|
+ for (BladeImageStoreApplyAttachment item : bladeImageStoreApply.getImageStoreApplyAttachmentList()) {
|
|
|
+ //添加理赔主表关联数据
|
|
|
+ item.setApplyId(imageStoreApply.getId());
|
|
|
+ //判断是否是第一次保存
|
|
|
+ if (item.getId() == null) {
|
|
|
+ item.setCreateTime(new Date());
|
|
|
+ item.setCreateUser(AuthUtil.getUserId());
|
|
|
+ item.setCreateDept(Long.valueOf(AuthUtil.getDeptId()));
|
|
|
+ } else {
|
|
|
+ item.setUpdateUser(AuthUtil.getUserId());
|
|
|
+ item.setUpdateTime(new Date());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //批量保存理赔附件数据数据
|
|
|
+ bladeImageStoreApplyAttachmentService.saveOrUpdateBatch(bladeImageStoreApply.getImageStoreApplyAttachmentList());
|
|
|
+ }
|
|
|
+ return R.data(imageStoreApply);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public R deleteByIds(List<Long> longList) {
|
|
|
+ //删除主表
|
|
|
+ this.removeByIds(longList);
|
|
|
+ //查询附件数据明细
|
|
|
+ List<BladeImageStoreApplyAttachment> claimAttachmentList = bladeImageStoreApplyAttachmentService.list(new LambdaQueryWrapper<BladeImageStoreApplyAttachment>()
|
|
|
+ .in(BladeImageStoreApplyAttachment::getApplyId, longList)
|
|
|
+ .eq(BladeImageStoreApplyAttachment::getIsDeleted, 0));
|
|
|
+ //判断是否存在附件数据明细 true 删除明细数据
|
|
|
+ if (!claimAttachmentList.isEmpty()) {
|
|
|
+ bladeImageStoreApplyAttachmentService.removeByIds(claimAttachmentList.stream().map(BladeImageStoreApplyAttachment::getId)
|
|
|
+ .collect(Collectors.toList()));
|
|
|
+ }
|
|
|
+ return R.success("操作成功");
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public R submitApproval(Long id) {
|
|
|
+ //通过id查询数据
|
|
|
+ BladeImageStoreApply imageStoreApply = this.getById(id);
|
|
|
+ //判断审核状态是否是录入状态
|
|
|
+ if (imageStoreApply.getAuditStatus() > 0) {
|
|
|
+ throw new RuntimeException("已提交审批,请勿重复审批");
|
|
|
+ }
|
|
|
+ imageStoreApply.setAuditStatus(1);
|
|
|
+ imageStoreApply.setUpdateTime(new Date());
|
|
|
+ imageStoreApply.setUpdateUser(AuthUtil.getUserId());
|
|
|
+ this.updateById(imageStoreApply);
|
|
|
+ return R.success("操作成功");
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public R revokeApproval(Long id) {
|
|
|
+ //通过id查询数据
|
|
|
+ BladeImageStoreApply imageStoreApply = this.getById(id);
|
|
|
+ //判断审核状态是否是审核中
|
|
|
+ if (imageStoreApply.getAuditStatus() != 1) {
|
|
|
+ throw new RuntimeException("未提交审批,撤销失败");
|
|
|
+ }
|
|
|
+ imageStoreApply.setAuditStatus(0);
|
|
|
+ imageStoreApply.setUpdateTime(new Date());
|
|
|
+ imageStoreApply.setUpdateUser(AuthUtil.getUserId());
|
|
|
+ this.updateById(imageStoreApply);
|
|
|
+ return R.success("操作成功");
|
|
|
+ }
|
|
|
+
|
|
|
}
|