|  |  |  | 
|---|
|  |  |  | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.core.metadata.IPage; | 
|---|
|  |  |  | import com.vincent.rsf.framework.common.R; | 
|---|
|  |  |  | import com.vincent.rsf.framework.exception.CoolException; | 
|---|
|  |  |  | import com.vincent.rsf.server.common.domain.BaseParam; | 
|---|
|  |  |  | 
|---|
|  |  |  | import com.vincent.rsf.server.manager.controller.params.MatnrToGroupParams; | 
|---|
|  |  |  | import com.vincent.rsf.server.manager.entity.MatnrGroup; | 
|---|
|  |  |  | import com.vincent.rsf.server.manager.entity.excel.MatnrsTemplate; | 
|---|
|  |  |  | import com.vincent.rsf.server.manager.enums.MatnrLocLevel; | 
|---|
|  |  |  | import com.vincent.rsf.server.manager.mapper.MatnrMapper; | 
|---|
|  |  |  | import com.vincent.rsf.server.manager.entity.Matnr; | 
|---|
|  |  |  | import com.vincent.rsf.server.manager.service.MatnrGroupService; | 
|---|
|  |  |  | import com.vincent.rsf.server.manager.service.MatnrService; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; | 
|---|
|  |  |  | import com.vincent.rsf.server.system.constant.SerialRuleCode; | 
|---|
|  |  |  | import com.vincent.rsf.server.system.service.FieldsService; | 
|---|
|  |  |  | import com.vincent.rsf.server.system.utils.SerialRuleUtils; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
|---|
|  |  |  | import org.springframework.stereotype.Service; | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private MatnrGroupService matnrGroupService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private FieldsService fieldsService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | 
|---|
|  |  |  | * @param list | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public List<Matnr> getMatnrTempletes(List<MatnrsTemplate> list) { | 
|---|
|  |  |  | List<Matnr> matnrs = new ArrayList<>(); | 
|---|
|  |  |  | list.forEach(template -> { | 
|---|
|  |  |  | 
|---|
|  |  |  | matnr.setBarcode(template.getBarcode()) | 
|---|
|  |  |  | .setCode(template.getCode()) | 
|---|
|  |  |  | .setName(template.getName()) | 
|---|
|  |  |  | .setId(null) | 
|---|
|  |  |  | .setDescrible(template.getDescrible()) | 
|---|
|  |  |  | .setColor(template.getColor()) | 
|---|
|  |  |  | .setFlagCheck(!Objects.isNull(template.getFlagCheck()) ? Short.parseShort(template.getFlagCheck()) : 0) | 
|---|
|  |  |  | 
|---|
|  |  |  | .setValid(!Objects.isNull(template.getValid()) ? Integer.parseInt( template.getValid()) : 0) | 
|---|
|  |  |  | .setUnit(template.getUnit()) | 
|---|
|  |  |  | .setStockUnit(template.getPurUnit()) | 
|---|
|  |  |  | .setShipperId(template.getShipperId()) | 
|---|
|  |  |  | .setSize(template.getSize()) | 
|---|
|  |  |  | .setSpec(template.getSpec()) | 
|---|
|  |  |  | .setStagn(!Objects.isNull(template.getStagn()) ? Integer.parseInt(template.getStagn()) : 0) | 
|---|
|  |  |  | .setModel(template.getModel()) | 
|---|
|  |  |  | .setGroupCode(template.getGroupCode()) | 
|---|
|  |  |  | .setPurUnit(template.getPurUnit()) | 
|---|
|  |  |  | .setStockLevel(!Objects.isNull(template.getStockLevel()) ? Short.parseShort(template.getStockLevel()) : 0) | 
|---|
|  |  |  | .setStockLevel(!Objects.isNull(template.getStockLevel()) ? MatnrLocLevel.getTypeVal(template.getStockLevel()) : null) | 
|---|
|  |  |  | .setSafeQty(!Objects.isNull(template.getSafeQty()) ? Double.parseDouble(template.getSafeQty()) : 0) | 
|---|
|  |  |  | .setMinQty(!Objects.isNull(template.getMinQty()) ? Double.parseDouble(template.getMinQty()) : 0); | 
|---|
|  |  |  | if (Objects.isNull(template.getGroupCode()) && Objects.isNull(template.getGroupName())) { | 
|---|
|  |  |  | if (!Objects.isNull(template.getGroupCode()) || !Objects.isNull(template.getGroupName())) { | 
|---|
|  |  |  | MatnrGroup matnrGroups = matnrGroupService.getOne(new LambdaQueryWrapper<MatnrGroup>() | 
|---|
|  |  |  | .eq(!Objects.isNull(template.getGroupCode()), MatnrGroup::getCode, template.getGroupCode()) | 
|---|
|  |  |  | .eq(!Objects.isNull(template.getGroupName()),MatnrGroup::getName, template.getGroupName())); | 
|---|
|  |  |  | matnr.setGroupId(matnrGroups.getId()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //获取动态字段,并保存明细内容 | 
|---|
|  |  |  | if (!FieldsUtils.getFieldsSta().isEmpty()) { | 
|---|
|  |  |  | //保存物料扩展属性值 | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | Map<String, Object> map = JSONObject.parseObject(JSONObject.toJSONString(template), Map.class); | 
|---|
|  |  |  | String uuid = CommonUtil.randomUUID16(); | 
|---|
|  |  |  | boolean b = FieldsUtils.saveFields(map, uuid); | 
|---|
|  |  |  | if (b) { | 
|---|
|  |  |  | matnr.setFieldsIndex(uuid); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | throw new RuntimeException(e); | 
|---|
|  |  |  | .eq(!Objects.isNull(template.getGroupName()), MatnrGroup::getName, template.getGroupName())); | 
|---|
|  |  |  | if (!Objects.isNull(matnrGroups)) { | 
|---|
|  |  |  | matnr.setGroupId(matnrGroups.getId()).setGroupCode(matnrGroups.getCode()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //            List<Fields> fields = fieldsService.list(new LambdaQueryWrapper<Fields>() | 
|---|
|  |  |  | //                    .eq(Fields::getUnique, CommonStatus.COMMONSTATUS_NO.val) | 
|---|
|  |  |  | //                    .eq(Fields::getFlagEnable, CommonStatus.COMMONSTATUS_YES.val)); | 
|---|
|  |  |  | // | 
|---|
|  |  |  | //            //获取动态字段,并保存明细内容 | 
|---|
|  |  |  | //            if (!fields.isEmpty()) { | 
|---|
|  |  |  | //                //保存物料扩展属性值 | 
|---|
|  |  |  | //                try { | 
|---|
|  |  |  | //                    Map<String, Object> map = JSONObject.parseObject(JSONObject.toJSONString(template), Map.class); | 
|---|
|  |  |  | //                    String uuid = CommonUtil.randomUUID16(); | 
|---|
|  |  |  | //                    boolean b = FieldsUtils.saveFields(map, uuid); | 
|---|
|  |  |  | //                    if (b) { | 
|---|
|  |  |  | //                        matnr.setFieldsIndex(uuid); | 
|---|
|  |  |  | //                    } | 
|---|
|  |  |  | //                } catch (Exception e) { | 
|---|
|  |  |  | //                    throw new RuntimeException(e); | 
|---|
|  |  |  | //                } | 
|---|
|  |  |  | //            } | 
|---|
|  |  |  | matnrs.add(matnr); | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | return matnrs; | 
|---|