|  |  |  | 
|---|
|  |  |  | package com.vincent.rsf.server.manager.service.impl; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.alibaba.fastjson.JSONObject; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | 
|---|
|  |  |  | import com.vincent.rsf.framework.common.Cools; | 
|---|
|  |  |  | import com.vincent.rsf.framework.exception.CoolException; | 
|---|
|  |  |  | import com.vincent.rsf.server.common.utils.FieldsUtils; | 
|---|
|  |  |  | import com.vincent.rsf.server.manager.entity.Companys; | 
|---|
|  |  |  | import com.vincent.rsf.server.manager.entity.Matnr; | 
|---|
|  |  |  | import com.vincent.rsf.server.manager.enums.CompanysType; | 
|---|
|  |  |  | import com.vincent.rsf.server.manager.mapper.TransferItemMapper; | 
|---|
|  |  |  | import com.vincent.rsf.server.manager.entity.TransferItem; | 
|---|
|  |  |  | import com.vincent.rsf.server.manager.service.CompanysService; | 
|---|
|  |  |  | import com.vincent.rsf.server.manager.service.MatnrService; | 
|---|
|  |  |  | import com.vincent.rsf.server.manager.service.TransferItemService; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; | 
|---|
|  |  |  | import org.apache.commons.lang3.StringUtils; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
|---|
|  |  |  | import org.springframework.stereotype.Service; | 
|---|
|  |  |  | import org.springframework.transaction.annotation.Transactional; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.util.Map; | 
|---|
|  |  |  | import java.util.Objects; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Service("transferItemService") | 
|---|
|  |  |  | public class TransferItemServiceImpl extends ServiceImpl<TransferItemMapper, TransferItem> implements TransferItemService { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private CompanysService companysService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private MatnrService matnrService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * @author Ryan | 
|---|
|  |  |  | * @date 2025/7/28 | 
|---|
|  |  |  | * @description: 调拔单扩展字段保存 | 
|---|
|  |  |  | * @version 1.0 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | @Transactional(rollbackFor = Exception.class) | 
|---|
|  |  |  | public boolean fieldsSave(Map<String, Object> params, Long loginUserId) { | 
|---|
|  |  |  | TransferItem wkOrderItem = JSONObject.parseObject(JSONObject.toJSONString(params), TransferItem.class); | 
|---|
|  |  |  | if (StringUtils.isNoneBlank(wkOrderItem.getSplrCode())) { | 
|---|
|  |  |  | Companys companys = companysService.getOne(new LambdaQueryWrapper<Companys>() | 
|---|
|  |  |  | .eq(Companys::getId, wkOrderItem.getSplrCode()) | 
|---|
|  |  |  | .eq(Companys::getType, CompanysType.COMPANYS_TYPE_SUPPLIER.val)); | 
|---|
|  |  |  | if (!Objects.isNull(companys)) { | 
|---|
|  |  |  | wkOrderItem.setSplrId(companys.getId()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (Objects.isNull(wkOrderItem.getAnfme()) || Double.compare(wkOrderItem.getAnfme(), 0.0) <= 0) { | 
|---|
|  |  |  | throw new CoolException("计划数不能为空!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Matnr matnr = matnrService.getOne(new LambdaQueryWrapper<Matnr>().eq(Matnr::getCode, wkOrderItem.getMatnrCode())); | 
|---|
|  |  |  | if (Objects.isNull(matnr)) { | 
|---|
|  |  |  | throw new CoolException("数据错误:物料" + wkOrderItem.getMatnrCode() + "不存在!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | wkOrderItem.setMatnrCode(matnr.getCode()).setMatnrId(matnr.getId()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //        //保存扩展字段 | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | StringBuffer sb = new StringBuffer(); | 
|---|
|  |  |  | if (Objects.isNull(wkOrderItem.getFieldsIndex()) || StringUtils.isBlank(wkOrderItem.getFieldsIndex())) { | 
|---|
|  |  |  | sb.append(wkOrderItem.getMatnrId() + wkOrderItem.getBatch()); | 
|---|
|  |  |  | //获取16位uuid | 
|---|
|  |  |  | String uuid16 = Cools.md5Chinese(sb.toString()); | 
|---|
|  |  |  | wkOrderItem.setFieldsIndex(uuid16); | 
|---|
|  |  |  | params.put("index", uuid16); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //保存或更新动态字段值 | 
|---|
|  |  |  | FieldsUtils.updateFieldsValue(params); | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | throw new RuntimeException(e); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | wkOrderItem.setUpdateBy(loginUserId).setCreateBy(loginUserId); | 
|---|
|  |  |  | if (!this.saveOrUpdate(wkOrderItem)) { | 
|---|
|  |  |  | throw new CoolException("收货通知单明细保存失败!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return true; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|