| | |
| | | import com.vincent.rsf.server.system.entity.FieldsItem; |
| | | import com.vincent.rsf.server.system.service.FieldsItemService; |
| | | import com.vincent.rsf.server.system.service.FieldsService; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.util.*; |
| | | |
| | |
| | | */ |
| | | public class ExtendFieldsUtils { |
| | | |
| | | /** |
| | | * @author Ryan |
| | | * @description 明细单据保存扩展字段 |
| | | * @param |
| | | * @return |
| | | * @time 2025/3/15 13:36 |
| | | */ |
| | | public static Boolean saveFields(Map<String, Object> params) throws Exception{ |
| | | FieldsService fieldsService = SpringUtils.getBean(FieldsService.class); |
| | | List<Fields> fields = fieldsService.list(new LambdaQueryWrapper<Fields>() |
| | | .eq(Fields::getStatus, 1) |
| | | .eq(Fields::getFlagEnable, 1)); |
| | | List<FieldsItem> fieldsItems = new ArrayList<>(); |
| | | if (!fields.isEmpty()) { |
| | | String uuid16 = CommonUtil.randomUUID16(); |
| | | for (Fields obj : fields) { |
| | | if (!Objects.isNull(params.get(obj.getFields()))) { |
| | | FieldsItem item = new FieldsItem(); |
| | | item.setUuid(uuid16) |
| | | .setValue(params.get(obj.getFields()).toString()) |
| | | .setMatnrId(Long.parseLong(params.get("matnrId").toString())) |
| | | .setFieldsId(obj.getId()); |
| | | fieldsItems.add(item); |
| | | } |
| | | params.put("fieldsIndex", uuid16); |
| | | } |
| | | FieldsItemService fieldsItemService = SpringUtils.getBean(FieldsItemService.class); |
| | | if (!fieldsItemService.saveBatch(fieldsItems)) { |
| | | throw new CoolException("单据明细扩展字段保存失败!!"); |
| | | } |
| | | } |
| | | return true; |
| | | } |
| | | // /** |
| | | // * @author Ryan |
| | | // * @description 明细单据保存扩展字段 |
| | | // * @param |
| | | // * @return |
| | | // * @time 2025/3/15 13:36 |
| | | // */ |
| | | // @Transactional(rollbackFor = Exception.class) |
| | | // public static Boolean saveFields(Map<String, Object> params, String uuid) throws Exception{ |
| | | // FieldsService fieldsService = SpringUtils.getBean(FieldsService.class); |
| | | // List<Fields> fields = fieldsService.list(new LambdaQueryWrapper<Fields>() |
| | | // .eq(Fields::getStatus, 1) |
| | | // .eq(Fields::getFlagEnable, 1)); |
| | | // List<FieldsItem> fieldsItems = new ArrayList<>(); |
| | | // if (!fields.isEmpty()) { |
| | | // for (Fields obj : fields) { |
| | | // if (!Objects.isNull(params.get(obj.getFields())) && StringUtils.isNotBlank(params.get(obj.getFields()).toString())) { |
| | | // FieldsItem item = new FieldsItem(); |
| | | // item.setUuid(uuid) |
| | | // .setValue(params.get(obj.getFields()).toString()) |
| | | // .setMatnrId(Long.parseLong(params.get("matnrId").toString())) |
| | | // .setFieldsId(obj.getId()); |
| | | // fieldsItems.add(item); |
| | | // } |
| | | // } |
| | | // if (fieldsItems.isEmpty()) { |
| | | // return false; |
| | | // } |
| | | // FieldsItemService fieldsItemService = SpringUtils.getBean(FieldsItemService.class); |
| | | // if (!fieldsItemService.saveBatch(fieldsItems)) { |
| | | // throw new CoolException("扩展字段保存失败!!"); |
| | | // } |
| | | // return true; |
| | | // } |
| | | // return false; |
| | | // } |
| | | |
| | | |
| | | /** |
| | | * @author Ryan |
| | | * @description 获取扩展字段key-value值 |
| | | * @param |
| | | * @return |
| | | * @time 2025/3/15 15:05 |
| | | */ |
| | | public static List<Map<String, Object>> getExtendFields(List<Map<String, Object>> params) { |
| | | FieldsService fieldsService = SpringUtils.getBean(FieldsService.class); |
| | | List<Fields> fields = fieldsService.list(new LambdaQueryWrapper<Fields>() |
| | | .eq(Fields::getStatus, 1) |
| | | .eq(Fields::getFlagEnable, 1)); |
| | | FieldsItemService fieldsItemService = SpringUtils.getBean(FieldsItemService.class); |
| | | List<Map<String, Object>> result = new ArrayList<>(); |
| | | for (Map<String, Object> param : params) { |
| | | result.add(param); |
| | | if (Objects.isNull(param.get("fieldsIndex"))) { |
| | | continue; |
| | | } |
| | | List<FieldsItem> itemList = fieldsItemService |
| | | .list(new LambdaQueryWrapper<FieldsItem>() |
| | | .eq(FieldsItem::getUuid, param.get("fieldsIndex"))); |
| | | if (itemList.isEmpty()) { |
| | | continue; |
| | | } |
| | | fields.forEach(fds -> { |
| | | for (FieldsItem fieldsItem : itemList) { |
| | | if (!Objects.isNull(fieldsItem.getFieldsId()) && fieldsItem.getFieldsId().equals(fds.getId())) { |
| | | param.put(fds.getFields(), fieldsItem.getValue()); |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | |
| | | return result; |
| | | } |
| | | } |