| | |
| | | import cn.afterturn.easypoi.excel.entity.result.ExcelImportResult; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | 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 java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Objects; |
| | | import java.util.stream.Collectors; |
| | | |
| | | @Service("matnrService") |
| | | public class MatnrServiceImpl extends ServiceImpl<MatnrMapper, Matnr> implements MatnrService { |
| | |
| | | throw new CoolException("物料导入失败!!"); |
| | | } |
| | | List<Matnr> matnrs = new ArrayList<>(); |
| | | List<Map<String, String>> list = result.getList(); |
| | | List<MatnrsTemplate> list = result.getList(); |
| | | list.forEach(template -> { |
| | | Matnr matnr = new Matnr(); |
| | | matnr.setBarcode(template.get("barcode")) |
| | | .setCode(template.get("code")) |
| | | .setDescrible(template.get("describle")) |
| | | .setColor(template.get("color")) |
| | | .setFlagCheck(!Objects.isNull(template.get("flagCheck")) ? Short.parseShort(template.get("flagCheck")) : 0) |
| | | .setWeight(!Objects.isNull(template.get("weight")) ? Double.parseDouble(template.get("weight")) : 0.0) |
| | | .setValidWarn(!Objects.isNull(template.get("validWarn")) ? Integer.parseInt(template.get("validWarn")): 0) |
| | | .setValid(!Objects.isNull(template.get("valid")) ? Integer.parseInt( template.get("valid")) : 0) |
| | | .setUnit(template.get("unit")) |
| | | .setStockUnit(template.get("purUnit")) |
| | | .setSpec(template.get("spec")) |
| | | .setStagn(!Objects.isNull(template.get("stagn")) ? Integer.parseInt(template.get("stagn")) : 0) |
| | | .setModel(template.get("model")) |
| | | .setGroupCode(template.get("groupCode")) |
| | | .setPurUnit(template.get("purUnit")) |
| | | .setStockLevel(!Objects.isNull(template.get("stockLevel")) ? Short.parseShort(template.get("stockLevel")) : 0) |
| | | .setSafeQty(!Objects.isNull(template.get("safeQty")) ? Double.parseDouble(template.get("safeQty")) : 0) |
| | | .setMinQty(!Objects.isNull(template.get("safeQty")) ? Double.parseDouble(template.get("minQty")) : 0); |
| | | if (Objects.isNull(template.get("groupCode")) && Objects.isNull(template.get("groupName"))) { |
| | | matnr.setBarcode(template.getBarcode()) |
| | | .setCode(template.getCode()) |
| | | .setName(template.getName()) |
| | | .setDescrible(template.getDescrible()) |
| | | .setColor(template.getColor()) |
| | | .setFlagCheck(!Objects.isNull(template.getFlagCheck()) ? Short.parseShort(template.getFlagCheck()) : 0) |
| | | .setWeight(!Objects.isNull(template.getWeight()) ? Double.parseDouble(template.getWeight()) : 0.0) |
| | | .setValidWarn(!Objects.isNull(template.getValidWarn()) ? Integer.parseInt(template.getValidWarn()): 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) |
| | | .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())) { |
| | | MatnrGroup matnrGroups = matnrGroupService.getOne(new LambdaQueryWrapper<MatnrGroup>() |
| | | .eq(!Objects.isNull(template.get("groupCode")), MatnrGroup::getCode, template.get("groupCode")) |
| | | .eq(!Objects.isNull(template.get("groupName")),MatnrGroup::getName, template.get("groupName"))); |
| | | .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()) { |
| | | String uuid = CommonUtil.randomUUID16(); |
| | | matnr.setFieldsIndex(uuid); |
| | | //保存物料扩展属性值 |
| | | try { |
| | | FieldsUtils.saveFields(template, uuid); |
| | | 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); |
| | | } |
| | |
| | | } |
| | | |
| | | @Override |
| | | public PageParam<Matnr, BaseParam> getMatnrPage(PageParam<Matnr, BaseParam> pageParam) { |
| | | IPage<Map<String, Object>> reulst = this.baseMapper.selectMatnrs(pageParam, pageParam.buildWrapper(true)); |
| | | /**获取物料分页信息 */ |
| | | List<Map<String, Object>> mapList = reulst.getRecords(); |
| | | if (!mapList.isEmpty()) { |
| | | mapList.forEach(map -> { |
| | | if (!Objects.isNull(map.get("fieldsIndex"))) { |
| | | FieldsUtils.mergeFields(map, map.get("fieldsIndex").toString()); |
| | | } |
| | | }); |
| | | } |
| | | public PageParam<Matnr, BaseParam> getMatnrPage(PageParam<Matnr, BaseParam> pageParam, Map<String, Object> params) { |
| | | List<Long> longs = new ArrayList<>(); |
| | | if (params.containsKey("groupId")) { |
| | | Object groupId = params.get("groupId"); |
| | | MatnrGroup group = matnrGroupService.getById(groupId.toString()); |
| | | if (null != group){ |
| | | pageParam.getWhere().getMap().remove("groupId"); |
| | | if(!group.getCode().equals("01")){ |
| | | List<MatnrGroup> matnrGroups = matnrGroupService.list(new LambdaQueryWrapper<MatnrGroup>() |
| | | .eq(MatnrGroup::getParentId, Long.parseLong(groupId.toString())) |
| | | .select(MatnrGroup::getId)); |
| | | if (!matnrGroups.isEmpty()) { |
| | | longs = matnrGroups.stream().map(MatnrGroup::getId).collect(Collectors.toList()); |
| | | |
| | | PageParam<Matnr, BaseParam> page = this.page(pageParam, pageParam.buildWrapper(true)); |
| | | } |
| | | longs.add(group.getId()); |
| | | } |
| | | } |
| | | } |
| | | QueryWrapper<Matnr> queryWrapper = pageParam.buildWrapper(true); |
| | | queryWrapper.in(!longs.isEmpty(),"group_id", longs); |
| | | |
| | | FieldsUtils.setFieldsFilters(queryWrapper,pageParam,Matnr.class); |
| | | /**拼接扩展字段*/ |
| | | PageParam<Matnr, BaseParam> page = this.page(pageParam, queryWrapper); |
| | | List<Matnr> records = page.getRecords(); |
| | | for (Matnr record : records) { |
| | | if (!Objects.isNull(record.getFieldsIndex())) { |
| | |
| | | return true; |
| | | } |
| | | |
| | | @Override |
| | | public PageParam<Matnr, BaseParam> getPages(Map<String, Object> map) { |
| | | |
| | | |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | | * @desc 更新扩展物料扩展字段值 |
| | | * @param matnr |
| | |
| | | */ |
| | | String uuid16 = CommonUtil.randomUUID16(); |
| | | if (!FieldsUtils.getFieldsSta().isEmpty()) { |
| | | Map<String, ?> extendFields = (Map<String, ?>) matnr.get("extendFields"); |
| | | // Map<String, ?> extendFields = (Map<String, ?>) matnr.get("extendFields"); |
| | | try { |
| | | FieldsUtils.saveFields(extendFields, uuid16); |
| | | FieldsUtils.saveFields(matnr, uuid16); |
| | | matnr1.setFieldsIndex(uuid16); |
| | | } catch (Exception ex) { |
| | | log.error(ex.toString()); |