skyouc
8 小时以前 63250869b7059e1ffc108a16eaffc557f8a44689
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
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.WkOrderItem;
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.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;
 
 
    /**
     * @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("计划数不能为空!!");
        }
        //保存扩展字段
        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;
    }
}